1.0.10 • Published 6 years ago

uneeqid v1.0.10

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

What's this?

A random string generator. (Yes, there are lots of them, but this was built as a learning exercise).

Demo

Right here

How to use it?

Just like so:

var ID = require('uneeqid');

and then in your program:

ID.generate()

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();

Or

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.

Options

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.

Type:

ID.type = 'loweralpha';
TypeExplanationExample (length = 16)
alphanumericlower and upper case alphabets + numbers (0-9)GejPA8BmYh55GuYU
loweralphanumericlowercase alphabets + numbersdjnzzm1eh7p1n82e
alphalower and upper case alphabets onlyKmIQCOvZzLVHiIZw
numericnumbers only8759684248582452
loweralphalower case alphabets onlycivjbazwxbwbaqgw
alphasymbolalphabets and symbolstlqQ_zXWa=l+ACFB
loweralphasymbollower case alphabets and symbols@dw%uq$ms~i!$x)m
alphanumericsymbolalphabets numbers and symbolsR^O=1Rz~A!qFB~58
loweralphanumericsymbollower case alphabets, numbers and symbols?ucprlw)yut8$_wj

Length:

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:

ID.lastID

Gives you the last generated ID. Is changed whenever you use ID.generate();

ID.flush()

Flushes out ID.list

ID.reset()

Resets everything (type, length, list, lastID).

Licence

No warranties whatsoever. Other than that, do whatever you want; no credits required.

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago