@windfish-studio/deterministic-uniqid

1.0.2 • Public • Published

deterministic-uniqid

This package serves a single purpose; to quickly generate alphanumeric unique IDs in a deterministic way. Meaning, this library can be passed a seed value, and given the same seed, it should generate the same ID strings in the same order.

Usage

var gen = new DeterministicUniqId();
gen.setSeed('some_unique_seed');
gen.generateId();
// => "12Ab88zY"
gen.generateId();
// => "81v2Y79j"
gen.setSeed('some_unique_seed');
gen.generateId();
// => "12Ab88zY"

API

constructor(seed: string, keyLength: number)

Takes two parameters:

  • seed: instantiate the ID generator with this seed value
  • keyLength: the length of the ID string output by generateId()
    new DeterministicUniqId('DINOSAURS', 16);

.setKeyLength(length: number)

Sets the desired ID length. This will be the length of the string returned by .generateId()

.setSeed(seed: string)

Sets the seed for deterministic random number generation. This ensures that generateId will always generate the same pseudo-random ID strings, in the same order.

.generateId(void)

Generates a pseudo-random ID. Given the same seed value, either passed to the constructor or set via .setSeed(seed), this will return a series of the same unique IDs, in the same order.

Readme

Keywords

none

Package Sidebar

Install

npm i @windfish-studio/deterministic-uniqid

Weekly Downloads

1

Version

1.0.2

License

none

Unpacked Size

3.91 kB

Total Files

4

Last publish

Collaborators

  • lubie_piwo
  • sikanrong