DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • node

    • NODE
    • parseArgs
    • compose
    • date-format
    • dayjs
    • encrypt
    • env-cmd
    • glob
    • Koa 洋葱模型
    • lodash
    • logger
    • log4js
    • mongod
    • nanoid
    • node-red
    • node-stream
    • node:test
    • nodemailer
    • nodemon
    • nodered
    • parse-curl
    • pm2
    • toml
    • ws
    • yargs
    • zx

nanoid

npm i nanoid nanoid-dictionary

import { nanoid } from 'nanoid'
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
// top level await 
await nanoid()
// 10 bits
nanoid(10) //=> "IRFa-VaY2b"

// performance 
import { nanoid } from 'nanoid/non-secure'
const id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqLJ"

// 自定义字符
import { customAlphabet } from 'nanoid'
const nanoid = customAlphabet('1234567890abcdef', 10)
model.id = nanoid() //=> "4f90d13a42"


// nanoid dictionary
import { customAlphabet } from 'nanoid';
import { lowercase } from 'nanoid-dictionary';

const lowercaseRandomString = customAlphabet(lowercase, 10);

Refer

  • npm nanoid
  • nanoid doc
  • nanoid dictionary
Last Updated:
Contributors: rosendo
Prev
mongod
Next
node-red