prefixed-id
v0.0.1
Published
Generates random ids with a prefix (like Stripe)
Downloads
8
Readme
prefixed-id
Generates random ids with a prefix (like Stripe)
Based on id-generator by Auth0.
Installing
npm install prefixed-id
Using
Simple case:
var PrefixedId = require('prefixed-id');
var generator = new PrefixedId();
var id = generator.new('cus');
console.log(id); // cus_lO1DEQWBbQAACfHO
Predefined set of allowed prefixes (to avoid mistakes):
var PrefixedId = require('prefixed-id');
var generator = new PrefixedId(['cus', 'con']);
var id = generator.new('cus');
console.log(id); // cus_lO1DEQWBbQAACfHO
generator.new('cli'); // throws
stackabuse.com · Twitter @ScottWRobinson · GitHub @ScottWRobinson