Module Brr.Jstr

JavaScript strings.

TODO. do a useful string API.


type t

The type for JavaScript strings.

val v : string -> t

v s is the string s as a javascript string.

val vf : ('a, Stdlib.Format.formatter, unit, t) Stdlib.format4 -> 'a

vf fmt ... is a Javascript string formatted according to fmt.

val empty : t

empty is an empty string.

val is_empty : t -> bool

is_empty s is true iff s is an empty string.

val append : t -> t -> t

append s0 s1 appends s1 to s0.

val cuts : sep:t -> t -> t list

cuts sep s is the list of all (possibly empty) substrings of s that are delimited by matches of the non empty separator string sep.

val concat : sep:t -> t list -> t

concat sep ss is the concatenates the list of strings ss inserting sep between each of them.

val slice : ?⁠start:int -> ?⁠stop:int -> t -> t

slice ~start ~stop s is the string s.start, s.start+1, ... s.stop - 1. start defaults to 0 and stop to String.length s.

If start or stop are negative they are subtracted from String.length s. This means that -1 denotes the last character of the string.

val trim : t -> t

trim s is s without whitespace from the beginning and end of the string.

val chop : prefix:t -> t -> t option

chop prefix s is s without the prefix prefix or None if prefix is not a prefix of s.

val rchop : suffix:t -> t -> t option

rchop suffix s is s without the suffix suffix or None if suffix is not a suffix of s.

val equal : t -> t -> bool

equal s0 s1 is true iff s0 and s1 are equal.

val compare : t -> t -> int

compare s0 s1 is a total order on strings compatible with equal.


val to_string : t -> string

to_string s is s as an OCaml string.

val of_string : string -> t

of_string s is the OCaml string s as a JavaScript string.

val to_int : t -> int option

to_int s is int_of_string (to_string s) with Failure _ mapping on None.

val of_int : int -> t

of_int i is Jstr.v (string_of_int i).

val pp : Stdlib.Format.formatter -> t -> unit

pp ppf s prints s on ppf.