callsign-uid
v1.0.6
Published
A NodeJS package that generates easily memorizable unqiue ids.
Readme
callsign-uid
A NodeJS package that generates easily memorizable unqiue ids.
Usage
To create a random CUID:
const Cuid = require("callsign-uid");
var myCuid = Cuid.Random();
var text = myCuild.text;To convert from Denary to CUID:
const Cuid = require("callsign-uid");
const myNum = 415898986;
var myCuid = Cuid.FromDenary(myNum);
console.log(myCuid.text); //ALJET959L (lower case)How it works
CUID generates a uid has the format of [Pronounceable 5-letter word][3 digits][1 single letter]. Combined, this algorithm yields 25,000,000,000 (25 billion) unique ids for a single CUID. Multiple CUIDs can be combined to yield more unique ids.
We will focus on the generation of the pronounceable 5-letter word. The 3 digits and 1 letter are simple randomly chosen from a character set. In the following explanation, the letter V will be used to represent a Vowel, and the letter C will represent a Consonant. The letter Y does not count as a vowel, nor a consonant. It is only used for special purposes..
Suppose a 5-letter phrase, 12345, where each number represents the corresponding character in a pronounceable 5-letter word, the rules are:
- The arrangement of
12must be eitherVCorCV. - The arrangement of
345must be exactlyCVC. - If
2is a consonant, then3cannot be the same as2. If3is the sames as2when randomly generated,3will use the characterY.
This is guaranteed to produce a pronounceable word. For example:
AVBOX
DAHOT
TURETA full CUID could look like:
AVBOX681D
DAHOT039A
TURET223Q
QULEM001DNote that 0s is padded to the front of the three-digit number.
Conversion From Denary
Sometimes there may be the need to convert a number into a CUID. Heres how it works:
Counting in CUID works the same way as denary numbers. You count up from the rightmost number, and when that number reaches the limit, your increment the number to the left of it by 1. With CUID, it is the same. You start from the rightmost. Note that there are no capitalization. Assume all characters are upper or lower case.
Some rules regarding counting:
- For the three digits,
0is the lowest data level,9is the highest data level. - For any vowel,
Ais the lowest data level,Uis the highest. - For any consonants,
Bis the lowest data level,Zis the highest.
According to these rules, the denary number 0 would translate to ABCAB000A in CUID. The denary number 1 would translate to ABCAB000B.
Flaws
It is important to know that an algorithm that generates a pronounceable word is prone to generating innapropriate or vulgar words. While there is an filter for vulgar words, it is not fool-proof.
