ymockjs

0.0.1 • Public • Published

ymockjs -- Node Module for Qunar Mock JS

API

Mock

YMock.mock(template, param);

根据模板生成 Mock 数据。

  • template: Mock 模板
  • param: 参数

Vaild

YMock.valid(template, data, param);

验证数据正确性。

  • template: Mock 模板
  • data: 数据
  • param: 参数

Example

var YMock = require('ymockjs');

var schema = {
    "name": "@hotelname('酒店')",
    "*date": "@date('yyyy-MM-dd')",
    "*description": "@ctitle",
    "*author": "{{author}}",
    "abc": "@function(return $max + $len + 1;)",
    "url": "@url('http', 'ued.qunar.com')",
    "email": "@email('gmail.com')",
    "number": "@natural(1, {{max}})",
    "dateRange": "@dateRange(true)",
    "obj|0-{{len}}": [{
        "mobile": "@mobilephone",
        "tel": "@telphone",
        "*roomtype": "@roomtype",
        "*address": "@hoteladdress"
    }]
}

var data = YMock.mock(schema, {
    author: 'adwon.lin',
    max: 5,
    len: 3
});

console.log('Mock: ', JSON.stringify(data, {}, 4));

console.log('Valid 1: ', YMock.valid(schema, {
    name: '七天酒店',
    description: '这是一个描述',
    author: "adwon.lin",
    abc: 9,
    date: '2016-02-28',
    url: 'http://ued.qunar.com/mobile/',
    email: 'edwon.lim@gmail.com',
    dateRange: {
        startDate: '2016-01-03',
        endDate: '2016-01-04'
    },
    number: 5,
    obj: [{
        mobile: "13811111111",
        tel: "010-87652353",
    }]
}, {
    author: 'adwon.lin',
    max: 5,
    len: 3
}));

console.log('Valid 2: ', YMock.valid(schema, {
    name: '七天酒店',
    number: 11,
    url: 'https://ued.qunar.com/mobile/',
    email: 'adwon.lin@qunar.com',
    dateRange: {
        startDate: '2016-01-03',
        endDate: '2016-01-02'
    },
    obj: [{
        mobile: "23811111111",
        tel: "01087652356",
    }]
}));

Readme

Keywords

none

Package Sidebar

Install

npm i ymockjs

Weekly Downloads

1

Version

0.0.1

License

none

Last publish

Collaborators

  • ymfe