1.如何安装nodecakeid
1.How to install nodecakeid
npm install nodecakeid
// 或/or
yarn add nodecakeid
2.如何使用nodecakeid
2.How to use nodecakeid
charset配置项写入任意大小写字母和数字即可
Charset configuration item can be written with any upper and lower case letters and numbers
const nodecakeid = require('nodecakeid')
const id = nodecakeid.definedCakeid({ byte: 10, charset: 'aA0' })
console.log(id) // 5oL2l1FIDM
const id_2 = nodecakeid.definedCakeid({ byte: 10, charset: 'a0' })
console.log(id_2) // 418r77tp3i
const id_3 = nodecakeid.definedCakeid({ byte: 10, charset: '0' })
console.log(id_3) // 7718071110
const id_4 = nodecakeid.definedCakeid({ byte: 10, charset: '9a' })
console.log(id_4)// y2f4pj448t
3.配置项
3.options
配置/options | 类型/type | 备注/remarks |
---|---|---|
byte | number | 生成了几个字节/How many bytes are generated |
charset | string | 字符集/character set |
4.内置方法
4.Built in method
const nodecakeid = require('nodecakeid')
// 直接生成由大小写字母和数字组成的字符串
// Directly generate a string composed of upper and lower case letters and numbers
// nodecakeid.cakeid( number )
const id_1 = nodecakeid.cakeid(10)
console.log(id_1) // tkrIcBrBiL
// 根据配置项生成的随机字符串
// Random string generated from configuration item
// nodecakeid.definedCakeid( { options } )
const id_2 = nodecakeid.definedCakeid( { byte: 6, charset: 'A0'} )
console.log(id_2) // B3DDT4