@gcoreplus/shortid
v1.0.1
Published
➔ @gcoreplus/shortid creates ✓random or ✓sequential with seed short url-friendly unique ids
Downloads
21
Maintainers
Readme
ShortIt! with ShortId
About
@gcoreplus/shortid
creates random or sequential with seed short url-friendly unique ids.
Perfect for url shorteners, MongoDB and Redis ids, and any other id users might see.
Inspired by the shortid
👨🏻💻Installation
Install the main lib
npm install --save @gcoreplus/shortid
Usage
import shortid from '@gcoreplus/shortid';
shortid.setCharacters('ABC');
let seed;
do {
seed = shortid.generate(seed);
console.log(seed); // A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC, AAA
} while (seed !== 'AAA')
Example
Example generating sequential ID from 0 to AAA
~/projects/shortid> node -r ts-node/register examples/example-01.ts
0
1
2
....
AAA
Example generating sequential ID from A to AAA using custom alphabet
~/projects/shortid> node -r ts-node/register examples/example-02.ts
A
B
C
AA
AB
AC
BA
BB
BC
CA
CB
CC
AAA
Backers
License
Distributed under the ISC License. See LICENSE
for more information.
Acknowledgements
Copyright © 2020 gCorePlus Inc.