https://github.com/marianmeres/random-human-readable
Human readable random string generator. Useful for creating passwords, tokens or just plain text placeholders.
https://github.com/marianmeres/random-human-readable
password-generator string-generator token-generator
Last synced: 10 months ago
JSON representation
Human readable random string generator. Useful for creating passwords, tokens or just plain text placeholders.
- Host: GitHub
- URL: https://github.com/marianmeres/random-human-readable
- Owner: marianmeres
- License: mit
- Created: 2023-02-15T16:15:57.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T22:04:29.000Z (about 2 years ago)
- Last Synced: 2025-03-12T19:47:28.584Z (11 months ago)
- Topics: password-generator, string-generator, token-generator
- Language: TypeScript
- Homepage: https://rhr.meres.sk
- Size: 69.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @marianmeres/random-human-readable
Simple utility function to help generating random but human readable
strings. The internal english words dictionary has about ~1500 nouns, ~250 adjectives
and ~130 colors, which makes - **with default options** - over 48 billion unique choices.
Should you worry about collision, 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
```shell
$ npm i @marianmeres/random-human-readable
```
## Main usage
```javascript
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: number,
specialCharsCount: number,
});
```
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-pizza
```
or, if you're feeling options-adventurous:
```javascript
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-ZIFuvACy
```
## Other exposed internals
```typescript
// 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[] = [], shorterSentenceProbability = 0.33);
getRandomParagraph(minSentences = 1, maxSentences = 5, shorterSentenceProbability = 0.33);
```