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

mock-record

v2.0.4

Published

伪造数据

Downloads

8

Readme

mock-record

GitHub license npm version

  • 虚拟数据生成

使用

npm install mock-record
import { mock } from 'mock-record'

mock("@name")
=> 'Ruihuag'

说明

mock({
  'name|rule|key1,key2,key3...|[DictionaryKey]':'@name'
})
  • name: 表示当前属性真正name
  • rule : 指定生成数量规则, 只表示数量
  • key1,key2,key3...: 表示当前属性为对象, 并且指定多个key, 且值为 @name
  • @name: 数据规则

规则使用

mock("@name")
=> 'Ruihuag'

name|number

 mock({ 'name': '@name' })
 mock({ 'name|1': 1 })
 mock({ 'name|1': '@name' })
 mock({ 'name|3': '@name' })
 mock({ 'name|3': 1 })
 =>
  { name: 'Ruihuag' }
  { name: 1 }
  { name: 'Jose' }
  { name: 'FrankGaryDavid' }
  { name: 4 }

范围 name|2-222

mock({"name|3-5":"@name"})
=> { name: [ 'Jeffrey', 'Jose', 'Gary', 'William' ] }

指定数量 name|12

mock({"name|3":"@name"})
=>  { name: [ 'Christopher', 'Daniel', 'Richard' ] }

多用一

基础使用 {'name||key1,key2,key3':'@name'}

{name: { key1: 'Mark', key2: 'Jason', key3: 'Thomas' }}

指定数量 {'name|2|key1,key2,key3': "@name"}

{
  name: [
    { key1: 'Mark', key2: 'Donald', key3: 'Michael' },
    { key1: 'George', key2: 'Jose', key3: 'Edward' },
  ]
}

数量范围组 {'name|2-5|key1,key2,key3': "@name"}

{
  name: [
    { key1: 'Jason', key2: 'Kenneth', key3: 'Scott' },
    { key1: 'Mark', key2: 'Donald', key3: 'Michael' },
    { key1: 'George', key2: 'Jose', key3: 'Edward' },
  ]
}

多用一 并转子串

基础 {'name||key1,key2,key3|JsonString':'@name'}

{
  name: '{"key1":"Joseph","key2":"Michael","key3":"Jose"}'
}

指定数量 {'name|2|key1,key2,key3|JsonString': "@name"}

{
  name: '[{"key1":"Anthony","key2":"Eric","key3":"Edward"},{"key1":"Thomas","key2":"Eric","key3":"Edward"}]'
}

数量范围 {'name|2-5|key1,key2,key3|JsonString': "@name"}

{ name: '{"key1":"James","key2":"Jeffrey","key3":"William"}' }

自定义规则

  • 优先级最高, 会覆盖包原本规则
import { mock, initDictionary, dictionary } from '../src'

// 可以查看已经设置的规则字典
dictionary

initDictionary({
  'aaa': 'ababab',
  'bbb': function (a = '1', b = '2') {
    return a + '---' + b
  }
})

mock('@bbb(123,456)') // 123---456
mock('@aaa') // ababab

操作符

基础数据类型

| 操作符 | 描述 | 结果 | | :------------: | :----------------: | :----------: | | @char | 字符 | A | | @boolean | 布尔值 | true | | @string | 字符串 | wg0DGEE1s[ | | @string(3,5) | 指定范围长度字符串 | wg0D | | @num | 数字 | 520 | | @num(5,10) | 指定范围数字 | 5 | | @num(5-10.1-2) | 指定范围数字, 和小数点位数 | 5.1 | | @float | 浮点型 | 13.14 |

名称

| 操作符 | 描述 | 结果 | | :-------: | :----------: | --------: | | @name | 英文名 | Ruihuag | | @cname | 中文名 | 关瑞毕 | | @first | 英文名称的名 | Sandra | | @last | 英文名称的姓 | Jose | | @cfirst | 中文姓 | | | @clast | 中文名 | 瑞毕 |

文本

| 操作符 | 描述 |结果| | :-------------: | :----: | :------------------------: | | @title | 标题 |土好保观| | @title(3,30) | 标题 | 传年圆美石所技道只式器知老引明说外海专性油复队运构科文重| | @cword | 中文字 || | @sentence(2) | 句子 | Enim ad aute eiusmod enim occaecat. Aliqua anim dolore eiusmod officia commodo amet nostrud.| | @sent(2) | 句 | Enim ad aute eiusmod enim occaecat. Aliqua anim dolore eiusmod officia commodo amet nostrud.| | @paragraph(2) | 自然段 |     Laboris ex ad duis ... eiusmod ipsum exercitation.    Eiusmod minim aliqua dolor nostrud et. ... cupidatat dolore consequat dolor. | | @para(2) | 自然段 |     Laboris ex ad duis reprehenderit deserunt enim. In laboris ... dolor. |

居住地址

| 操作 | 描述 | 结果 | | :--------------------- | :------------- | :---------------------------------------------- | | region | 地区 | 西北 | | province | 省 | 广东省 | | city | 城市 | 韶关市 | | district | 区域 | 洮北区 | | address | 地址 | 安徽省宣城市宣州区1d8街道6e路69号99栋36单元78号 | | address(RR PP CC DD) | 地址(指定格式) | 东北 山西省 吕梁市 汾阳市 |

补充:

  • RR: 地区
  • PP: 省
  • CC: 城市
  • DD: 地区

其他地址

| 操作 | 描述 | 结果 | | :-------- | :------ | :-------------------------------------- | | @ip | ip | 242.86.47.174 | | @ip6() | ipv6 | e60b:3d50:be5c:ea37:3005:8a35:846e:1aeb | | @domain | web地址 | opubztw.xxq | | @email | 邮箱 | [email protected] |

颜色

  • 待开发
  • color, hex, rgb, rgba, hsl

图片

@image([text[,size[,background[,foreground[,format]]]]])

  • 图片链接
  • text = '': 文字
  • size = '200x200' :图片大小
  • background = '000': 背景图片
  • foreground = 'fff': 文字颜色
  • format: '' | 'png' | 'gif' | 'jpg' = '' : 图片格式

时间

| 操作符 | 描述 | 结果 | | :--------------------------- | :------------- | :-------------------- | | @now | 现在 | 2022-06-08 16:58:16 | | @now(YYYY-MM-DD HH:mm:ss) | 现在 | 2022-06-08 16:58:16 | | @date | 日期 | 2021-09-27 | | @date(YYYY-MM-DD) | 日期 | 2022-03-28 | | @date(YYYY-MM-DD HH:mm:ss) | 日期 | 2020-03-24 22:58:16 | | @time | 时间 | 22:58:16 | | @time(HH:mm:ss) | 时间 | 04:58:16 | | @time(YYYY-MM-DD HH:mm:ss) | 时间 | 2020-06-27 22:58:16 | | @timeStamp | 时间戳 | 1604703768135 | | @nowTimeStamp | 当前时间时间戳 | 1604703768135 |

特殊

|操作符| 描述 |结果| | :----------- | :---: | :-----------------------: | | @id | id | 3191230364936506 | | @uuid | uuid | 326be748-57bd-c2d0-84f4-99bb488a4292 | | @uuid(xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx) | uuid | 326be748-57bd-c2d0-84f4-99bb488a4292 |