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

blind-monk

v0.0.1

Published

A Tool for Data Mock and Check

Downloads

3

Readme

Blind Monk

A Tool for Data Mock and Check

Data Mock

example

const BlindMonk = require('blind-monk');

const reqMockData = BlindMonk.mockData({
  a1: 'string',
  a2: 'number|0-100.1-4',
  a3: ['string'],
  a4: ['string', 'number'],
  a5: [{
    a51: 'string',
    a52: 'boolean',
  }],
  a8: BlindMonk.define({
    define: 'string',
    required: false,
  }),
  a9: BlindMonk.define({
    define: 'string',
    callback: (Mock) => {
      return Mock.Random.cword();
    },
  }),
});

output

{
  "a1": "gyvmycrwe",
  "a2": 54.5038,
  "a3": [
    "gsgaydf",
    "xsen",
    "jguugioh"
  ],
  "a4": [
    "vpcdz",
    820
  ],
  "a5": [
    {
      "a51": "wdruwhwrty",
      "a52": false
    },
    {
      "a51": "qmbbqhp",
      "a52": true
    },
    {
      "a51": "ofnabsll",
      "a52": false
    },
  ],
  "a8": "gyagbmtbi",
  "a9": "主"
}

Data Check

example

const BlindMonk = require('blind-monk');

BlindMonk.check({
  // disabled: true, // 是否对请求参数进行验证
  mock: true, // 是否构造请求参数数据
  params: {
    a: {
      a1: 'string',
      a2: 'number|0-100',
      a3: ['string', 'number'],
      a4: ['string'],
      a5: BlindMonk.define({
        define: {
          a51: 'string',
          a52: 'boolean',
        }
      }),
    },
  }
}, {
  a: {
    a1: 'hisheng',
    a2: 20,
    a3: ['handsome', 21],
    a4: ['xx', 'yy', 'zz'],
    a5: {
      a51: 'awesome',
      a52: false,
    },
  }
}).then(params => {
  console.log('>>> done', JSON.stringify(params, null, 2));
}).catch(err => {
  console.log('>>> check failed: \n', err);
});

output

>>> checking data
>>> done {
  "a": {
    "a1": "fmpjrfbxn",
    "a2": 35,
    "a3": [
      "yihgqyqc",
      346
    ],
    "a4": [
      "jgdppufsga",
      "dleno",
      "oabycv",
      "lefxmlwqts",
      "gviuk",
      "hzakr",
      "fitddkue",
      "wpeefp",
      "lbcvcly"
    ],
    "a5": {
      "a51": "nygcyr",
      "a52": true
    },
  }
}

Doc

mock template is based on Mock.js, but a little difference.

string

BlindMonk.mockData({
  a1: 'string',
  // min: min length of string, max: max length of string
  a2: 'string|min-max',
  // detail define
  a3: BlindMonk.define({
    define: 'string',
    required: false, // will be ignored if key not exist in data
  }),
});

'string|repeatCount' is not supported

number

BlindMonk.mockData({
  a1: 'number',
  // generate a number between [min, max]
  a2: 'number|min-max',
  // generate a number between [min, max] and decimal length berween [minbit, maxbit]
  a3: 'number|min-max.minbit-maxbit',
  // detail define
  a4: BlindMonk.define({
    define: 'number',
    required: false,
  }),
});

'number|+1' is not supported

boolean

BlindMonk.mockData({
  a1: 'boolean',
  // generate a boolean probability is about (min / (min + max))
  a2: 'boolean|min-max',
  // detail define
  a3: BlindMonk.define({
    define: 'boolean',
    required: false,
  }),
});

array

BlindMonk.mockData({
  a1: ['string'],
  a2: ['string', 'number'],
  a3: ['string', 'number', {
    a31: 'string',
    a32: 'boolean',
  }],
});

object

BlindMonk.mockData({
  a1: {
    a11: 'string',
    a12: ['string', 'number'],
  },
});