1.0.1 • Published 4 years ago

wordhash v1.0.1

Weekly downloads
39
License
Unlicense
Repository
github
Last release
4 years ago

WordHash

WordHash creates a human-readable hash designed for uuids but can handle other strings too.

Installation

Use the package manager npm to install wordhash.

npm install wordhash

Usage

var WordHash = require('wordhash');

var wordHash = WordHash();

const input = "0073baeb-c5dc-48a5-bcf7-b35f9d7a36fd";

wordHash.hash(input);
//  "video-sad-carolina-twenty"

wordHash.hash("d13175d4-bee9-4e80-b24c-89c15c126cbf");
//  "massachusetts-social-apart-robert"
  
WordHash({ salt: 'saltySalt'}).hash(input)
//  "skylark-bakerloo-low-early"

WordHash({ length: '3'}).hash(input)
//  "video-sad-carolina"

WordHash({ separator: '~'}).hash(input)
//  "video~sad~carolina~twenty"

WordHash({ separator: null }).hash(input)
//  ["video", "sad", "carolina", "twenty"]

See test.js for usage more examples

Caveats

WordHash conversions are one way, and are not as 'unique' as uuids meaning its more likely to be collisions. With default settings its statistical uniqueness is only around 1 in 4.3 billion.

How It Works

Each word is generated by mapping a segment of the input to a word in the wordlist. Segments are taken from the start of the md5 hash of the string and salt.

This algorithm is deterministic, so the same input and wordlist will always produce the same output.

Inspiration

License

Unlicense