package nanoid

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Implementation of Nano ID, a tiny, secure, URL-friendly, unique string ID generator popular in the javascript ecosystem.

The interface mimics the Javascript interface as closely as possible with a single nanoid entrypoint. Custom alphabets are not yet supported.

Both native and js_of_ocaml environments are supported 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.

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. Use the Nanoid_os library to customize the random number generation.

val nanoid : ?size:int -> unit -> string

nanoid ?size () generates a random Nano ID of size size, which defaults to 21.

OCaml

Innovation. Community. Security.