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 1.1.0 to 2.0.0

16

dist/index.d.ts

@@ -18,15 +18,17 @@ interface IdOpts {

/** Returns id with ≈ 10^6 permutations */
export declare function getName(opts?: IdOpts): string;
export declare function createNameId(opts?: IdOpts): string;
/** Returns id with ≈ 10^4 permutations */
export declare function getShortName(opts?: {}): string;
export declare function createShortNameId(opts?: {}): string;
/** Returns id with ≈ 10^6 permutations */
export declare function getAction(opts?: {}): string;
export declare function createActionId(opts?: {}): string;
/** Returns id with ≈ 10^10 permutations */
export declare function getStory(opts?: {}): string;
export declare function createStoryId(opts?: {}): string;
/** Returns id with ≈ 10^14 permutations */
export declare function createLongStoryId(opts?: {}): string;
/** Returns customized id based on options */
export declare function getCustom(opts?: IdOpts): string;
export declare function createCustomId(opts?: IdOpts): string;
/** Returns a customized id based on options */
export declare function getHashId(length: number): string;
export declare function createId(length: number): string;
/** Returns a customized id based on options */
export declare function getNumberId(length: number): string;
export declare function createNumberId(length: number): string;
export {};

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getNumberId = exports.getHashId = exports.getCustom = exports.getStory = exports.getAction = exports.getShortName = exports.getName = void 0;
exports.createNumberId = exports.createId = exports.createCustomId = exports.createLongStoryId = exports.createStoryId = exports.createActionId = exports.createShortNameId = exports.createNameId = void 0;
const verbs_1 = __importDefault(require("./words/verbs"));

@@ -12,27 +12,32 @@ const animals_1 = __importDefault(require("./words/animals"));

/** Returns id with ≈ 10^6 permutations */
function getName(opts) {
function createNameId(opts) {
opts = Object.assign({ adj: 2, subject: true }, opts);
return getCustom(opts);
return createCustomId(opts);
}
exports.getName = getName;
exports.createNameId = createNameId;
/** Returns id with ≈ 10^4 permutations */
function getShortName(opts = {}) {
function createShortNameId(opts = {}) {
opts = Object.assign({ adj: 1, subject: true }, opts);
return getCustom(opts);
return createCustomId(opts);
}
exports.getShortName = getShortName;
exports.createShortNameId = createShortNameId;
/** Returns id with ≈ 10^6 permutations */
function getAction(opts = {}) {
function createActionId(opts = {}) {
opts = Object.assign({ adj: 1, verb: true, object: true }, opts);
return getCustom(opts);
return createCustomId(opts);
}
exports.getAction = getAction;
exports.createActionId = createActionId;
/** Returns id with ≈ 10^10 permutations */
function getStory(opts = {}) {
opts = Object.assign({ adj: 2, subject: true, verb: true, object: true }, opts);
return getCustom(opts);
function createStoryId(opts = {}) {
opts = Object.assign({ adj: 1, subject: true, verb: true, object: true }, opts);
return createCustomId(opts);
}
exports.getStory = getStory;
exports.createStoryId = createStoryId;
/** Returns id with ≈ 10^14 permutations */
function createLongStoryId(opts = {}) {
return createStoryId(Object.assign({ adj: 2 }, opts));
}
exports.createLongStoryId = createLongStoryId;
/** Returns customized id based on options */
function getCustom(opts = {}) {
function createCustomId(opts = {}) {
const _opts = Object.assign({ adj: 0, subject: false, verb: false, object: false, delimiter: '-', numberSuffix: 0, idSuffix: 0 }, opts);

@@ -50,3 +55,3 @@ const parts = [];

if (_opts.object) {
parts.push(getCustom({
parts.push(createCustomId({
adj: _opts.adj,

@@ -58,7 +63,7 @@ subject: true,

if (_opts.idSuffix) {
const id = getHashId(_opts.idSuffix);
const id = createId(_opts.idSuffix);
parts.push(id);
}
if (_opts.numberSuffix) {
const id = getNumberId(_opts.numberSuffix);
const id = createNumberId(_opts.numberSuffix);
parts.push(id);

@@ -68,5 +73,5 @@ }

}
exports.getCustom = getCustom;
exports.createCustomId = createCustomId;
/** Returns a customized id based on options */
function getHashId(length) {
function createId(length) {
const choices = 'ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789';

@@ -79,5 +84,5 @@ let out = '';

}
exports.getHashId = getHashId;
exports.createId = createId;
/** Returns a customized id based on options */
function getNumberId(length) {
function createNumberId(length) {
const choices = '0123456789';

@@ -93,3 +98,3 @@ let out = '';

}
exports.getNumberId = getNumberId;
exports.createNumberId = createNumberId;
function randomFromList(list) {

@@ -96,0 +101,0 @@ return list[randomInt(0, list.length)];

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

@@ -6,0 +6,0 @@ "author": "Mattias E. O. Andersson",

@@ -8,6 +8,24 @@ # Mnemonic id

## Usage
```
import { createNameId, createStoryId } from 'mnemonic-id';
createNameId(); // -> hot-splendid-duck
createStoryId(); // -> neat-warthog-erase-evil-rat
```
or
```
const mnemonicId = require('mnemonic-id');
mnemonicId.createNameId(); // -> spicy-new-skunk
mnemonicId.createStoryId(); // -> fluffy-dragon-fly-nervous-pug
```
## Examples
### getName()
### createNameId()

@@ -26,3 +44,3 @@ Generates ids that strike a balance between conciseness and number of permutation.

### getShortName()
### createShortNameId()

@@ -41,3 +59,3 @@ Generates concise ids for when only a small number of instances is needed.

### getAction()
### createActionId()

@@ -56,3 +74,3 @@ Generates action-oriented ids.

### getStory()
### createStoryId()

@@ -71,8 +89,46 @@ Generates story-oriented ids.

### getCustom({...})
### createLongStoryId()
Generates vivid story-oriented ids.
≈ 10^14 permutations
Output:
```
wicked-evil-eel-help-horrible-pretty-hamster
neat-warthog-erase-evil-rat
modern-fox-lull-shy-dog
cuddly-bird-defy-moody-badger
```
### createId(length: number)
Generates id of given length
Output (length = 8):
```
jgCe7BQT
tO4xCM7i
ZDMrOk33
BsktPStU
```
### createNumberId(length: number)
Generates number of given length
Output (length = 4):
```
7175
2233
5368
6678
```
### createCustomId({...})
If neither of the predefined formats fits your use case,
the output is fully customizable through the `options` parameter:
```
getCustom({
createCustomId({
adj: 2,

@@ -79,0 +135,0 @@ subject: true,

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