Skip to content

bennett000/ch1-uid

Folders and files

NameName
Last commit message
Last commit date
Sep 3, 2018
Sep 17, 2018
Sep 3, 2018
Sep 3, 2018
Sep 17, 2018
Sep 3, 2018
Sep 3, 2018
Sep 9, 2018
Sep 17, 2018
Sep 8, 2018
Sep 9, 2018

Repository files navigation

CH1 UID

CircleCI

This is not well maintained

Installation

yarn add @ch1/uid

Usage

import { createUid } from '@ch1/uid';

const uid = createUid();

const someId = uid();
const someOtherId = uid();
const someOtherIdStartingWithFoo = uid('Foo');

Ids have the following formats:

prefix-id-date-rollover-entropy

or

id-date-rollover-entropy

  • Where all numbers (id, date, rollover, and entropy) are in base 32.
  • Where id is internally generated at the createUid call
  • Where dates are timestamps in milliseconds
  • Where rollover is an internal numeric counter that increments to a maximum and then "rolls over"
  • Where entropy is random data added to the end

Customizing

There are options!

const uid = createUid(
  random: () => number, // random number generator, ideally returns `0 <= x < 1`
  date: () => number,   // timestamp in ms
  rolloverMax: number,  // internal rollover counter
  entropyMax: number,   // multiplier of `random()` for ends of uids
);

const someId = uid();

License

LGPL

About

Simple Universal ID Generator

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published