Mockjs

作者: 习惯芥末味 | 来源:发表于2020-10-17 17:02 被阅读0次

    Mockjs

    一、Node 安装

    # 安装
    npm install mockjs
    
    // 引入mock.js,相当于src=mock.js
    var Mock = require('mockjs')
    // 创建模拟数据
    var data = Mock.mock({
        // 属性 list 的值是一个数组,其中含有 1 到 10 个元素
        'list|1-10': [{
            // 属性 id 是一个自增数,起始值为 1,每次增 1
            'id|+1': 1
        }]
    })
    // 输出结果
    console.log(data)
    // 转换JSON格式
    console.log(JSON.stringify(data, null, 4))
    

    如果想在浏览器测试运行,那么直接在html文件引入以下文件

    <script src='http://mockjs.com/dist/mock.js'></script> 
    

    二、语法规范

    1、Mock.js的语法规范包括两部分:数据模板定义规范和数据占位定义规范
    2、数据模板定义的规范包含3个部分:属性名、生成规则和属性值
    ‘属性名|生成规则’:属性值 // ‘name|rule’:value
    3、字符串、数值有7中生成规则,具体如下表:

    Tables Are Cool
    min-max 生成 min ~ max之间的字符串 “list|1-10”
    count 生成 count 个字符串 ‘list|5’
    min-max.dmin-dmax 生成 min ~ max之间的浮点数,小数点位数在 dmin ~ dmax之间 ‘id|1-10.1-3’:1
    count.dcount 生成 count个字符串,小数点位数为count ‘id|8.2’:1
    min-max.dcount //同上 // 同上
    const obj = {
          name:'Mr.Lee',
          age:'18',
          gender:'男'
    }
    
    const  arr = [ 'a' , 'b' , 'c' , 'd' ]
    const data = Mock.mock({
              'list|1-10':[{
                   //  'id|+1':1 
                   //  'id|1-10.1-3':1    
                   //  'flag|+1':true
                   //  'obj|1-3':1obj
                  'arr|1':arr
              }]
    })
    console.log(data)
    

    4、函数和正则表达式

    Tables Are Cool
    生成规则 说明 示例
    函数 支持函数 'fn|1':function
    正则 支持正则 'reg|1':/[a=z]/

    5、数据定义的占位符 @ ,比较好理解,占领属性值的位置

    'list|5' : [{
          cname : '@name',
          city : '@city',
          full : ''@cname - @city'
    }]
    

    Mock.Random 中的方法与数据模板的 @占位符 一一对应,在需要时还可以为 Mock.Random 扩展方法,然后在数据模板中通过 @扩展方法 引用。例如:

    Random.extend({
        constellation: function(date) {
            var constellations = ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
            return this.pick(constellations)
        }
    })
    Random.constellation()
    // => "水瓶座"
    Mock.mock('@CONSTELLATION')
    // => "天蝎座"
    Mock.mock({
        constellation: '@CONSTELLATION'
    })
    // => { constellation: "射手座" }
    

    三、随机占位符

    1、基础 Base

    布尔值:boolean,随机自然数:natural,随机整数:integer,浮点数:float,随机字符:character,随机字符串:string,整型数组:range

    2、时间 Date

    日期:date,时间:time,日期和时间:datetime,当前的日期和时间:now

    3、图片Iamge

    默认:image,base64编码图:dataImage

    4、颜色Color

    默认:color,有吸引力的颜色:hex,rgb格式色值:rgb,rgba格式:rgba,hsl格式:hsl

    5、文本Text

    一段文本:paragraph,一段中文文本:cparagraph,第一个单词的首字母大写的句子:sentence,一段中文文本:csentence,一个单词:word,一个汉字:cword,一句标题:title,中文标题:ctitle

    6、名字Name

    英文名:first,英文姓:last,英文姓名:name,中文名:cfirst,中文姓:clast,中文姓名:cname

    7、网络Web

    URL地址:url,URL 协议:protocol,域名:domain,顶级域名:tld,邮件地址:email,IP 地址:ip

    8、地址Address

    (中国)大区:region,中国)省(或直辖市、自治区、特别行政区):province,(中国)市:city,(中国)县:county,邮政编码(六位数字):zip

    9、帮助

    把字符串的第一个字母转换为大写:capitalize,字符串转换为大写:upper,字符串转换为小写:lower,从数组中随机选取一个元素,并返回:pick,打乱数组中元素的顺序,并返回:shuffle

    10、其它

    随机生成一个 GUID:guid, 18 位身份证:id,一个全局的自增整数:increment

    • 布尔值 boolean
    Random.boolean()
    // => true
    Random.boolean(1, 9, true)
    // => false
    Random.bool()
    // => false
    Random.bool(1, 9, false)
    // => true
    
    • 随机自然数 natural
    Random.natural()
    // => 1002794054057984
    Random.natural(10000)
    // => 71529071126209
    Random.natural(60, 100)
    // => 77
    
    • 随机整数 integer (输出的值有正有负)
    Random.integer()
    // => -3815311811805184
    Random.integer(10000)
    // => 4303764511003750
    Random.integer(60,100)
    // => 96
    
    • 浮点数 float
    Random.float()
    // => -1766114241544192.8
    Random.float(0)
    // => 556530504040448.25
    Random.float(60, 100)
    // => 82.56779679549358
    Random.float(60, 100, 3)
    // => 61.718533677927894
    Random.float(60, 100, 3, 5)
    // => 70.6849
    
     {
        lower: "abcdefghijklmnopqrstuvwxyz",
        upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
        number: "0123456789",
        symbol: "!@#$%^&*()[]"
    }
    
    • 随机字符 character
    Random.character()
    // => "P"
    Random.character('lower')
    // => "y"
    Random.character('upper')
    // => "X"
    Random.character('number')
    // => "1"
    Random.character('symbol')
    // => "&"
    Random.character('aeiou')
    // => "u"
    
    • 随机字符串string
    Random.string()
    // => "pJjDUe"
    Random.string( 5 )
    // => "GaadY"
    Random.string( 'lower', 5 )
    // => "jseqj"
    Random.string( 7, 10 )
    // => "UuGQgSYk"
    Random.string( 'aeiou', 1, 3 )
    // => "ea"
    Random.string( '壹贰叁肆伍陆柒捌玖拾', 3, 5 )
    // => "肆捌伍叁"
    
    • 整型数组 range
    Random.range(10)
    // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    Random.range(3, 7)
    // => [3, 4, 5, 6]
    Random.range(1, 10, 2)
    // => [1, 3, 5, 7, 9]
    Random.range(1, 10, 3)
    // => [1, 4, 7]
    
    • 日期 date
    Random.date()
    // => "2002-10-23"
    Random.date('yyyy-MM-dd')
    // => "1983-01-29"
    Random.date('yy-MM-dd')
    // => "79-02-14"
    Random.date('y-MM-dd')
    // => "81-05-17"
    Random.date('y-M-d')
    // => "84-6-5"
    
    • 时间time
    Random.time()
    // => "00:14:47"
    Random.time('A HH:mm:ss')
    // => "PM 20:47:37"
    Random.time('a HH:mm:ss')
    // => "pm 17:40:00"
    Random.time('HH:mm:ss')
    // => "03:57:53"
    Random.time('H:m:s')
    // => "3:5:13"
    
    • 日期和时间datetime
    Random.datetime()
    // => "1977-11-17 03:50:15"
    Random.datetime('yyyy-MM-dd A HH:mm:ss')
    // => "1976-04-24 AM 03:48:25"
    Random.datetime('yy-MM-dd a HH:mm:ss')
    // => "73-01-18 pm 22:12:32"
    Random.datetime('y-MM-dd HH:mm:ss')
    // => "79-06-24 04:45:16"
    Random.datetime('y-M-d H:m:s')
    // => "02-4-23 2:49:40"
    
    • 当前的日期和时间 now
    Random.now()
    // => "2014-04-29 20:08:38 "
    Random.now('day', 'yyyy-MM-dd HH:mm:ss SS')
    // => "2014-04-29 00:00:00 000"
    Random.now('day')
    // => "2014-04-29 00:00:00 "
    Random.now('yyyy-MM-dd HH:mm:ss SS')
    // => "2014-04-29 20:08:38 157"
    
    Random.now('year')
    // => "2014-01-01 00:00:00"
    Random.now('month')
    // => "2014-04-01 00:00:00"
    Random.now('week')
    // => "2014-04-27 00:00:00"
    Random.now('day')
    // => "2014-04-29 00:00:00"
    Random.now('hour')
    // => "2014-04-29 20:00:00"
    Random.now('minute')
    // => "2014-04-29 20:08:00"
    Random.now('second')
    // => "2014-04-29 20:08:38"
    
    • 图片image
    Random.image()
    // => "http://dummyimage.com/125x125"
    Random.image('200x100')
    // => "http://dummyimage.com/200x100"
    Random.image('200x100', '#fb0a2a')
    // => "http://dummyimage.com/200x100/fb0a2a"
    Random.image('200x100', '#02adea', 'Hello')
    // => "http://dummyimage.com/200x100/02adea&text=Hello"
    Random.image('200x100', '#00405d', '#FFF', 'Mock.js')
    // => "http://dummyimage.com/200x100/00405d/FFF&text=Mock.js"
    Random.image('200x100', '#ffcc33', '#FFF', 'png', '!')
    // => "http://dummyimage.com/200x100/ffcc33/FFF.png&text=!"
    
    • Base64 图片编码dataImage
    Random.dataImage()
    // => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAH0AAAB9CAYAAACPgGwlAAAFJElEQVR4Xu2dS0hUURzG/1Yqlj2otJe10AqCoiJaFFTUpgcUhLaKCIogKCEiCl0U1SIIF1EIQlFE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QQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQQoiIQSY9QSoCBqW8/CJQT+C8lshm60+8xmAAAAAElFTkSuQmCC"
    Random.dataImage('200x100', 'Hello Mock.js!')
    // => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAALI0lEQVR4Xu2aCXCO1xrH/1nIIrFzUVpLbdHYYt8bWm6rRBWJpcQNg9RWak/t281tqpbWtbRoSS9XEEuZwaXo2EpariqGsdyh0UpjyR6585y57zdvEkn6nWtG5PzfGdO83/c+5z3P73n+53nO+eqCgOFZ4EUCJPBEAi4UCDODBPImQIEwO0ggHwIUCNODBCgQ5gAJ6BFgBdHjRitDCFAghgSabuoRoED0uNHKEAIUiCGBppt6BCgQPW60MoQABWJIoOmmHgEKRI8brQwhQIEYEmi6qUeAAtHjRitDCFAghgSabuoRoED0uNHKEAIUiCGBppt6BCgQPW60MoQABWJIoOmmHgEKRI8brQwhQIEYEmi6qUeAAtHjRitDCFAghgSabuoRoED0uNHKEAIUiCGBppt6BCgQPW60MoQABWJIoOmmHgEKRI8brQwhQIEYEmi6qUeAAtHjRitDCFAghgSabuoRoED0uNHKEAIUiCGBppt6BCgQPW60MoQABWJIoOmmHgEKRI8brQwhQIEYEmi6qUeAAtHjRitDCFAghgSabuoRoED0uNHKEAIUiCGBppt6BCgQPW60MoQABWJIoOmmHgEKRI8brQwhUCQF4uvtgcVjesP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+NdXzV2/dVZtt6dntCZtXBQmeuhoj3+mITs3qqke+2nNCtUWSlDkPBeR72SdJRZN9hFzSAsqPeT/HzFX7IPnu5i/3UKtqBSUIqTrR+04pgcgpVr3eH2L97FAENq/nmJ9swO2/89gPJewLgOxfvv/pOhrUqqIEe+fXRHU8/ec2r6jfm6R9tbeZhS/N9WdkrECstiUmcgR6dmzsaCEkuTfsPo4hs9Y5VlSrhbGOea172SifWD9VtSDWJfZrth/F8Plf5YqKvbJJWyZ2Igixsd9bx7/yu4Vs1Lu391dJb11Hzl5Gh2F/U7eyqs8fFQSP4u6O74/GXUH7sMhcx7zSxp3/x0x1JC1zjzl4Vi0AOf2z3j/87Q4YF9I52x5GDi7kcGDhur2O8XP+3qSfjoXPskgKxFnMfjUq460ODdVKvHrbEadbBflfNCTZZaXWsS9ovoHN6qpK41m8GEQcOU+g5DRpfP8u8PH2RNylm2ovo3NZ+xt7CyVjS2WRtlMqyZLoAzpDP7c2FMhzG7qnO3H5sXTy4G6qkkp1qdJt0tN9wXM6GgXynAbuaU/b2qDLj4Ib955ULSYvgAJhFpBAPgQoEKYHCVAgzAES0CPACqLHjVaGEKBADAk03dQjQIHocaOVIQQoEEMCTTf1CFAgetxoZQgBCsSQQNNNPQIUiB43WhlCgAIxJNB0U48ABaLHjVaGEKBADAk03dQjQIHocaOVIQQoEEMCTTf1CFAgetxoZQgBCsSQQNNNPQIUiB43WhlCgAIxJNB0U48ABaLHjVaGEKBADAk03dQjQIHocaOVIQQoEEMCTTf1CFAgetxoZQgBCsSQQNNNPQIUiB43WhlCgAIxJNB0U48ABaLHjVaGEKBADAk03dQjQIHocaOVIQQoEEMCTTf1CFAgetxoZQgBCsSQQNNNPQIUiB43WhlCgAIxJNB0U48ABaLHjVaGEKBADAk03dQjQIHocaOVIQQoEEMCTTf1CFAgetxoZQgBCsSQQNNNPQIUiB43WhlC4L8WolIQDDthEAAAAABJRU5ErkJggg=="
    
    
    • 颜色color
    Random.color()
    // => "#3538B2"
    
    Random.hex()
    // => "#3538B2"
    
    Random.rgb()
    // => "rgb(242, 198, 121)"
    
    Random.rgba()
    // => "rgba(242, 198, 121, 0.13)"
    
    Random.hsl()
    // => "hsl(345, 82, 71)"
    
    • 文本 Text
      1、 一段文本paragraph
    Random.paragraph()
    // => "Yohbjjz psxwibxd jijiccj kvemj eidnus disnrst rcconm bcjrof tpzhdo ncxc yjws jnmdmty. ."
        
    Random.paragraph(2)
    // => "Dlpec hnwvovvnq slfehkf zimy qpxqgy vwrbi mok wozddpol umkek nffjcmk gnqhhvm ztqkvjm kvukg dqubvqn xqbmoda. "
        
    Random.paragraph(1, 3)
    // => "Qdgfqm puhxle twi lbeqjqfi bcxeeecu pqeqr srsx tjlnew oqtqx zhxhkvq pnjns eblxhzzta hifj csvndh ylechtyu."
    

    2、一段中文文本cparagraph

    Random.cparagraph()
    // => "给日数时化周作少情者美制论。到先争劳今已美变江以好较正新深。族国般建难出就金感基酸转。任部四那响成族利标铁导术一或已于。省元切世权往着路积会其区素白思断。加把他位间存定国工取除许热规先法方。"
        
    Random.cparagraph(2)
    // => "去话起时为无子议气根复即传月广。题林里油步不约认山形两标命导社干。"
        
    Random.cparagraph(1, 3)
    // => "候无部社心性有构员其深例矿取民为。须被亲需报每完认支这明复几下在铁需连。省备可离展五斗器就石正队除解动。"
    

    3、一个句子(默认18个单词)sentence

    Random.sentence()
    // => "Jovasojt qopupwh plciewh dryir zsqsvlkga yeam."
    Random.sentence(5)
    // => "Fwlymyyw htccsrgdk rgemfpyt cffydvvpc ycgvno."
    Random.sentence(3, 5)
    // => "Mgl qhrprwkhb etvwfbixm jbqmg."
    

    4、一段中文文本csentence

    Random.csentence()
    // => "第任人九同段形位第律认得。"
        
    Random.csentence(2)
    // => "维总。"
        
    Random.csentence(1, 3)
    // => "厂存。"
    

    5、一个单词word

    Random.word()
    // => "fxpocl"
    Random.word(5)
    // => "xfqjb"
    Random.word(3, 5)
    // => "kemh"
    

    6、一个汉字cword

    Random.cword()
    // => "干"
    Random.cword('零一二三四五六七八九十')
    // => "六"
    Random.cword(3)
    // => "别金提"
    Random.cword('零一二三四五六七八九十', 3)
    // => ""七七七""
    Random.cword(5, 7)
    // => "设过证全争听"
    Random.cword('零一二三四五六七八九十', 5, 7)
    // => "九七七零四"
    

    7、一句标题title

    Random.title()
    // => "Rduqzr Muwlmmlg Siekwvo Ktn Nkl Orn"
    Random.title(5)
    // => "Ahknzf Btpehy Xmpc Gonehbnsm Mecfec"
    Random.title(3, 5)
    // => "Hvjexiondr Pyickubll Owlorjvzys Xfnfwbfk"
    

    8、中文标题ctitle

    Random.ctitle()
    // => "证构动必作"
    Random.ctitle(5)
    // => "应青次影育"
    Random.ctitle(3, 5)
    // => "出料阶相"
    
    • 名字
    // 英文名
    Random.first()
    // => "Nancy"
    
    //英文姓
    Random.last()
    // => "Martinez"
    
    // 英文姓名
    Random.name()
    // => "Larry Wilson"
    Random.name(true)   // 是否生成中间名
    // => "Helen Carol Martinez"
    
    // 中文名
    Random.cfirst()
    // => "曹"
    
    // 中文姓
    Random.clast()
    // => "艳"
    
    // 中文姓名
    Random.cname()
    // => "袁军"
    
    • 链接地址:url
    Random.url()
    // => "mid://axmg.bg/bhyq"
    Random.url('http')
    // => "http://splap.yu/qxzkyoubp"
    Random.url('http', 'nuysoft.com')
    // => "http://nuysoft.com/ewacecjhe"
    
    • URL 协议protocol
    Random.protocol()
    // => "ftp"
    
    • 域名domain
    Random.domain()
    // => "kozfnb.org"
    
    • 顶级域名tld
    Random.tld()
    // => "net"
    
    • 邮件地址email
    Random.email()
    // => "x.davis@jackson.edu"
    Random.email('nuysoft.com')
    // => "h.pqpneix@nuysoft.com"
    
    • IP 地址ip
    Random.ip()
    // => "34.206.109.169"
    
    • 地址
    // 大区
    Random.region()
    // => "华北"
    
    Random.province()
    // => "黑龙江省"
    
    Random.city()
    // => "唐山市"
    Random.city(true)   // true:指定所属的省
    // => "福建省 漳州市"   
    
    Random.county()
    // => "上杭县"
    Random.county(true)
    // => "甘肃省 白银市 会宁县"
    
    // 于正编码
    Random.zip()
    // => "908812"
    
    • 把字符串的第一个字母转换为大写capitalize
    Random.capitalize('hello')
    // => "Hello"
    
    • 把字符串转换为大写upper
    Random.upper('hello')
    // => "HELLO"
    
    • 把字符串转换为小写lower
    Random.lower('HELLO')
    // => "hello"
    
    • 从数组中随机选取一个元素,并返回pick
    Random.pick(['a', 'e', 'i', 'o', 'u'])
    // => "o"
    
    • 打乱数组中元素的顺序,并返回shuffle
    Random.shuffle(['a', 'e', 'i', 'o', 'u'])
    // => ["o", "u", "e", "i", "a"]
    
    • 随机生成一个 GUIDguid
    Random.guid()
    // => "662C63B4-FD43-66F4-3328-C54E3FF0D56E"
    
    • 随机生成一个 18 位身份证id
    Random.id()
    // => "420000200710091854"
    
    • 生成一个全局的自增整数increment
    Random.increment()
    // => 1
    Random.increment(100)
    // => 101
    Random.increment(1000)
    // => 1101
    

    相关文章

      网友评论

          本文标题:Mockjs

          本文链接:https://www.haomeiwen.com/subject/rwtfmktx.html