auth0-id-generator
auth0-id-generator
npm i auth0-id-generator
auth0-id-generator

auth0-id-generator

Generates random ids with a prefix (a la Stripe)

by auth0

0.2.0 (see all)License:MITTypeScript:Not Found
npm i auth0-id-generator
Readme

id-generator

Generates random ids with a prefix (a la Stripe)

Installing

npm i auth0-id-generator

Using

Simple case:

var IdGenerator = require('auth0-id-generator');

var generator = new IdGenerator();
var id = generator.new('cus');

console.log(id); // cus_lO1DEQWBbQAACfHO

Predefined set of allowed prefixes (to avoid mistakes):

var IdGenerator = require('auth0-id-generator');

var generator = new IdGenerator(['cus', 'con']);
var id = generator.new('cus');

console.log(id); // cus_lO1DEQWBbQAACfHO

generator.new('cli'); // throws

To get a uid (id with a given length and without prefix):

var IdGenerator = require('auth0-id-generator');

var generator = new IdGenerator(['cus', 'con']);
var id = generator.newUid(10);

console.log(id); // lO1DEQWBbQ

New API

Updated api allows more customizations. Uses a new method .get():

var generator = new IdGenerator({len: 5, alphabet: 'abc123', prefix: 'foo', separator: ':'});

generator.get();  // -> foo:2a2b1

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

Downloads/wk

9.9K

GitHub Stars

60

LAST COMMIT

2yrs ago

MAINTAINERS

5

CONTRIBUTORS

8

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.2.0
latest
2yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate