Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mnemonic-id

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mnemonic-id

Library to generate easy to remember, and sometimes entertaining, human readable ids

  • 3.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33K
decreased by-48.31%
Maintainers
1
Weekly downloads
 
Created
Source

Mnemonic id

Coverage Status TypeScript-ready

Library to generate easy to remember, and sometimes entertaining, human readable ids.

createStoryId(); // -> awesome-chipmunk-banish-evil-rat

Partly inspired by Docker name generator and major mnemonic system.

Highlights

  • Dictionary of approximate 150 nouns (animals), 200 verbs, 500 adjectives.
  • Deterministic size, with max length of 10 for nouns, 8 for verbs and adjectives.
  • Customizable id generation.
  • TypeScript annotated API.
  • Slim package size with no dependencies.

Install

$ npm install mnemonic-id

Usage

Import in either way that suits your environment:

import { createNameId } from 'mnemonic-id';
createNameId();
import * as mnemonicId from 'mnemonic-id';
mnemonicId.createNameId();
const mnemonicId = require('mnemonic-id');
mnemonicId.createNameId();

Then select one of the existing id formats:

/** Format "noun", ≈ 10^2 permutations, 10 max length */
createNounId(); // -> narwhal

/** Format "adj+noun", ≈ 10^5 permutations, 19 max length */
createNameId(); // -> hungry-hippo

/** Format "adj+adj+noun", ≈ 10^6 permutations, 28 max length */
createLongNameId(); // -> hot-splendid-duck

/** Format "adj+noun+id", ≈ 10^14 permutations, 26 max length */
createUniqueNameId(); // -> dull-dugong-QkCHmf

/** Format "verb+adj+noun", ≈ 10^6 permutations, 28 max length */
createQuestId(); // -> find-pretty-sheep

/** Format "adj+noun+verb+adj+noun", ≈ 10^12 permutations, 48 max length */
createStoryId(); // -> eloquent-beaver-quote-unknown-dinosaur

/** Format "adj+adj+noun+verb+adj+adj+noun", ≈ 10^17 permutations, 64 max length */
createLongStoryId(); // -> wicked-evil-eel-help-horrible-pretty-hamster

/** Format "number" of given length, length^10 - length^9 permutations */
createNumberId(10); // -> 6941634647  (= 10^10-10^9 permutations)

/** Format "id" of given length, = 40^length permutations */
createId(10); // -> uXOGTUiOoD  (= 40^10 ≈ 10^16 permutations)

Or customize your own:

createCustomId({
  adjectives: 2,
  subject: true,
  verb: true,
  object: true,
  numberSuffix: 4,
  idSuffix: 6,
  delimiter: '_',
  capitalize: true
}); // -> Talented_Bold_Pig_Hunt_Brawny_Supreme_Bumblebee_6343_VQ5EAZ

Most existing formats can also be customized:

createNameId({
  adjectives: 3, 
  capitalize: true
  delimiter: '',
}); // -> OrdinaryCuddlyLaughingSquid

Options

Description of options:

interface IdOpts {
  /** Number of adjectives given to object/subject */
  adjectives?: number;
  /** Creates subject in id sentence */
  subject?: boolean;
  /** Creates verb in id sentence */
  verb?: boolean;
  /** Creates object in id sentence */
  object?: boolean;
  /** Creates number of given length at end of id sentence */
  /** Creates id of given length at end of id sentence */
  idSuffix?: number;
  /** Delimiter to be used in id sentence */
  delimiter?: string;
  /** Capitalize each word in sentence */
  capitalize?: boolean;
}

Alternatives

Similar libraries that also exist:

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 14 Jun 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc