idgenie
v1.1.1
Published
A magical and flexible ID generator with support for unique IDs, date/time, prefixes, suffixes, and more.
Maintainers
Keywords
Readme
idgenie
A magical and flexible ID generator with support for unique IDs, date/time, prefixes, suffixes, and more.
Installation
npm install idgenieyarn add idgeniepnpm add idgenieUsing IdGenie from a CDN
IdGenie is available on jsDelivr and unpkg, so you can use it directly in the browser without installing via npm. Just include the script, and idgenie will be available globally:
<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/npm/idgenie/dist/idgenie.umd.min.js"></script> or
<script src="https://unpkg.com/idgenie/dist/idgenie.umd.min.js"></script>
<!-- Or pin to a specific version -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/idgenie.umd.min.js"></script> or
<script src="https://unpkg.com/[email protected]/dist/idgenie.umd.min.js"></script>
<script>
const id = idgenie.uniqueId({ length: 20, prefix:'manikant' });
console.log(id);
</script>Usage After Installation
Importing
// ES Module
import { uniqueId } from "idgenie";
// CommonJS
const { uniqueId } = require("idgenie");Basic Example
// Generate Default unique id
const id = uniqueId();
console.log(id); // Outputs unique id string
// Generate Custom unique id using options parameters --->
const customId = uniqueId({length: 20, prefix:'mani', suffix:'kumar'});
// It will generate unique id of length 20 + prefix + suffix
const customId = uniqueId({mode:'uuid'});
// It will generate unique uuid
const customId = unqiueId({randomLength: true, alphabet:'manikant123', includeDate: true, casing:'upper', secure: true, separator:'#'});
// It will generate random length of custom unique id between 8-36 also it'll take my 'manikant123' alphabet to generate id and include date, separator('#') where need and
// generate id securely using crypto and give Unique id in Uppercase as passed casing 'upper'
console.log(customId); // Outputs custom id string
// You can use in the same way options as your needs else use without it for just idAPI
uniqueId(options)
Generates a unique ID with flexible options.
| Option | Type | Default | Description | | ----------------- | ------- | ------------ | ------------------------------------------ | | length | number | 8 | Length of generated ID | | randomLength | boolean | false | Randomize length between 8-36 if set true | | prefix | string | '' | Adds a prefix to the generated ID | | suffix | string | '' | Adds a suffix to the generated ID | | includeDate | boolean | false | Include localized date string | | includeTime | boolean | false | Include localized time string | | dateLocale | string | 'en-IN' | Locale used for date formatting | | timeLocale | string | 'en-IN' | Locale used for time formatting | | dateFormatOptions | object | { year: "numeric", month: "2-digit", day: "2-digit" } | Intl.DateTimeFormat options for date | | timeFormatOptions | object | { hour: "2-digit", minute: "2-digit", second: "2-digit" } | Intl.DateTimeFormat options for time | | alphabet | string | Alphanumeric [A-Za-z0-9] | Characters used for randomness | | casing | string | 'mixed' | Casing style: 'lower', 'upper', or 'mixed' | | separator | string | '' | Separator string between different parts. For Example '@' or '#' etc. | | secure | boolean | false | Use cryptographically secure randomness | | mode | string | 'random' | Mode of generation, 'random' or 'uuid' | | counter | boolean | false | Append a counter value | | timestamp | boolean | false | Append timestamp string |
License
MIT
