mainid

1.0.8 • Public • Published

IdGenerator

IdGenerator

  1. Features;
  2. Usage:
    1. Prepare:
      1. Create id generator:
        1. Unsafe;
        2. Safe;
        3. Dictionary and random pool size.
    2. Commands:
      1. Create.

Features

  1. Unlimited id size;
  2. Configurable random pool size;
  3. Replacable dictionary;
  4. Support replacable Crypto (requires Buffer);
  5. 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

  1. Create;

Create

const id = idGenerator.create();

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i mainid

    Weekly Downloads

    3

    Version

    1.0.8

    License

    MIT

    Unpacked Size

    22.4 kB

    Total Files

    9

    Last publish

    Collaborators

    • ilushling