@gcoreplus/shortid
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i @gcoreplus/shortid

Weekly Downloads

3

Version

1.0.1

License

ISC

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • rennanboni