0.1.2 • Published 5 years ago

stripe-id-generator v0.1.2

Weekly downloads
255
License
MIT
Repository
github
Last release
5 years ago

stripe-id-generator

Build Status Coverage Status styled with prettier

Generates random ids with a prefix (a la Stripe)

Installing

npm i stripe-id-generator # or
yarn add stripe-id-generator

Using

Simple case:

const IdGenerator = require('stripe-id-generator');

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

console.log(id); // cus_lO1DEQWBbQAACfHO

Predefined set of allowed prefixes (to avoid mistakes):

const IdGenerator = require('stripe-id-generator');

const generator = new IdGenerator(['cus', 'con']);
const 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):

const IdGenerator = require('stripe-id-generator');

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

console.log(id); // lO1DEQWBbQ

Author

Fork from Auth0

License

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

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago