hashids-ocaml is an OCaml (4.02.3+) implementation of hashids. It generates short, unique, non-sequential ids from numbers, that you can also decode. It is compatible with version 1.0.0 of hashids.

It’s licensed under the MIT license. It’s available on OPAM, its documentation and its source code are on GitHub.

Questions? Remarks? Bugs? Want to contribute? Open an issue!

https://img.shields.io/travis/jacquev6/hashids-ocaml/master.svg https://img.shields.io/github/issues/jacquev6/hashids-ocaml.svg https://img.shields.io/github/forks/jacquev6/hashids-ocaml.svg https://img.shields.io/github/stars/jacquev6/hashids-ocaml.svg

Quick start

Install from OPAM:

$ opam install hashids

Launch utop:

$ utop -require hashids

Create a config:

utop # let config = Hashids.make ();;
val config : Hashids.t = <abstr>

Encode some integers:

utop # Hashids.encode config [42; 57];;
- : string = "wYcGX"

And decode them:

utop # Hashids.decode config "wYcGX";;
- : int list = [42; 57]


module Hashids : sig
type t
val make: ?salt:string -> ?min_length:int -> ?alphabet:string -> unit -> t

salt: an arbitrary string used to randomize the encoding.

min_length: an integer specifying the minimal length of encoded values. Useful to hide their order of magnitude.

alphabet: the set of characters used to encode.

val encode: t -> int list -> string
val decode: t -> string -> int list