Segmenter
Bindings to JavaScript's Intl.Segmenter.
See MDN for API details.
t
type tgranularity
type granularity = [#grapheme | #sentence | #word]options
type options = {
localeMatcher?: Intl_Common.localeMatcher,
granularity?: granularity,
}pluralCategories
type pluralCategories = [
| #few
| #many
| #one
| #other
| #two
| #zero
]resolvedOptions
type resolvedOptions = {
locale: string,
granularity: granularity,
}supportedLocalesOptions
type supportedLocalesOptions = {
localeMatcher: Intl_Common.localeMatcher,
}make
let make: (~locales: array<string>=?, ~options: options=?) => tCreates a new Intl.Segmenter instance for segmenting strings.
See Intl.Segmenter on MDN.
Examples
RESCRIPTlet segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #word})
Intl.Segmenter.resolvedOptions(segmenter).granularity == #word
supportedLocalesOf
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
RESCRIPTIntl.Segmenter.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]
resolvedOptions
let resolvedOptions: t => resolvedOptionsresolvedOptions(segmenter) returns the locale and granularity currently in use.
See Intl.Segmenter.prototype.resolvedOptions on MDN.
Examples
RESCRIPTlet segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #sentence})
Intl.Segmenter.resolvedOptions(segmenter).granularity == #sentence
segment
let segment: (t, string) => Intl_Segments.tsegment(segmenter, input) returns a Segments object describing input.
See Intl.Segmenter.prototype.segment on MDN.
Examples
RESCRIPTlet segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #word})
let segments = segmenter->Intl.Segmenter.segment("Hello world")
Intl.Segments.containingWithIndex(segments, 0).segment == "Hello"
ignore
let ignore: t => unitignore(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.