npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-interface-faker

v1.1.2

Published

typescript interface mock/fake——基于typescript的interface生成对应结构的假数据;支持 mockjs de '@语法'和'Random'方法; fake/mock data base on Typescript Interfaces;

Downloads

6

Readme

ts-interface-faker

typescript interface mock/fake——基于 typescript 的 interface 结构创造假数据;支持 mockjs de '@语法'和'Random'方法

generating fake data base on interface of typescript;

Install

npm i ts-interface-faker --save

Usage

const path = require('path');
import InterfaceFake from 'ts-interface-faker';

const faker = new InterfaceFake({
  workRoot: path.resolve(__dirname, './'), // the base path to your workspace
});
// get the fake data by using getFakeData
const data = faker.getFakeData((interfaceName: string));

Demo

typescript

const path = require('path');
import InterfaceFaker from 'ts-interface-faker';

interface IPerson {
  name: string;
  age: number;
  isMale: boolean;
  son: {
    name: string,
    age: number,
    isMale: boolean,
  };
}

const faker = new InterfaceFake({
  workRoot: path.resolve(__dirname, './'),
});

const data = faker.getFakeData('IPerson');
console.log(data);

output

{ age: 7273430.9083658755,
  isMale: true,
  name: 'Duis labore sunt nisi sint',
  son:
   { age: 26279849.364269882,
     isMale: true,
     name: 'ad amet enim in' } }

如何使用 mockjs

ts-interface-faker 本身依赖了 mockjs,你可以在项目中直接使用。目前仅支持 mockjs 的"@语法"和"Random"方法,尽管如此,这已经能覆盖到绝大部分的工作了。

export interface IBook {
  name: '@ctitle';
  EnglishName: '《@sentence(2, 4)》';
  publishTime: `Random.date('yyyy-MM-dd')`; // use mockjs Random
  desc: '@csentence';
}
export interface IChild {
  isGirl: boolean;
  inSchool: '@boolean'; // use mockjs boolean
  booksList: IBook[];
}


export interface IPerson {
  age: '@integer(180, 60)'; // mockjs @integer
  name: '@name';
  cname: '@cname';
  birthday: `Random.datetime('yyyy-M-d H:m:s')`;
  photos: `Random.image('200x200', '#FF6600')`[];// use mockjs Random
  address: '@province(true)';
  children: IChild[];
}

const faker = new InterfaceFake({
  'workRoot': path.resolve(__dirname, './')
});
const data: IPerson = faker.getFakeData('IPerson');

output

{
  "age": "102",
  "name": "Frank Hernandez",
  "cname": "袁勇",
  "birthday": "1985-9-28 8:39:51",
  "photos": [
    "http://dummyimage.com/200x200/FF6600",
    "http://dummyimage.com/200x200/FF6600"
  ],
  "address": "天津",
  "children": [
    {
      "isGirl": true,
      "inSchool": "false",
      "booksList": [
        {
          "name": "电根打你给研",
          "EnglishName": "《Bnounzzei hzdbxjg dzwdbtu xsdldr.》",
          "publishTime": "1974-12-16",
          "desc": "样声无们几报增装议两身后布多。"
        }
      ]
    },
    {
      "isGirl": true,
      "inSchool": "false",
      "booksList": [
        {
          "name": "命各期报",
          "EnglishName": "《Oxtt ewbnoy mxepwto ignbihb.》",
          "publishTime": "1999-01-28",
          "desc": "酸率易织国造江流前商商及为。"
        },
        {
          "name": "运一约与月常",
          "EnglishName": "《Pvnapzs hvfjxypn.》",
          "publishTime": "1975-05-01",
          "desc": "真酸队出厂我维质线约他直已局来石。"
        },
        {
          "name": "回公回任民",
          "EnglishName": "《Wcqgb too wqigie smjylqf.》",
          "publishTime": "2004-02-11",
          "desc": "去准中办义度斗按好例但结南得。"
        }
      ]
    },
    {
      "isGirl": false,
      "inSchool": "false",
      "booksList": [
        {
          "name": "效号作什论于低",
          "EnglishName": "《Lgip khjke qqhfiey.》",
          "publishTime": "1975-11-05",
          "desc": "电问意二北员话物声就备除劳列区太。"
        },
        {
          "name": "书入解品了每现",
          "EnglishName": "《Mtabweslx kcdg gtkhfpq oki.》",
          "publishTime": "1999-07-21",
          "desc": "龙金性各引南温万中每活层别些党委根。"
        }
      ]
    },
    {
      "isGirl": false,
      "inSchool": "false",
      "booksList": [
        {
          "name": "温平单率据",
          "EnglishName": "《Jmuen wtjwt eowfnbsjyn yltty.》",
          "publishTime": "1991-08-27",
          "desc": "斯张马处着节南青切问公响论。"
        },
        {
          "name": "白工许决",
          "EnglishName": "《Lvknl chfpfsm fjhhqawu.》",
          "publishTime": "1988-06-01",
          "desc": "年只基成但完第做八门书党。"
        },
        {
          "name": "约车般级",
          "EnglishName": "《Gkwjjzjj pgguphkpdu ljgovqny.》",
          "publishTime": "1992-12-21",
          "desc": "阶示术个然号内见系条根此并按深取。"
        },
        {
          "name": "例整包",
          "EnglishName": "《Nbdlwova wexjym.》",
          "publishTime": "1993-04-17",
          "desc": "布意在具复身叫支人律历特强所。"
        }
      ]
    }
  ]
}

点击查看更多 mockjs 示例

Todo

Welcome Star