
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
human-readable-id-gen
Advanced tools
Library for generating human-readable id strings.
const { generateId } = require('human-readable-id-gen');
console.log(generateId());
// ex. Regina's required request
console.log(generateId());
// ex. Garrett's graceful giraffe
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.
Use the IdGenerator
constructor with instances of WordCollection
.
const { IdGenerator, WordCollection } = require('human-readable-id-gen');
let nouns = new WordCollection(['chair', 'tie', 'lamp']);
let adjectives = new WordCollection(['good', 'bad', 'ugly']);
let names = new WordCollection(['Tom', 'Dick', 'Harry']);
let idGenerator = new IdGenerator(nouns, adjectives, names);
console.log(idGenerator.generate());
// 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').
Use IdGenerator.load
to load words from text files. These files should contain words separated by newlines.
const { IdGenerator } = require('human-readable-id-gen');
let idGenerator = IdGenerator.load(
'path/to/nouns.txt',
'path/to/adjectives.txt',
'path/to/names.txt'
);
console.log(idGenerator.generate());
// ex. Leanna's logical laundry
Individual WordCollection
instances can also be loaded from files:
const { IdGenerator, WordCollection } = require('human-readable-id-gen');
let nouns = WordCollection.load('path/to/nouns.txt');
let adjectives = new WordCollection(['good', 'bad', 'ugly']);
let names = new WordCollection(['Tom', 'Dick', 'Harry']);
let idGenerator = new IdGenerator(nouns, adjectives, names);
console.log(idGenerator.generate());
// ex. Harry's bad hair
FAQs
Library for generating human-readable id strings
We found that human-readable-id-gen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.