Skip to content

gCorePlus/shortid

Repository files navigation

npm version Codecov Coverage ISC license

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

Rennan Stefan Boni

License

Distributed under the ISC License. See LICENSE for more information.

Acknowledgements

Copyright © 2020 gCorePlus Inc.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published