1.0.2 โข Published 7 months ago
human-readable-id v1.0.2
๐ Human Readable ID Generator
Generate human-readable, memorable IDs with customizable word patterns, separators, and optional numbers! Perfect for creating unique identifiers for your applications. ๐
โจ Features
- ๐ ๏ธ Customizable Word Patterns: Choose from adjectives, nouns, verbs, colors, or random words.
- ๐ Custom Separators: Use any character to separate words and numbers.
- ๐ข Optional Numbers: Add a random number for extra uniqueness.
- ๐ฆ Bulk ID Generation: Generate multiple IDs at once!
๐ฅ Installation
NPM
npm install human-readable-id
Yarn
yarn add human-readable-id
pnpm
pnpm add human-readable-id
๐ Usage
๐ Import the Library
const HumanReadableID = require('human-readable-id');
โ๏ธ Create an Instance
Customize the generator with options:
const idGenerator = new HumanReadableID({
wordType: "adjective-noun", // Word pattern (e.g., adjective + noun)
separator: "-", // Separator between words and numbers
includeNumbers: true // Whether to include random numbers
});
๐ Generate a Single ID
const singleID = idGenerator.generate();
console.log(singleID); // Example: "happy-cat-123"
๐ Generate Bulk IDs
Generate multiple IDs in one call:
const bulkIDs = idGenerator.generateBulk(5, 3);
console.log(bulkIDs);
// Example Output:
// [
// "bright-sun-red-456",
// "fast-fox-sky-789",
// "calm-rain-bird-123",
// "funny-moon-star-654",
// "sharp-tree-leaf-987"
// ]
โ๏ธ Customize ID Length
Control how many words are in the ID:
const customLengthID = idGenerator.generate(3); // Three words
console.log(customLengthID); // Example: "blue-dog-run-234"
๐ฏ Advanced Usage
๐ Change Word Types Dynamically
You can generate IDs with different word types by modifying the wordType
property dynamically:
idGenerator.wordType = "verb-color"; // Update to verb and color pattern
const dynamicID = idGenerator.generate(2);
console.log(dynamicID); // Example: "run-blue-789"
๐ Exclude Numbers
If you prefer IDs without numbers, set includeNumbers
to false
:
idGenerator.includeNumbers = false;
const noNumberID = idGenerator.generate(2);
console.log(noNumberID); // Example: "happy-cat"
๐ Use Custom Separators
You can change the separator at any time:
idGenerator.separator = "_"; // Use an underscore as separator
const customSeparatorID = idGenerator.generate(2);
console.log(customSeparatorID); // Example: "bright_sky"
๐งช Testing
Run the following commands to test the library in your project:
Node.js Script
const HumanReadableID = require('human-readable-id');
const idGenerator = new HumanReadableID({
wordType: "color-noun",
separator: "-",
includeNumbers: true
});
console.log("Test ID:", idGenerator.generate());
console.log("Bulk Test IDs:", idGenerator.generateBulk(3));
๐ค Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
๐ค Author
- Name: Milan Rathod
- GitHub: milan-rath0d
- Email: milanrathod9080@gmail.com
Feel free to reach out if you have any questions or suggestions!