Git Product home page Git Product logo

data.js's Introduction

data.js

随机模拟数据 生成器

免写规则,自动推测返回类型

示例

自动

var userRule = {
  id: 'auto',
  name: 'auto',
  phone: 'auto',
  avatar: 'auto',
  isAdmin: 'auto',
  departmentId: 'auto',
}

var user = Data(userRule) // {id:1, name:'李xx', avatar:'img url', isAdmin:true, ...}

var userList = Data([userRule]) // [{}, ...] 长度随机[0-10],可指定

指定

Data('id') //=> 1

Data('date') // => '2018/8/8 8:8:8'

Data({
  total: 'number(10, 100)'
})
// => {total: 51}

Data({
  list: [
    {id: 'id'},
    [3, 15]
  ]
})
// => 指定list数组长度[3,15]

语法

// 基本类型
Data('type')

// 对象
Data({
  key: 'type',
  k: 'auto',
  ...
})

// 数组
Data(['type', [min,max]?])

// 嵌套
Data([
  {
    key: 'type',
    list: ['type', [min,max]?]
  },
  [min, max]?
])

type

  • { key: 'auto' } 自动根据 key 推测需要返回的类型

    • key 键名
  • id(base=1, step=1) 自增整数

    • base id起始值
    • step 自动步长
  • number(min=0, max=100, fixed=0) 数字类型

    • min 最小值
    • max 最大值
    • fixed 小数位数
  • boolean(rate=0.5) bool类型

    • rate 返回 true 的概率
  • date(min=-1y, max=+1y) 日期类型

    • min 最小日期
    • max 最大日期
  • string(min=5, max=15) 字符串

    • min 最小长度
    • max 最大长度
  • url(min=15, max=35) url地址

    • min 最小长度
    • max 最大长度
  • img(width=50-300, height=50-300) 图片url

    • width 宽度
    • height 长度
    • bg 背景颜色
    • text 文本
  • imgBase64(width=200, height=100, bg='#eee', text='$width x $height') base64图片

    • width 宽度
    • height 长度
    • bg 背景颜色
    • text 文本
  • video 视频地址

  • color(min=0, max=255) #颜色

    • min rgb最小取值
    • max rgb最大取值
  • email 电子邮箱

  • phone 手机号

  • name 两三个字的中文姓名

  • zh(min=25, max=min) 中文字符

    • min 最小长度
    • max 最大长度
  • repeat(char, min, max) 重复字符

    • char 字符
    • min 最小次数
    • max 最大次数
  • { key: type } 对象类型

    • key 键名
    • type 键值,任意类型,可用类型名称生成数据,如: {userId: 'id'}
  • [ type, [min=0, max=min||10]? ] 数组类型,以第一个元素为模板生成指定长度的数组

    • type 任意类型
    • min 最小长度
    • max 最大长度

data.js's People

Contributors

wushufen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.