Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

27

dist/index.d.ts

@@ -19,22 +19,23 @@ interface IdOpts {

}
/** Returns id with ≈ 10^4 permutations (e.g. "cool-dragonfly") */
/** Returns id in format "noun" (e.g. "narwhal"), ≈ 10^2 permutations, 10 max length */
export declare function createNounId(opts?: IdOpts): string;
/** Returns id in format "adj+noun" (e.g. "hungry-hippo"), ≈ 10^5 permutations, 19 max length */
export declare function createNameId(opts?: IdOpts): string;
/** Returns id with ≈ 10^6 permutations (e.g. "hot-splendid-duck") */
/** Returns id in format "adj+adj+noun" (e.g. "hungry-hippo"), ≈ 10^6 permutations, 28 max length */
export declare function createLongNameId(opts?: IdOpts): string;
/** Returns id with ≈ 10^14 permutations (e.g. "dull-dugong-8x4s0K") */
/** Returns id in format "adj+noun+id" (e.g. "dull-dugong-QkCHmf"), ≈ 10^14 permutations, 26 max length */
export declare function createUniqueNameId(opts?: IdOpts): string;
/** Returns id with ≈ 10^6 permutations */
/** Returns id in format "verb+adj+noun" (e.g. "find-pretty-sheep"), ≈ 10^6 permutations, 28 max length */
export declare function createQuestId(opts?: IdOpts): string;
/** Returns id with ≈ 10^10 permutations */
/** Returns id in format "adj+noun+verb+adj+noun" (e.g. "eloquent-beaver-quote-unknown-dinosaur"), ≈ 10^10 permutations, 48 max length */
export declare function createStoryId(opts?: IdOpts): string;
/** Returns id with ≈ 10^14 permutations */
/** Returns id in format "adj+adj+noun+verb+adj+adj+noun" (e.g. "wicked-evil-eel-help-horrible-pretty-hamster"), ≈ 10^14 permutations,
* 64 max length */
export declare function createLongStoryId(opts?: IdOpts): string;
/** Returns customized id based on options */
/** Returns number of given length, = length^10-length^9 permutations */
export declare function createNumberId(length: number): string;
/** Returns id of given length, = 40^x permutations */
export declare function createId(length: number): string;
/** Returns customized id based on given options */
export declare function createCustomId(opts?: IdOpts): string;
/** Returns id with ≈ 10^2 permutations (e.g. "narwhal") */
export declare function createNounId(opts?: IdOpts): string;
/** Returns id of given length */
export declare function createId(length: number): string;
/** Returns number of given length */
export declare function createNumberId(length: number): string;
export {};

@@ -6,7 +6,12 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createNumberId = exports.createId = exports.createNounId = exports.createCustomId = exports.createLongStoryId = exports.createStoryId = exports.createQuestId = exports.createUniqueNameId = exports.createLongNameId = exports.createNameId = void 0;
exports.createCustomId = exports.createId = exports.createNumberId = exports.createLongStoryId = exports.createStoryId = exports.createQuestId = exports.createUniqueNameId = exports.createLongNameId = exports.createNameId = exports.createNounId = void 0;
const verbs_1 = __importDefault(require("./words/verbs"));
const noun_1 = __importDefault(require("./words/noun"));
const adjectives_1 = __importDefault(require("./words/adjectives"));
/** Returns id with ≈ 10^4 permutations (e.g. "cool-dragonfly") */
/** Returns id in format "noun" (e.g. "narwhal"), ≈ 10^2 permutations, 10 max length */
function createNounId(opts = {}) {
return createCustomId(Object.assign({ subject: true }, opts));
}
exports.createNounId = createNounId;
/** Returns id in format "adj+noun" (e.g. "hungry-hippo"), ≈ 10^5 permutations, 19 max length */
function createNameId(opts = {}) {

@@ -16,3 +21,3 @@ return createCustomId(Object.assign({ adjectives: 1, subject: true }, opts));

exports.createNameId = createNameId;
/** Returns id with ≈ 10^6 permutations (e.g. "hot-splendid-duck") */
/** Returns id in format "adj+adj+noun" (e.g. "hungry-hippo"), ≈ 10^6 permutations, 28 max length */
function createLongNameId(opts) {

@@ -22,3 +27,3 @@ return createCustomId(Object.assign({ adjectives: 2, subject: true }, opts));

exports.createLongNameId = createLongNameId;
/** Returns id with ≈ 10^14 permutations (e.g. "dull-dugong-8x4s0K") */
/** Returns id in format "adj+noun+id" (e.g. "dull-dugong-QkCHmf"), ≈ 10^14 permutations, 26 max length */
function createUniqueNameId(opts = {}) {

@@ -28,3 +33,3 @@ return createNameId(Object.assign({ idSuffix: 6 }, opts));

exports.createUniqueNameId = createUniqueNameId;
/** Returns id with ≈ 10^6 permutations */
/** Returns id in format "verb+adj+noun" (e.g. "find-pretty-sheep"), ≈ 10^6 permutations, 28 max length */
function createQuestId(opts = {}) {

@@ -34,3 +39,3 @@ return createCustomId(Object.assign({ adjectives: 1, verb: true, object: true }, opts));

exports.createQuestId = createQuestId;
/** Returns id with ≈ 10^10 permutations */
/** Returns id in format "adj+noun+verb+adj+noun" (e.g. "eloquent-beaver-quote-unknown-dinosaur"), ≈ 10^10 permutations, 48 max length */
function createStoryId(opts = {}) {

@@ -40,3 +45,4 @@ return createCustomId(Object.assign({ adjectives: 1, subject: true, verb: true, object: true }, opts));

exports.createStoryId = createStoryId;
/** Returns id with ≈ 10^14 permutations */
/** Returns id in format "adj+adj+noun+verb+adj+adj+noun" (e.g. "wicked-evil-eel-help-horrible-pretty-hamster"), ≈ 10^14 permutations,
* 64 max length */
function createLongStoryId(opts = {}) {

@@ -46,3 +52,26 @@ return createStoryId(Object.assign({ adjectives: 2 }, opts));

exports.createLongStoryId = createLongStoryId;
/** Returns customized id based on options */
/** Returns number of given length, = length^10-length^9 permutations */
function createNumberId(length) {
const choices = '0123456789';
let out = '';
if (length > 0) {
out += choices[randomInt(1, choices.length)];
}
for (let i = 1; i < length; i += 1) {
out += choices[randomInt(0, choices.length)];
}
return out;
}
exports.createNumberId = createNumberId;
/** Returns id of given length, = 40^x permutations */
function createId(length) {
const choices = 'ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789';
let out = '';
for (let i = 0; i < length; i += 1) {
out += choices[randomInt(0, choices.length)];
}
return out;
}
exports.createId = createId;
/** Returns customized id based on given options */
function createCustomId(opts = {}) {

@@ -84,30 +113,2 @@ opts = Object.assign({ adjectives: 0, subject: false, verb: false, object: false, delimiter: '-', numberSuffix: 0, idSuffix: 0 }, opts);

exports.createCustomId = createCustomId;
/** Returns id with ≈ 10^2 permutations (e.g. "narwhal") */
function createNounId(opts = {}) {
return createCustomId(Object.assign({ subject: true }, opts));
}
exports.createNounId = createNounId;
/** Returns id of given length */
function createId(length) {
const choices = 'ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789';
let out = '';
for (let i = 0; i < length; i += 1) {
out += choices[randomInt(0, choices.length)];
}
return out;
}
exports.createId = createId;
/** Returns number of given length */
function createNumberId(length) {
const choices = '0123456789';
let out = '';
if (length > 0) {
out += choices[randomInt(1, choices.length)];
}
for (let i = 1; i < length; i += 1) {
out += choices[randomInt(0, choices.length)];
}
return out;
}
exports.createNumberId = createNumberId;
function randomFromList(list) {

@@ -114,0 +115,0 @@ return list[randomInt(0, list.length)];

@@ -64,3 +64,2 @@ "use strict";

gorilla
grasshopper
hamster

@@ -123,3 +122,2 @@ hedgehog

rat
rattlesnake
rhino

@@ -126,0 +124,0 @@ robin

@@ -166,2 +166,3 @@ "use strict";

smell
snuggle
soak

@@ -168,0 +169,0 @@ study

{
"name": "mnemonic-id",
"description": "Library to generate easy to remember, and sometimes entertaining, human readable ids",
"version": "3.1.1",
"version": "3.2.0",
"license": "MIT",

@@ -18,3 +18,4 @@ "author": "Mattias E. O. Andersson",

"readable",
"sentence"
"sentence",
"memorable"
],

@@ -34,2 +35,3 @@ "main": "dist/index.js",

"coverage": "jest --coverage",
"coverage-upload": "jest --coverage && coveralls < coverage/lcov.info",
"format": "prettier ./src --write",

@@ -47,2 +49,3 @@ "format-check": "prettier ./src --check",

"@typescript-eslint/parser": "3.0.0",
"coveralls": "3.1.0",
"eslint": "7.1.0",

@@ -49,0 +52,0 @@ "husky": "4.2.5",

# Mnemonic id
![Coverage Status](https://coveralls.io/repos/github/Adelost/mnemonic-id/badge.svg?branch=master)
![TypeScript-ready](https://img.shields.io/npm/types/mnemonic-id.svg)
Library to generate easy to remember, and sometimes entertaining, human readable ids.
```
createStoryId(); // -> eloquent-beaver-quote-average-fish
createStoryId(); // -> awesome-chipmunk-banish-evil-rat
```

@@ -10,7 +13,8 @@

## Features
* Dictionary of approximate 150 nouns (animals), 200 verbs, 500 adjectives
* Profanity free
* Customizable id generation
* TypeScript annotated API
## 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.

@@ -41,12 +45,30 @@ ## Install

Then select one of the existing id formats:
```
createNounId(); // -> narwhal (≈ 10^2 permutations)
createNameId(); // -> hungry-hippo (≈ 10^5 permutations)
createLongNameId(); // -> hot-splendid-duck (≈ 10^7 permutations)
createUniqueNameId(); // -> gallant-jellyfish-QkCHmf (≈ 10^14 permutations)
createQuestId(); // -> find-unknown-dinosaur (≈ 10^7 permutations)
createStoryId(); // -> awesome-chipmunk-banish-evil-rat (≈ 10^12 permutations)
createLongStoryId(); // -> wicked-evil-eel-help-horrible-pretty-hamster (≈ 10^17 permutations)
createNumberId(10); // -> 6941634647 (= 10^10 - 10^9 permutations)
createId(10); // -> uXOGTUiOoD (= 40^10 ≈ 10^16 permutations)
/** 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)
```

@@ -71,3 +93,7 @@

```
createNameId({adjectives: 3, capitalize: true}); // -> Ordinary-Cuddly-Laughing-Squid
createNameId({
adjectives: 3,
capitalize: true
delimiter: '',
}); // -> OrdinaryCuddlyLaughingSquid
```

@@ -82,14 +108,21 @@

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 */
numberSuffix?: number;
/** 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 */

@@ -101,3 +134,3 @@ capitalize?: boolean;

Similar libraries:
Similar libraries that also exist:

@@ -104,0 +137,0 @@ * [human-id](https://www.npmjs.com/package/human-id)

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