Generate human-readable, user-friendly IDs.
npm install human-readable-idGenerate human-readable, memorable IDs with customizable word patterns, separators, and optional numbers! Perfect for creating unique identifiers for your applications. ๐
---
- ๐ ๏ธ 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!
---
``bash`
npm install human-readable-id
`bash`
yarn add human-readable-id
`bash`
pnpm add human-readable-id
---
`javascript`
const HumanReadableID = require('human-readable-id');
Customize the generator with options:
`javascript`
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
});
`javascript`
const singleID = idGenerator.generate();
console.log(singleID); // Example: "happy-cat-123"
Generate multiple IDs in one call:
`javascript`
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"
// ]
Control how many words are in the ID:
`javascript`
const customLengthID = idGenerator.generate(3); // Three words
console.log(customLengthID); // Example: "blue-dog-run-234"
---
#### ๐ Change Word Types Dynamically
You can generate IDs with different word types by modifying the wordType property dynamically:
`javascript`
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:
`javascript`
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:
`javascript`
idGenerator.separator = "_"; // Use an underscore as separator
const customSeparatorID = idGenerator.generate(2);
console.log(customSeparatorID); // Example: "bright_sky"
---
Run the following commands to test the library in your project:
javascript
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));
``---
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
- Name: Milan Rathod
- GitHub: milan-rath0d
- Email: milanrathod9080@gmail.com
Feel free to reach out if you have any questions or suggestions!