• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Powerful data generator tool.

yod-mock

Join the chat at https://gitter.im/qiu8310/yod-mock NPM version Build Status Coverage Status Dependency Status

本项目主要用来在测试环境中生成测试数据用的,另外也可以在命令行上快速生成简单测试数据。

背景

  • 前端程序员会因为后端没有接口数据,开发某些功能可能就不太方便
  • 而后端程序员常会被前端程序员催促给接口,给数据,但你也还没开发完时会显得他们很烦人

此工具就是希望在前后端都没有数据的情况下生成大量随机的测试数据

Features:

  • 语法简洁,学习成本低,功能强大
  • 支持所有 JS 原生的函数
  • 支持所有 lodash 的函数
  • 支持自定义新的 type 和 modifier
  • 支持配置系统现有的数据(使用 yod.config('system.xxx', ...)

在线体验本项目的功能

Install

CLI

npm install --global yod-mock
  • Using yod image to get a random image
  • Using yod image -c to get a random image and copy it to clipboard
  • Using yod image .repeat 10 to get 10 random images

Node.js

npm install --save-dev yod-mock

Browser

bower install --save-dev yod-mock

Usage

DEMO:(Edit this demo online

/*

@Self:   Current plain object
@Parent: Parent plain object
@Config: Config item

*/

// Define an `User` type
yod.type('User', {
  firstName: '@First',              // Get a random firstName
  lastName: '@Last',
  sex: '@Sex',
  fullName: '@Self.firstName @Self.lastName',  // Join current object's firstName and lastName
  nickName: '@Nick',
  chineseName: '@ChineseName',
  age: '@Age(adult)',               // Call @Age with a argument
  to100: '` 100 - @Self.age `',     // Execute javascript code
  telephone: '@Tel',
  avatar: '@Avatar',
  others: {
     words: 'Hello, my name is @Parent.fullName, you can call me @Parent.nickName.',
     bestFriends: '@Nick.repeat(2, 3).join(", ")',    // Call native array's join function
     myFirstNameLength: '@Parent.firstName.length',   // Call native string's length attribute
     favouriteLetter: '@([A, B, C]).sample'           // Call lodash sample function
  }
});

// Use `User` type to generate an object with ten users in it
console.log(yod({
    status: 'ok',
    list: '@User.repeat(10)'
}));

// or Use `User` type to generate directly array
// console.log(yod('@User.repeat(10)'));

Types

BASIC

LOCATION

MEDIA

MIXED

TEXT

USER

WEB

Modifiers

Support all function in lodash:

yod('@([1, 2, 3]).sample');   // equal to `_.sample([1, 2, 3])`
yod('@Int.repeat(10).uniq');  // equal to `_.uniq(yod('@Int.repeat(10)'))`

Support all function in native javascript:

yod('@([a, b, c]).join("-")'); // equal to `['a', 'b', 'c'].join('-')`
yod('@String.replace(a, b)');  // equal to `yod('@String').replace('a', 'b')`

BASIC

Reference

  • yod:本项目的核心引擎(我写的)。
  • mockjs:阿里出的,也不错,但学习成本较高,也不够强大。
  • chance:国外的一个 mock 库,代码很简洁,但不适合中国人用。
  • jsonfy:将任意的字符串解析成 JS 里的数据,类似于 JSON.parse,但语法要求没它那么严格(我写的)。
  • sscan:字符串分析器,很多复杂的解析用正则表达式是满足不了要求的,所以需要把字符串化分成字符来一个个解析(我写的)。
  • elegant.def:优雅的定义 JS 函数,很多情况下我们定义了函数要处理参数的各种情况,用了它处理函数参数就非常简单了(我写的)。

TODO

History

ChangeLog

License

Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.

More Repositories

1

minapp

重新定义微信小程序的开发
TypeScript
925
star
2

smart-npm

Auto switch registry according your npm command.
JavaScript
331
star
3

tinypng

基于 TinyPNG 封装的一个支持nodejs、命令行和 webpack 的图片压缩工具
TypeScript
112
star
4

crontab

windows 版 crontab
Java
59
star
5

dot-template

create new files according to pre-defined templates
TypeScript
28
star
6

deploy-asset

对前端静态资源进行 Minify, Revisioning 以及 Uploading
JavaScript
13
star
7

elegant-api

优雅的定义 API 接口
JavaScript
10
star
8

holiday

holiday api (only for china now)
TypeScript
8
star
9

require-resolve

Use the node way to resolve required path to absolute path.
JavaScript
7
star
10

ccode

程序员命令行工具集
JavaScript
6
star
11

grunt-deploy-asset

部署静态文件到远程CDN服务器(支持 七牛/FTP/又拍云)
JavaScript
5
star
12

check-style

Using jshint and jscs and eslilnt to check your project javascript files style.
JavaScript
5
star
13

mora-common

TypeScript
4
star
14

post-web

For myself use only
JavaScript
4
star
15

mora-scripts

Some collection scripts by myself
JavaScript
4
star
16

tty-wrap

Wrap text on terminal, support East Asian Character, Combinint Marks and Surrogate Pairs.
JavaScript
3
star
17

data-transform

将源数据转换成一个全新的规范的数据
TypeScript
3
star
18

doc

My doc collection
2
star
19

imagemin

压缩图片
TypeScript
2
star
20

cache-store

数据缓存,支持 React 组件之间数据共享。
JavaScript
2
star
21

swagger-parser

TypeScript
2
star
22

yod

Fantasy data generator.
JavaScript
2
star
23

index-loader

根据 map 文件按需加载需要的脚本
TypeScript
2
star
24

ChromePlugins

Chrome plugins development hub
JavaScript
2
star
25

blog

just a test project
CSS
1
star
26

ylog

Why another logger? That's a good question!
JavaScript
1
star
27

tty-text-size

Get string's real length on ternimal.
JavaScript
1
star
28

dep

Parse shallow depends to deep depends
JavaScript
1
star
29

min-asset

Minify any static file type, includes html, css, js, json, image.
JavaScript
1
star
30

eslint-plugin-serpent

eslint plugin for https://github.com/qiu8310/serpent
JavaScript
1
star
31

style-manager

Manage style, add/replace/delete rules, support media.
JavaScript
1
star
32

demo-web-babel

web project based on karma and mocha and use es6
JavaScript
1
star
33

jsonfy

Parse simple string to json object
JavaScript
1
star
34

generator-nody

A node generator for Yeoman, with mocha, gulp, istanbul, jshint and jasmine supported
JavaScript
1
star
35

qiu8310.github.io

my jekyll blog
JavaScript
1
star
36

host

windows host file manage (ip v4 for now)
JavaScript
1
star
37

naming-transform

Transform object keys naming style.
JavaScript
1
star
38

grunt-spa-bootstrap

用一个固定的HTML文件启动单页面的应用,解除因为前端修改而引起的后端重新部署问题
JavaScript
1
star