# miz

> Generate mock data, just like a person.

Latest version **1.0.1** (published 2021-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install miz
pnpm add miz
yarn add miz
bun add miz
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-02-02 |
| First published | 2021-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | hustcc |
| Maintainers | atool |
| Keywords | mock, faker, miz, mock-data, fake-variable |

## Links

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

## 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
- [@versini/auth0-auth-js-stub](https://npm.io/package/@versini/auth0-auth-js-stub.md) — 0 weekly downloads
- [@loutre-run/core](https://npm.io/package/@loutre-run/core.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-prism](https://npm.io/package/@crvouga/mockingbird-service-prism.md) — 0 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-02-02
- 1.0.0 — 2021-02-02
- 0.0.1-beta.1 — 2021-01-29

## README

# miz

> (< 800b) Generate fake / mock structured variable in a modern, human-readable way. Just like a person.
>
> 用一个现代的、可读的方式来生成用于测试的假数据。

[![npm Version](https://img.shields.io/npm/v/miz.svg)](https://www.npmjs.com/package/miz)
[![Build Status](https://github.com/hustcc/miz/workflows/build/badge.svg)](https://github.com/hustcc/miz/actions)
[![Coverage Status](https://coveralls.io/repos/github/hustcc/miz/badge.svg?branch=master)](https://coveralls.io/github/hustcc/miz?branch=master)
[![npm License](https://img.shields.io/npm/l/miz.svg)](https://www.npmjs.com/package/miz)


## Features

⚡️  Simple but highly perfection API  
🐣 Tiny footprint (< 800b)  
👓 Customize  
🎃 3 types of bundles exposed: ESM, CJS and UMD  
🔥 TypeScript Typings readily available  
🎸 Browser and NodeJs supported  
🎯 End-to-end testing with GitHub Action  


## Install

```bash
$ npm i --save miz
```


## Usage

```ts
import { M } from 'miz'; // ES6

const m = M.arrayOf(M.shape({
  id: M.number(10000, 1000000),     // id is between 10000 ~ 1000000.
  name: M.string(6),                // 6 length random string.
  sex: M.bool(),                    // random true or false.
  city: 'hz',                        // constant value.
  work: M.oneOf(['QA', 'FED'])      // random from array
}), 2);                              // list length is 2.

m.mock();
```

Then will get the mock variable like below:

```ts
[{
	id: 757852,
	name: 'mU7RTB',
	sex: false,
	city: 'hz',
	work: 'FED'
}, {
	id: 359987,
	name: 'jWuKxX',
	sex: true,
	city: 'hz',
	work: 'FED'
}]
```


## API & Mocker

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

 - **M.bool()**

```ts
M.bool().mock(); // true
```

 - **M.number(min[, max = min, fixed = 0])**

```ts
M.number(1, 9, 2).mock(); // 4.71
```

 - **M.string([len = 8])**

```ts
M.string(6).mock(); // `Qv_teE`
```

- **M.constant(value)**

```ts
M.constant('hello, hustcc.').mock(); // `hello, hustcc`
M.constant(null).mock(); // got null
```

 - **M.oneOf(valueArray)**

```ts
M.oneOf(['hustcc', 'imcxl']).mock(); // hustcc
```

 - **M.arrayOf(mocker[, min = 20, max = min])**

```ts
// got an array which contains string, and array length 10 ~ 20.
M.arrayOf(VT.string(4), 10, 20);.mock(); 
```

 - **M.shape(mockerObject)**

```ts
// random value object.
M.shape({
  name: M.string(10),
  id: M.number(10000, 1000000),
  sex: M.bool(),
  city: 'hz',
}).mock();
```
 
 - **M.apply(Function)**

```ts
// will got number generate by fucntion Math.random()
M.apply(() => Math.random()).mock(); 
```

> More `Mocker` needed, welcome to `send a pull request`, or put an issue to me.


## License

ISC@[hustcc](https://github.com/hustcc).

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