0.1.7 • Published 2 years ago
shrt-id v0.1.7
Fastest way to create Short Id
How we create short id
Under writing
Installation
Open your terminal and run:
npm install shrt-id
Then, at the top of each of your Javascript script, you should be able to import the module:
const { ShortId, shrtId } = require("shrt-id");
Use shrt_id
Simple use
const id = shrtId(); // default length is 9
console.log(id);
// ev60bb7QX
Custom length
const id = shrtId(10);
console.log(id);
// wiwdhx8V7x
Get Id and shard at same time
const [id, shard] = new ShortId().idWithShard(10);
console.log(id, shard);
// euiOXu9QYt 55
Decode id for datetime and shard
const myShortId = new ShortId(10, 4); // length = 10 and has 4 shards
const [id, shard] = myShortId.idWithShard();
console.log(id, shard);
// eujbNU000A 2
console.log(myShortId.decode(id));
// {
// id: 'eujbNU000A',
// shardSeq: 2,
// dt: 2022-08-22T12:22:10.800Z,
// randomSeq: 12596194,
// randomString: '000A'
// }