human-readable-id-gen
Library for generating human-readable id strings.
Basic Usage
const generateId = ; console;// ex. Regina's required request console;// ex. Garrett's graceful giraffe
Custom Generators
The generateId
function randomly pulls words from a default collection of nouns, adjectives, and names. To pull from a different set of words, you must use the IdGenerator
class and its #generate
method.
Using words in memory
Use the IdGenerator
constructor with instances of WordCollection
.
const IdGenerator WordCollection = ; let nouns = 'chair' 'tie' 'lamp';let adjectives = 'good' 'bad' 'ugly';let names = 'Tom' 'Dick' 'Harry'; let idGenerator = nouns adjectives names; console;// ex. Tom's ugly tie
Note that alliteration is not guaranteed if, for any word in the nouns collection, there isn't a word beginning with the same letter in both the adjectives and names collections, as above (adjectives
has no words beginning with 't').
Loading from files
Use IdGenerator.load
to load words from text files. These files should contain words separated by newlines.
const IdGenerator = ; let idGenerator = IdGenerator; console;// ex. Leanna's logical laundry
Individual WordCollection
instances can also be loaded from files:
const IdGenerator WordCollection = ; let nouns = WordCollection;let adjectives = 'good' 'bad' 'ugly';let names = 'Tom' 'Dick' 'Harry'; let idGenerator = nouns adjectives names; console;// ex. Harry's bad hair