A random string generator. (Yes, there are lots of them, but this was built as a learning exercise).
How to use it?
Just like so:
var ID = require('uneeqid');
and then in your program:
Works right out of the box. Without setting any options, you'll get a 64-character alphanumeric.
Where can I use it?
Most likely when you want to create unique IDs for something like users, or links etc.
How can I make sure the ID is unique?
So you can pass a list of IDs as an array to the library. Like so:
ID.list = ['...','...','...']; ID.generate();
var arr = [...]; // this is some array that you build. Like an array of all existing userIDs in your table ID.list = arr; ID.generate();
ID will automatically check if the generated ID is already in the list of IDs you fed into ID.list. If yes, it will re-generate another ID till it creates an ID that's unique.
When you use
ID.generate() just like that, you get a 64-character long alphanumeric (with upper- and lower-case letters).
You can configure the length and the type of a string you want.
ID.type = 'loweralpha';
|Type||Explanation||Example (length = 16)|
|alphanumeric||lower and upper case alphabets + numbers (0-9)||GejPA8BmYh55GuYU|
|loweralphanumeric||lowercase alphabets + numbers||djnzzm1eh7p1n82e|
|alpha||lower and upper case alphabets only||KmIQCOvZzLVHiIZw|
|loweralpha||lower case alphabets only||civjbazwxbwbaqgw|
|alphasymbol||alphabets and symbols||tlqQ_zXWa=l+ACFB|
|loweralphasymbol||lower case alphabets and symbols||@dw%uq$ms~i!$x)m|
|alphanumericsymbol||alphabets numbers and symbols||R^O=1Rz
|loweralphanumericsymbol||lower case alphabets, numbers and symbols||?ucprlw)yut8$_wj|
Default is 64. You can give a number between 4 and 512 (both included). Anything off this will result in fallback to the default (64).
ID.length = 128;
Mo' things to do with this:
Gives you the last generated ID. Is changed whenever you use ID.generate();
Resets everything (type, length, list, lastID).
No warranties whatsoever. Other than that, do whatever you want; no credits required.