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-variable

v0.0.2

Published

Generate fake / mock structured variable.

Downloads

11

Readme

mock-variable

[WIP] Generate fake / mock structured variable in a modern, human-readable way.

用一个现代的、可读的的方式来生成用于测试的假数据。

Ver Build Status Coverage Status npm download

1. Install

npm i --save mock-variable

Then import it.

import MV from 'mock-variable'; // ES6
var MV = require('mock-variable'); // ES5 with npm

2. API & Mocker

You can assemble the variable structure arbitrarily by using the mockers below:

  • MV.bool()
  • MV.number(min[, max = min, fixed = 0])
  • MV.string([len = 8])
  • MV.arrayOf(mocker[, min = 20, max = min])
  • MV.shape(mockerObject)
  • MV.oneOf(valueArray)
  • MV.constant(value)
  • MV.apply(Function)

After you got the mocker, then use mocker.mock() to get the fake data.

You can see all the usage in the test cases file.

If more Mocker are needed, welcome to send a pull request, or put an issue to me.

3. Usage examples

Here is some examples. More you can see in tests/test.js file.

  • Simple usage
MV.number(1, 9, 2).mock(); // 4.71
MV.string(6).mock(); // `Qv_teE`
MV.bool().mock(); // true / false
MV.oneOf(['hustcc', 'imcxl']).mock(); // random element from the array
MV.constant('hello, hustcc.').mock(); // `hello, hustcc`
MV.constant(null).mock(); // got null
MV.apply(function() { return Math.random(); } )).mock(); // will got number generate by fucntion Math.random()
  • arrayOf
var mocker = MV.arrayOf(VT.string(4), 10, 20);

mocker.mock(); // got an array which contains string, and array length 10 ~ 20.
  • shape
var mocker = MV.shape({
  name: MV.string(10),
  id: MV.number(10000, 1000000),
  sex: MV.bool(),
  city: 'hz',
});

mocker.mock(); // got a random value object.
  • complex usage
var mocker = MV.arrayOf({
  name: MV.string(),
  id: MV.number(10000, 1000000),
  sex: MV.bool(),
  city: 'hz',
});

mocker.mock(); // will got an array of users, and the list's length is 20.

4. Test

npm i

npm t

License

ISC@hustcc.