als-uid
v1.1.0
Published
A utility to generate unique identifiers with cryptographic randomness and time-based elements.
Downloads
33
Maintainers
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:
- prefix - secure cryptographic random string from 2 bytes
- changing on start or every 100 times by default
- Random string - random 3 length string (generated with Math.random)
- modified date digits - last 7 digits from Date.now() - random numbers from performance.now()