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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mock-yaml

v1.0.3

Published

mockjs 和 yaml,方便模拟数据

Downloads

16

Readme

mock-yaml

用yaml语法作为数据结构,兼容绝大部分mockjs语法,同时获得yaml的强大扩展能力。

安装

服务端npm安装

$ npm install mock-yaml --save-dev

客户端引入script脚本

<script src="dist/mockyaml.js"></script>

使用

使用示例

how to use

方法

  • toJSON: 将yaml文件转成json
  • toYAML: 将json转成yaml,暂不支持mockjs规则自动转成yaml语法的规则
  • Random: 扩展mockjs的占位符,也即Mock.Random
  • Mock: mockjs对象

相关文档

TODO

  • [todo] xhr mock,增强且覆盖尽可能多的库
  • [todo] 增加mock占位符
  • [todo] 转换器页面增加链接到GitHub主页

mockjs模板在mock-yaml的语法

属性:规则模板         具体规则   初始值
key:  !str/min-max     1-3        ★

mockjs数据模板

|类型 | mockjs数据模板 | mock-yaml示例语法 | 示例结果 | 备注 | |------------------|---------------------|---------------------------|-------------------|-------| |string | min-max | key: !str/min-max 1-3 ★ | {key: "★★"} | | |string | count | key: !str/count 4 ★ | {key: "★★★★"} | | |number | min-max | key: !num/min-max -10-10 1| {key: -3} | | |number | min-max.dmin-dmax | key: !num/min-max.dmin-dmax 1-10.2-3 10 | {key: 9.77} | | |number | min-max.dcount | key: !num/min-max.dcount 1-10.3 1 | {key: 1.104} | | |number | count.dmin-dmax | key: !num/count.dmin-dmax -30.1-2 1 | {key: -30.9} | | |number | count.dcount | key: !num/count.dcount -23.4 1 | {key: -23.7824} | | |number | count | | | 没有实现 | |number | +step | | | 没有实现 | |boolean | 1 | key: !bool/1 | {key: false} | 可以只写规则模板!bool/1,不用写具体规则和初始值| |boolean | min-max | key: !bool/min-max 1-3 true | {key: false} | | |object | count | | | 见示例 | |object | min-max | | | 见示例 | |array | 1 | | | 见示例 | |array | +1 | | | 没有实现 | |array | min-max | | | 见示例 | |array | count | | | 见示例 | |function | !!js/function > | | | yaml内置 | |regexp | | | | 见示例 | |regexp | min-max | | | 没有实现 |

mockjs占位符

|类型 | 占位符 | 兼容(default Y) | 备注 | |------------------|-------------------|------------|-------| |all | all | Y | |

注意事项

yml语法的@字符已被保留,所以如果存在以@为首字母的字符串(比如说mockjs的占位符),那么需要用引号将其包裹起来,如果@不是首字母,那么可以省略引号。

placeholder: 
    - '@url'
    - hello @string(5,10)

示例

  • file.yml
root: 
  str:
    -10--1: !str/min-max -10--1 ★
    1-10: !str/min-max 1-10 ★
    4: !str/count 4 ★
  number:
    -10-10: !num/min-max -10-10  1
    1-10.2-3: !num/min-max.dmin-dmax 1-10.2-3  10
    -10-1.1-4: !num/min-max.dmin-dmax -10-1.1-4  10
    1-10.3: !num/min-max.dcount 1-10.3 1
    1-10.-3: !num/min-max.dcount 1-10.-3 1
    -30.1-2: !num/count.dmin-dmax -30.1-2 1
    -23.4: !num/count.dcount -23.4 1
  boolean:
    anychar: !bool/1 1 1
    true1-3: !bool/min-max 1-3 true
    false1-3: !bool/min-max 1-3 false
  object:
    2: &aliasobj1  !object/count
      /rule: 2
      310000: 北京市
      320000: 江苏省
      330000: 浙江省
      340000: 安徽省
    1-3: &aliasobj2 !object/count
      /rule: 1-3
      310000: 北京市
      320000: 江苏省
      330000: 浙江省
      340000: 安徽省
  array:
    1-3: !array/min-max &alias1
      - 1-3
      - 北京市
      - 江苏省
      - 浙江省
      - 安徽省
    2: !array/count 
      - 2
      - 北京市
      - 江苏省
      - 浙江省
      - 安徽省
  func: !!js/function >
      function foobar() {
        return 'Wow! JS-YAML Rocks!';
      }
  regexp: 
    - !regexp/1 /[a-z][A-Z][0-9]/
    - !regexp/1 /\w\W\s\S\d\D/
    - !regexp/1 /\d{5,10}/
    - !regexp/1 /@color/
  placeholder:
    - '@check' 
    - '@url'
    - hello @string(5,10)
    - '@now'
  alias: *alias1
  aliasobj: 
    <<: *aliasobj1
    <<: *aliasobj2
  • json
{
  "root": {
    "str": {
      "4": "★★★★",
      "-10--1": "",
      "1-10": "★★★★★★★"
    },
    "number": {
      "-10-10": 2,
      "1-10.2-3": 9.361,
      "-10-1.1-4": -8.07,
      "1-10.3": 2.412,
      "1-10.-3": 8.6158,
      "-30.1-2": -30.37,
      "-23.4": -23.9829
    },
    "boolean": {
      "anychar": false,
      "true1-3": false,
      "false1-3": false
    },
    "object": {
      "2": {
        "310000": "北京市",
        "320000": "江苏省"
      },
      "1-3": {
        "310000": "北京市",
        "330000": "浙江省",
        "340000": "安徽省"
      }
    },
    "array": {
      "2": [
        "北京市",
        "江苏省",
        "浙江省",
        "安徽省",
        "北京市",
        "江苏省",
        "浙江省",
        "安徽省"
      ],
      "1-3": [
        "北京市",
        "江苏省",
        "浙江省",
        "安徽省",
        "北京市",
        "江苏省",
        "浙江省",
        "安徽省"
      ]
    },
    "regexp": [
      "fG8",
      "V@
u1\"",
      "54677466",
      "#79f2af"
    ],
    "placeholder": [
      "extend success",
      "tn3270://vdqsmnf.sa/weo",
      "hello GmFmah",
      "2017-06-21 22:42:15"
    ],
    "alias": [
      "北京市",
      "江苏省",
      "浙江省",
      "安徽省",
      "北京市",
      "江苏省",
      "浙江省",
      "安徽省"
    ],
    "aliasobj": {
      "310000": "北京市",
      "320000": "江苏省",
      "330000": "浙江省",
      "340000": "安徽省"
    },
    "func": "Wow! JS-YAML Rocks!"
  }
}