JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q43958F
  • License ISC

A utility to generate unique identifiers with cryptographic randomness and time-based elements.

Package Exports

  • als-uid
  • als-uid/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (als-uid) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Als-uid

ALS-UID is a JavaScript utility for generating unique identifiers (UIDs). It combines cryptographic randomness with time-based elements to ensure a high degree of uniqueness and reduce the likelihood of collisions.

import

In Node.js

const GenerateUid = require('als-uid')

In browser:

<script src="node_modules/als-uid/index.js"></script>

Usage

// Generate a UID
const uid = GenerateUid.uid();
console.log(uid); // Outputs a unique identifier 14 symbols

// Change how often the prefix is updated
GenerateUid.changePrefixEvery = 200; // 100 by default
GenerateUid.prefix // curent generated prefix

Performace

Tests showed that prefix generation (on start and every 100 generations by default) takes about 1ms. Every generation without prefix (each of 99 generations by default), takes about 0.1ms - 0.2ms.

Generation method

als-uid using unique method for uid generation. Each uid has 3 parts:

  1. prefix - secure cryptographic random string from 2 bytes
    1. changing on start or every 100 times by default
  2. Random string - random 3 length string (generated with Math.random)
  3. modified date digits - last 7 digits from Date.now() - random numbers from performance.now()