CUID generator for Lua.
For more information, see: http://usecuid.org
If available on LuaRocks:
$ luarocks --local install cuidOtherwise, you could install through this root project directory:
$ luarocks --local makeTo load this library, just type:
local cuid = require ("cuid")Once loaded, you can generate fresh CUIDs through:
local id = cuid.generate ( )As an example of CUID, we have c00p6qup20000ckkzslahp5pn, where:
cis the CUID prefix (so it's a valid variable).00p6qup2is a timestamp/continuous number.0000is the internal sequential counter.ckkzis the machine/host fingerprint.slahp5pnare pseudo-random numbers.
To generate slugs (shorter and collision-weak CUIDs), just type the following:
local slug = 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.
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:
local cuid = require 'cuid'
local fingerprint_input = "It's me, Mario!"
local id = cuid.generate (fingerprint_input)
local slug = cuid.slug (fingerprint_input)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.
Pull requests and issues are welcome! Happy hacking!