Segmenter

Bindings to JavaScript's Intl.Segmenter.

See MDN for API details.

granularity

RESCRIPT
type granularity = [#grapheme | #sentence | #word]

ignore

RESCRIPT
let ignore: t => unit

ignore(segmenter) ignores the provided segmenter and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

make

RESCRIPT
let make: (~locales: array<string>=?, ~options: options=?) => t

Creates a new Intl.Segmenter instance for segmenting strings.

See Intl.Segmenter on MDN.

Examples

RESCRIPT
let segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #word}) Intl.Segmenter.resolvedOptions(segmenter).granularity == #word

options

RESCRIPT
type options = { localeMatcher?: Intl_Common.localeMatcher, granularity?: granularity, }

pluralCategories

RESCRIPT
type pluralCategories = [ | #few | #many | #one | #other | #two | #zero ]

resolvedOptions

RESCRIPT
type resolvedOptions = { locale: string, granularity: granularity, }

resolvedOptions

RESCRIPT
let resolvedOptions: t => resolvedOptions

resolvedOptions(segmenter) returns the locale and granularity currently in use.

See Intl.Segmenter.prototype.resolvedOptions on MDN.

Examples

RESCRIPT
let segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #sentence}) Intl.Segmenter.resolvedOptions(segmenter).granularity == #sentence

segment

RESCRIPT
let segment: (t, string) => Intl_Segments.t

segment(segmenter, input) returns a Segments object describing input.

See Intl.Segmenter.prototype.segment on MDN.

Examples

RESCRIPT
let segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #word}) let segments = segmenter->Intl.Segmenter.segment("Hello world") Intl.Segments.containingWithIndex(segments, 0).segment == "Hello"

supportedLocalesOf

RESCRIPT
let supportedLocalesOf: ( array<string>, ~options: supportedLocalesOptions=?, ) => array<string>

supportedLocalesOf(locales, ~options) filters locales to those supported for segmentation.

See Intl.Segmenter.supportedLocalesOf on MDN.

Examples

RESCRIPT
Intl.Segmenter.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]

supportedLocalesOptions

RESCRIPT
type supportedLocalesOptions = { localeMatcher: Intl_Common.localeMatcher, }

t

RESCRIPT
type t