short-id
A Sumor Cloud Tool.
More Documentation
This is a short-id library for Node.js and the browser.
You can easily use it to generate a short id from number.
Installation
npm i @sumor/short-id --save
Prerequisites
Node.JS version
Require Node.JS version 18.x or above
require Node.JS ES module
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
Usage
Standard Usage
import { encode, decode } from '@sumor/short-id'
const shortId1 = encode(10)
console.log(shortId1)
const shortId2 = encode(72)
console.log(shortId2)
const number1 = decode('a')
console.log(number1)
const number2 = decode('1a')
console.log(number2)
Custom Usage
import { encode, decode } from '@sumor/short-id'
const rule = '0123456789abcdefghigklmnopqrstuvwxyz'
const shortId1 = encode(10, rule)
console.log(shortId1)
const shortId2 = encode(46, rule)
console.log(shortId2)
const number1 = decode('a', rule)
console.log(number1)
const number2 = decode('1a', rule)
console.log(number2)