sp-mockjs
v1.0.3
Published
Common mock data by mockjs
Downloads
5
Readme
sp-mock
Common mock data by mockjs
Install
npm i mockjs sp-mockjs //or yarn add mockjs sp-mockjs
CDN
<script src="https://unpkg.com/mockjs/dist/mock-min.js"></script>
<script src="https://unpkg.com/sp-mockjs/dist/index.min.js"></script>
<script>
__Mock.name();
// return '陈玲'
</script>
Usage
const {
name,
number,
text,
email,
phoneNumber,
date,
image,
ip,
url,
color,
region,
idCard
} = require("sp-mockjs")
name(obj = {})
- {Object} obj
- {Number} len
- {Boolean} isEnglish = false
name(); // return '陈玲' name({ len: 2 }) // return ['李殊','张爽'] name({ isEnglish: true }) // return 'Alice Paul' name({ len: 2, isEnglish: true }) // return ['Jan Sen','Sword Hadon']
- {Object} obj
number(obj = {})
- {Object} obj
- {Number} len
- {Number} min = 0
- {Number} max = 100
- {Boolean} isFloat = false
- {Number} toFixedLen = 2
number() // return 13 number({ len: 2 }) // return [24, 2] number({ isFloat: true }) // return 1.32 number({ len: 2, min: -10, max: 10, isFloat: true, toFixedLen: 3 }) // return [ '-10.355', '1.319' ]
- {Object} obj
phoneNumber(obj = {})
- {Object} obj
- {Number} len
phoneNumber() // return '13718239930' phoneNumber({ len: 2 }) //return ['13829120020', '15920393302']
- {Object} obj
text(obj = {})
- {Object} obj
- {Number} len
- {Boolean} isEnglish = false
text() // return '放两文示后和再万用值候院容位委它半。' text({ len: 2 }) //return ['放两文示后和再万用值候院容位委它半。', '好三生毛去任七真山世完相。'] text({ isEnglish: true }) //return 'Ncwthzxmu emkjjvo nop lbenqup emhumxqv exc qgw cpsfjihu khbri qyfqbbr nyfviby ugiz ehdsoe ctjnoq jwcdqt.'
- {Object} obj
date(obj = {})
- {Object} obj
- {Number} len
- {String} format = 'yyyy-MM-dd': see more
date() // return '2001-11-02' date({ len: 2 }) //return ['2001-11-02', '2011-01-22'] date({ len: 2, format: 'MM-dd' }) //return ['11-02', '01-22']
- {Object} obj
email(obj = {})
- {Object} obj
- {Number} len
- {String} domain = 'mockdata.com'
email() // return '[email protected]' email({ len: 2 }) //return ['[email protected]', '[email protected]'] email({ len: 2, domain: 'alipay.one' }) //return ['[email protected]', '[email protected]']
- {Object} obj
ip(obj = {})
- {Object} obj
- {Number} len
ip() // return '104.74.140.197' ip({ len: 2 }) //return [ '220.215.41.236', '202.168.91.147' ]
- {Object} obj
url(obj = {})
- {Object} obj
- {Number} len
- {String} protocol
- {String} domain
url() // return 'http://mockdata.com/voyxd' url({ len: 2 }) //return [ 'http://mockdata.com/qdwhqywr', 'http://mockdata.com/glenhg' ] url({ len: 2, protocol: 'https', domain: 'alipay.one' }) //return [ 'https://alipay.one/qdwhqywr', 'https://alipay.one/glenhg' ]
- {Object} obj
image(obj = {})
- {Object} obj
- {String} size = '400x300'
- {String} background = '#000000'
- {String} foreground = '#FFFFFF'
- {String} format = 'png'、'gif'、'jpg'
- {String} text
image() // return ''http://dummyimage.com/400x300'' image({ len: 2 }) //return [ 'http://dummyimage.com/400x300', 'http://dummyimage.com/400x300']
- {Object} obj
color(obj = {})
- {Object} obj
- {Number} len
- {String} type = 'hex'、'rgb'、'rbga'、'hsl'
color() // return '#b9f279' color({ len: 2 }) //return ['#f2dd79', '#f2dd79'] color({ len: 2, type: 'hsl' }) //return [ 'hsl(82, 82, 71)', 'hsl(82, 82, 71)' ]
- {Object} obj
region(obj = {})
- {Object} obj
- {Number} len
- {String} type = 'country'、'province'、'city'、'county'
- {Boolean} showParent = false
region() // return '澳门特别行政区' region({ len: 2 }) //return [ '四川省', '河北省' ] region({ len: 2, type: 'country' }) //return [ '智利', '孟加拉' ] region({ len: 2, type: 'county', showParent: true }) //return [ '河北省秦皇岛市北戴河区', '江苏省常州市金坛市' ]
- {Object} obj
idCard(obj = {})
- {Object} obj
- {Object} obj
- {Number} obj.area 6位地区编码
- {Number} obj.year 4位年
- {Number} obj.month 2位月
- {Number} obj.day 2位日
- {Number} obj.policeNum 2位派出所识别号
- {Number} obj.gender 1位性别 0:女 1:南 2:不限
- {Number} obj.len 长度
idCard() // return 513592194904256072 idCard({ len: 2 }) // return [ '55276319660824862X', '194483193107205410' ] idCard({ area: '520100', year: '1969', month: '09', day: '13', policeNum: '99', gender: 0, len: 2 }) // return [ '520100196909139907', '52010019690913994X' ]
- {Object} obj