You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Otherwise, you could install through this root project directory:
$ luarocks --local make
Usage
To load this library, just type:
localcuid=require ("cuid")
Once loaded, you can generate fresh CUIDs through:
localid=cuid.generate ( )
As an example of CUID, we have c00p6qup20000ckkzslahp5pn, where:
c is the CUID prefix (so it's a valid variable).
00p6qup2 is a timestamp/continuous number.
0000 is the internal sequential counter.
ckkz is the machine/host fingerprint.
slahp5pn are pseudo-random numbers.
To generate slugs (shorter and collision-weak CUIDs), just type the following:
localslug=cuid.slug ( )
Slugs are made of 8 characters, and there's no prefix
(as is the case of CUIDs - "c" in the case). So, slugs
are often used as suffixes, for instance, on URLs.
Configuration
You could as well set a custom fingerprint for CUID generation
by an environment variable. This environment variable is called
LUA_CUID_FINGERPRINT.
Whenever the cuid library is loaded, it will lookup such
environment variable to generate a fingerprint if it is
indeed defined.
It's also possible to set a custom fingerprint prior CUID/slug
generation, just type the following for both cases:
Such fingerprint text is used only once per function call,
that is, on the next function call, everything remains the
same of previous state prior custom fingerprint's function
call.
Remarks
Pull requests and issues are welcome! Happy hacking!