1.1.0 • Published 5 months ago

als-uid v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

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()