package crockford
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=3e26e20be39cf0c98588dd256d8be3fd
sha512=90407e12691cd55cd32d556baf250d505f108fd0a4f83ed044f757829fe75dce481321d7d14eea7e93c882286ea7904029c3a2b5250da8b4981ea52e593d14e5
Description
An OCaml implementation of Douglas Crockford's Base32 encoding with ISO 7064 checksum support. Provides encoding and decoding of int64 values to URI-friendly base32 strings, with optional checksum validation, padding, splitting, and random ID generation.
Added to opam-repository:
README
Crockford Base32 Encoding for OCaml
An OCaml implementation of Douglas Crockford's Base32 encoding with ISO 7064 checksum support. Provides encoding and decoding of int64 values to URI-friendly base32 strings, with optional checksum validation, padding, splitting, and random ID generation. Ported from https://github.com/front-matter/commonmeta.
Installation
opam install crockfordOr add to your dune-project:
(package
(depends
(crockford)))Usage
Basic Encoding and Decoding
(* Encode a number *)
let encoded = Crockford.encode 1234567890L in
(* "16jkpa2" *)
(* Decode back to number *)
let decoded = Crockford.decode "16jkpa2" in
(* 1234567890L *)With Checksum
(* Encode with checksum *)
let encoded = Crockford.encode ~checksum:true 1234567890L in
(* "16jkpa2d" *)
(* Decode and validate checksum *)
let decoded = Crockford.decode ~checksum:true "16jkpa2d" in
(* 1234567890L - or raises Checksum_mismatch if invalid *)Formatted Output
(* Split with dashes for readability *)
let encoded = Crockford.encode ~split_every:4 1234567890L in
(* "16jk-pa2" *)
(* With minimum length (zero-padded) *)
let encoded = Crockford.encode ~min_length:10 1234L in
(* "000000016j" *)Random ID Generation
Random.self_init ();
(* Generate random IDs *)
let id = Crockford.generate ~length:8 ~checksum:true () in
(* e.g., "a3x7m9q5" *)
(* Generate formatted IDs *)
let id = Crockford.generate ~length:16 ~split_every:4 ~checksum:true () in
(* e.g., "7n2q-8xkm-5pwt-3hr9" *)Normalization
(* Handles common character confusions *)
let decoded = Crockford.decode "ILO" in (* Treated as "110" *)
let decoded = Crockford.decode "16-JK-PA" in (* Dashes ignored *)License
MIT License
Author
Anil Madhavapeddy anil@recoil.org (based on code from https://github.com/front-matter/commonmeta)
Links
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building crockford with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 1.0.0 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure