Customizable and secure ID generator with async and prefix/suffix support for JS/TS environment.
npm install unique-forge
Use UniqueForge
for standard unique ID generation:
const { UniqueForge } = require("unique-forge");
const forge = new UniqueForge();
console.log(forge.generate()); // Outputs a unique ID
For asynchronous workflows, use AsyncUniqueForge
:
const { AsyncUniqueForge } = require("unique-forge");
const asyncForge = new AsyncUniqueForge();
asyncForge.generate().then((id) => console.log(id));
For cryptographically secure IDs, use SecureUniqueForge
:
const { SecureUniqueForge } = require("unique-forge");
const secureForge = new SecureUniqueForge();
console.log(secureForge.generate()); // Outputs a secure unique ID
Use CustomUniqueForge
for IDs with custom prefixes or suffixes:
const { CustomUniqueForge } = require("unique-forge");
const customForge = new CustomUniqueForge({ prefix: "user_", suffix: "_2023" });
console.log(customForge.generate()); // Outputs: user_<unique-id>_2023
- Customizable Alphabet: Define your own characters for ID generation.
- Adjustable Length: Set the size of the generated IDs.
- Synchronous & Asynchronous: Flexible workflows for various use cases.
- Secure Random IDs: Leverage cryptographic randomness when needed.
- Prefix/Suffix Support: Easily create formatted IDs.
This library is MIT Licensed. Contributions are welcome!