yuid
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Yield UID (yuid)

What is it?

yuid produces unique ids using javascript generator methods.

Goals

  1. Extremely small, less than 600 bytes (ES6, non-minified)
  2. Non-cryptographic but random enough to not have collisions when used async
  3. Has a monotonic component

A generated Id looks like this: "1-khjm3urk-2aru7hqvsdv"

It is composed of: ${serial}-${time}-${random}

Installation

npm install --save yuid

Usage

import yuid from 'yuid';

// using generators
const generator = yuid.generator();  // initialize the generator
const uid = generator.next().value; // pull a uid

or, alternatively, you can use a static, pre-instantiated generator provided by the class.

import yuid from 'yuid';
const uid = yuid.getId();

Instantiating your own generates a new monotonic sequence. Using getId shares a global sequence.

Readme

Keywords

none

Package Sidebar

Install

npm i yuid

Weekly Downloads

2

Version

0.2.2

License

MIT

Unpacked Size

9.23 kB

Total Files

12

Last publish

Collaborators

  • hedzer