# mock2js

> 生成随机数据 & 拦截 Ajax 请求, 增强版。

Latest version **1.0.6** (published 2018-02-27) · 0 weekly downloads

## Install

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

Provides the command `random`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-02-27 |
| First published | 2018-02-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | nuysoft@gmail.com |
| Maintainers | wapznw |
| Keywords | mock, mockJSON, mockAjax |

## Links

- npm: https://www.npmjs.com/package/mock2js
- Repository: https://github.com/wapznw/Mock
- Homepage: http://mockjs.com/
- Issues: https://github.com/wapznw/Mock/issues
- npm.io page: https://npm.io/package/mock2js

## Dependencies (1)

- [commander](https://npm.io/package/commander.md) *

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.6 (latest) — 2018-02-27
- 1.0.5 — 2018-02-26
- 1.0.4 — 2018-02-24
- 1.0.3 — 2018-02-24
- 1.0.2 — 2018-02-24
- 1.0.1 — 2018-02-24
- 1.0.1-beta3 — 2018-02-24

## README

# Mock.js
<!-- 模拟请求 & 模拟数据 -->
[![Build Status](https://travis-ci.org/nuysoft/Mock.svg?branch=refactoring)](https://travis-ci.org/nuysoft/Mock)

<!-- [![Coverage Status](https://coveralls.io/repos/nuysoft/Mock/badge.png?branch=refactoring)](https://coveralls.io/r/nuysoft/Mock?branch=refactoring)
[![NPM version](https://badge.fury.io/js/mockjs.svg)](http://badge.fury.io/js/mockjs)
[![Bower version](https://badge.fury.io/bo/mockjs.svg)](http://badge.fury.io/bo/mockjs)
[![Dependency Status](https://gemnasium.com/nuysoft/Mock.svg)](https://gemnasium.com/nuysoft/Mock)
[![spm package](http://spmjs.io/badge/mockjs)](http://spmjs.io/package/mockjs) -->

Mock.js is a simulation data generator to help the front-end to develop and prototype separate from the back-end progress and reduce some monotony particularly while writing automated tests.

The official site: <http://mockjs.com>

## Demo

mock.js
```javascript
import Mock from 'mock2js'

const rules = {
  // Support type as Object and Array
  'GET /api/users': {users: [1, 2]},

  '/api/users/1': {id: 1},
  '/api/users/2': (req, res) => {
    setTimeout(() => {
      res.send({id: 2, name: 'jack'})
    }, 3000)
  },

  'POST /api/users/create': () => {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve('ok 123')
      }, 1000)
    })
  },
};

Mock.mockWithRules(rules);

```
main.js
```javascript
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import '../mock'


/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>'
});

```
ajax:
```javascript
axios.get('/api/users/2').then(res=>{
  console.log(res.data);
})
```

## Features

* Generate simulated data according to the data template
* Provide request/response mocking for ajax requests
* ~~Generate simulated data according to HTML-based templates~~

This library is loosely inspired by Elijah Manor's post [Mocking
Introduction](http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html), [mennovanslooten/mockJSON](https://github.com/mennovanslooten/mockJSON), [appendto/jquery-mockjax](https://github.com/appendto/jquery-mockjax) and [victorquinn/chancejs](https://github.com/victorquinn/chancejs/).

## Questions?
If you have any questions, please feel free to ask through [New Issue](https://github.com/nuysoft/Mock/issues/new).

## Reporting an Issue
Make sure the problem you're addressing is reproducible. Use <http://jsbin.com/> or <http://jsfiddle.net/> to provide a test page. Indicate what browsers the issue can be reproduced in. What version of Mock.js is the issue reproducible in. Is it reproducible after updating to the latest version?

## License
Mock.js is available under the terms of the [MIT License](./LICENSE).

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