mainid
v1.0.8
Published
Id generator with crypto
Readme
IdGenerator
IdGenerator
Features
- Unlimited id size;
- Configurable random pool size;
- Replacable dictionary;
- Support replacable Crypto (requires Buffer);
- Fallback to Math.random (if Crypto & Buffer not used).
Usage
Prepare
import { IdGenerator } 'mainid';Create id generator
Unsafe
Math.random for random
const idGenerator = new IdGenerator();Safe
- Crypto - usage:
crypto.getRandomValues(buffer); - Buffer is required - usage:
buffer = buffer.alloc(randomPoolSize).
const idGenerator = new IdGenerator({
crypto: /** @type {Crypto} */ (crypto)
});Dictionary and random pool size
Optinal.
const idGenerator = new IdGenerator({
dictionary: 'abc',
randomPoolSize: 3
});Commands
Create
const id = idGenerator.create();