slug

Url safe slug generator
README

Url safe slug generator for OCaml

This library turns title into URL-safe slug with support for non-latin characters.

This library uses algorithm and data from node-slugify

Installation

opam install slug

If you use esy

esy add @opam/slug

Usage

  • OCaml syntax:

Slug.slugify "my string";;
- : string = "my-string"

(* Custom separator *)
Slug.slugify ?sep: "_" "my string";;
- : string = "my_string" 

(* Retain uppercase *)
Slug.slugify ?lowercase: false "My String";;
- : string = "My-String" 

(* Use locale *)
let with_vi = Slug.(Charmap.mk_charmap [Slug_data.base; Slug_data.vi]);;
- : Charmap.t = <abstr>
Slug.slugify ?charmap: with_vi "Đ";;
- : string = "d" 
Slug.slugify "Đ";;
- : string = "dj"

(* Custom characters map *)
let custom_map = Slug.(Charmap.mk_charmap [Slug_data.base; [ ("M", "z"); ("m", "z") ]]);;
val custom_map : Charmap.t = <abstr>

Slug.slugify ?charmap: custom_map "Mm";;
- : string = "zz"
  • ReasonML syntax

Slug.slugify("my string");
- : string = "my-string"

/* Custom separator */
Slug.slugify(~sep = "_", "my string");
- : string = "my_string" 

/* Retain uppercase */
Slug.slugify(~lowercase = false, "My String");
- : string = "My-String" 

/* Use locale */
let with_vi = Slug.(Charmap.mk_charmap([Slug_data.base, Slug_data.vi]));
let with_vi : Charmap.t = <abstr>
Slug.slugify(~charmap = with_vi, "Đ");
- : string = "d" 
Slug.slugify("Đ");
- : string = "dj"

/* Custom characters map */
let custom_map = Slug.(Charmap.mk_charmap([Slug_data.base, [ ("M", "z"), ("m", "z") ]]));;
let custom_map : Charmap.t = <abstr>

Slug.slugify(~charmap = custom_map, "Mm");
- : string = "zz"

Notice

Please don't send PR to update data/*. They are auto-generated from upstream library.

Please send PRs about new locales to node-slugify.

If you really need it, you can use a custom_map instead.

License

MIT. Data are downloaded from node-slugify

Install
Maintainers
Sources
1.0.1.tar.gz
md5=4a3663a216f8a2696d6897f99c98b80b
Dependencies
re
>= "1.7.2"
uunf
>= "1.0.0"
alcotest
with-test
dune
>= "2.0"
ocaml
>= "4.05"
Reverse Dependencies
camyll
>= "0.4.0"