Skip to content

nelsonic/uniki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uniki

Build Status Code Climate Test Coverage Dependency Status devDependency Status Node.js Version NPM Version

matrix-reloaded-keymaster

There are many use cases for unique keys.

Our "itch" is minimizing the bytes occupied in our database by frequent strings.

Like a Hash but shorter.

Usage

Install from NPM

npm install uniki ---save

Use it in your code/script

var uniki = require('uniki');
console.log(uniki('hello world')); // >> MJ7MSJwS    (ALWAYS The Same!)

That's all there is to it. Enjoy!

tl;dr

How many IDs?

Getting the base64 "digest" of the sha512 of a string means we have a 64 character population (potential characters):

A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, /

Which means we can have 648 = 281,474,976,710,656 or 281 Billion possible IDs. (way more than we will ever need!)

Hold On, This Sounds Familiar ...

If this looks familiar, its because it is!!
We have built a virtually identical module: https://www.npmjs.com/package/perma
The key (see what we did there...?) difference is that we are not excluding any characters from the population because no humans are going to be typing these keys, they are used exclusively by our database as keys.
Also similar is https://www.npmjs.com/package/aguid but uniki we don't want our keys to be 36 characters long!

About

🔑 Generate a unique key (uniki get it?) based on any string input

Resources

Stars

Watchers

Forks

Packages

No packages published