package nanoid
Install
Dune Dependency
Authors
Maintainers
Sources
md5=a5c602bbac85b60218297f4705726ed9
sha512=debb9c4c0fb1ccadb4814cda797e96d380b20120e258b3b193635e65215a6fe74ab932fca40ab27d6502f72797326b44329952336bab2e745feb963d03e82419
README.md.html
Nano ID for OCaml %%VERSION%%
This is an implementation of Nano ID, a tiny, secure, URL-friendly, unique string ID generator.
API
The API in documented in the source code. It mimics the Javascript interface and is mostly composed of a single entrypoint which generates a Nano ID of the given size, which defaults to 21.
val nanoid : ?size:int -> unit -> string
Usage
Nanoid supports both native and js_of_ocaml environments via a virtual library: nanoid
. Libraries should depend on this library, and final executables should pick an implementation by depending either on nanoid.os
or nanoid.jsoo
.
Unsupported features
Custom alphabets are not yet supported.
Native implementation
The native implementation mimics the javascript one and relies by default on cryptokit
pseudo random number generator seeded with the current unix time as given by Unix.gettimeofday
. This should yield satisfying results for most application without ever blocking, unless you need strong cryptographic guarantees for security reasons.
One can customize the random number generation by using the nanoid_os
library instead. The generated module will only work in native code. One can regain this genericity by functorizing over the Nanoid_os.S
interface. The setup used in nanoid.os
is the one generated by Simple ()
.