1.0.2 โ€ข Published 7 months ago

human-readable-id v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

๐ŸŽ‰ 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!

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago