微信小程序開發(fā)實(shí)戰(zhàn)——使用UUID、Base64、Chance等
UUID
node-uuid模塊,可以快速地生成符合 RFC4122 規(guī)范 version 1 或者 version 4 的 UUID。
- var uuid = require('../../libs/node-uuid/uuid.modified.js');
- // v1 是基于時(shí)間戳生成uuid
- console.log(uuid.v1());
- // v4 是隨機(jī)生成uuid
- console.log(uuid.v4());
Base64
js-base64 是 Base64 的 JavaScript 實(shí)現(xiàn)。
- var Base64 = require('../../libs/js-base64/base64.modified.js');
- console.log(Base64.encode('Wechat'));
- console.log(Base64.encode('微信'));
- console.log(Base64.decode('V2VjaGF0'));
- console.log(Base64.decode('5b6u5L+h'));
Chance
Chance 是一個(gè)基于 JavaScript 的隨機(jī)數(shù)工具類??梢陨呻S機(jī)數(shù)字,名稱,地址,域名,郵箱,時(shí)間等等,幾乎網(wǎng)站中使用的任何形式的內(nèi)容都能夠生成。這個(gè)隨機(jī)數(shù)工具可以幫助減少單調(diào)的測(cè)試數(shù)據(jù)編寫工作,特別是編寫自動(dòng)化測(cè)試的時(shí)候。
- var Chance = require('../../libs/chance/chance.modified.js');
- var chance = new Chance();
- console.log(chance.string());
- console.log(chance.integer());
- console.log(chance.bool());
- console.log(chance.phone());
- console.log(chance.zip());
- console.log(chance.guid());
其他