IdGenerator
- Unlimited id size;
- Configurable random pool size;
- Replacable dictionary;
- Support replacable Crypto (requires Buffer);
- Fallback to Math.random (if Crypto & Buffer not used).
import { IdGenerator } 'mainid';
Math.random for random
const idGenerator = new IdGenerator();
- Crypto - usage:
crypto.getRandomValues(buffer)
; - Buffer is required - usage:
buffer = buffer.alloc(randomPoolSize)
.
const idGenerator = new IdGenerator({
crypto: /** @type {Crypto} */ (crypto)
});
Optinal.
const idGenerator = new IdGenerator({
dictionary: 'abc',
randomPoolSize: 3
});
const id = idGenerator.create();