@marianmeres/random-human-readable
v1.8.3
Published
[](https://www.npmjs.com/package/@marianmeres/random-human-readable) [](https://jsr.io/@marianmeres/random-human-readabl
Readme
@marianmeres/random-human-readable
Simple utility function to generate random but human-readable strings. The internal English words dictionary has ~1500 nouns, ~250 adjectives and ~130 colors, which makes — with default options — over 48 billion unique choices.
Should you worry about collisions, you can grow the count of possible choices by orders
of magnitude by simply increasing the adjCount/colorsCount/nounsCount/syllablesCount
options and/or setting the randomizeCase flag.
Playground: https://rhr.meres.sk/
Installation
# npm
npm install @marianmeres/random-human-readable
# jsr
deno add @marianmeres/random-human-readableMain usage
import { getRandomHumanReadable } from '@marianmeres/random-human-readable';
// All options are optional, and the generation order is always:
// 1. adjectives, 2. colors, 3. nouns, 4. syllables, (5. digits, 6. special chars)
getRandomHumanReadable({
// number of adjectives to generate
adjCount: 1,
// number of colors to generate
colorsCount: 1,
// number of nouns to generate
nounsCount: 2,
// number of (nonsense) syllables to generate
syllablesCount: 0,
// if true, will RanDOmiZe case on generated output
randomizeCase: false,
// string to join the generated words with
// (use explicit `false` to disable joining and return as array of words)
joinWith: '-',
// Since many password validators require digits and/or special chars (and this tool
// can be used as a password generator), these are also supported, although they
// are not really human-readable (in this context)
digitsCount: 0,
specialCharsCount: 0,
});Example results (with default options):
fit-transparent-mouse-phrase
massive-navy-wood-joint
unkempt-cadetblue-hand-branch
incalculable-brown-quality-tank
chubby-aquamarine-year-flower
wooden-springgreen-profit-personal
prickly-darkblue-incident-schedule
refined-blue-reason-policy
wide-white-contract-transition
whispering-burlywood-ring-pizzaOr, if you're feeling options-adventurous:
getRandomHumanReadable({
adjCount: 5,
syllablesCount: 4,
randomizeCase: true,
// other options will be inherited from the defaults if not provided
});You may get something like this:
shRiLLing-helPLESs-Tiny-jollY-ScrawNy-KHAki-PRiEsT-ZIFuvACyOther exposed internals
// internal db
data = { adjs, colors, nouns };
// all below return string
getRandomAdj();
getRandomColor();
getRandomNoun();
getRandomVowel();
getRandomConsonant();
getRandomSyllable();
randomizeCase(str);
// Somewhat off-topic and quite opinionated "lorem ipsum"-like helpers
getRandomSentence(options: Partial<Options>[] = [], shorterSentenceProbability = 0.33);
getRandomParagraph(minSentences = 1, maxSentences = 5, shorterSentenceProbability = 0.33);API
See API.md for complete API documentation.
