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