# mock-variable

> Generate fake / mock structured variable.

Latest version **0.0.2** (published 2017-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install mock-variable
pnpm add mock-variable
yarn add mock-variable
bun add mock-variable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-09-16 |
| First published | 2017-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | hustcc |
| Maintainers | atool |
| Keywords | mock, faker, mock-variable, mock-data, fake-variable |

## Links

- npm: https://www.npmjs.com/package/mock-variable
- Repository: https://github.com/hustcc/mock-variable
- Homepage: https://github.com/hustcc/mock-variable#readme
- Issues: https://github.com/hustcc/mock-variable/issues
- npm.io page: https://npm.io/package/mock-variable

## Dependencies (1)

- [fixed-round](https://npm.io/package/fixed-round.md) ^1.0.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [astro-better-toc](https://npm.io/package/astro-better-toc.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-fcm](https://npm.io/package/@crvouga/mockingbird-service-fcm.md) — 0 weekly downloads
- [jabber](https://npm.io/package/jabber.md) — 0 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2017-09-16
- 0.0.1 — 2017-09-15

## README

# mock-variable

> [WIP] Generate fake / mock structured variable in a modern, human-readable way.
>
> 用一个现代的、可读的的方式来生成用于测试的假数据。

[![Ver](https://img.shields.io/npm/v/mock-variable.svg)](https://www.npmjs.com/package/mock-variable) [![Build Status](https://travis-ci.org/hustcc/mock-variable.svg?branch=master)](https://travis-ci.org/hustcc/mock-variable) [![Coverage Status](https://coveralls.io/repos/github/hustcc/mock-variable/badge.svg?branch=master)](https://coveralls.io/github/hustcc/mock-variable) [![npm download](https://img.shields.io/npm/dm/mock-variable.svg)](https://www.npmjs.com/package/mock-variable)


## 1. Install

> **npm i --save mock-variable**

Then import it.

```js
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](tests/test.js).

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](tests/test.js) file.

 - Simple usage

```js
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`

```js
var mocker = MV.arrayOf(VT.string(4), 10, 20);

mocker.mock(); // got an array which contains string, and array length 10 ~ 20.
```

 - `shape`

```js
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

```js
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](https://github.com/hustcc).

---
_Source: https://npm.io/package/mock-variable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
