Id generator with crypto
npm install mainid1) Features;
2) Usage:
1) Prepare:
1) Create id generator:
1) Unsafe;
2) Safe;
3) Dictionary and random pool size.
2) Commands:
1) Create.
js
import { IdGenerator } 'mainid';
`#### Create id generator
##### Unsafe
Math.random for random
`js
const idGenerator = new IdGenerator();
`##### Safe
- Crypto - usage:
crypto.getRandomValues(buffer);
- Buffer is required - usage: buffer = buffer.alloc(randomPoolSize).`js
const idGenerator = new IdGenerator({
crypto: /* @type {Crypto} / (crypto)
});
`##### Dictionary and random pool size
Optinal.
`js
const idGenerator = new IdGenerator({
dictionary: 'abc',
randomPoolSize: 3
});
`$3
1) Create;#### Create
`js
const id = idGenerator.create();
``