Current section

Files

Jump to
gossamer src utils intl.ffi.mjs
Raw

src/utils/intl.ffi.mjs

// src/utils/intl.ffi.ts
import * as $intl from "../gossamer/intl.mjs";
import { Result$Error, Result$Ok } from "../../prelude.mjs";
import { fromArray, toArray } from "./list.ffi.mjs";
function supportedLocalesOf(lookup, locales) {
try {
return Result$Ok(fromArray(lookup(toArray(locales))));
} catch {
return Result$Error(void 0);
}
}
function toLocaleMatcher(matcher) {
return $intl.LocaleMatcher$isBestFit(matcher) ? "best fit" : "lookup";
}
function toHourCycle(cycle) {
if ($intl.HourCycle$isH11(cycle)) return "h11";
if ($intl.HourCycle$isH12(cycle)) return "h12";
if ($intl.HourCycle$isH23(cycle)) return "h23";
return "h24";
}
function toLabelStyle(style) {
if ($intl.LabelStyle$isLong(style)) return "long";
if ($intl.LabelStyle$isShort(style)) return "short";
return "narrow";
}
function fromLabelStyle(value) {
switch (value) {
case "long":
return $intl.LabelStyle$Long();
case "short":
return $intl.LabelStyle$Short();
default:
return $intl.LabelStyle$Narrow();
}
}
function fromRangeSource(source) {
if (source === "startRange") return $intl.RangePartSource$Start();
if (source === "endRange") return $intl.RangePartSource$End();
return $intl.RangePartSource$Shared();
}
function fromHourCycle(value) {
switch (value) {
case "h11":
return $intl.HourCycle$H11();
case "h12":
return $intl.HourCycle$H12();
case "h24":
return $intl.HourCycle$H24();
default:
return $intl.HourCycle$H23();
}
}
function toCaseFirst(value) {
if ($intl.CaseFirst$isUpper(value)) return "upper";
if ($intl.CaseFirst$isLower(value)) return "lower";
return "false";
}
function fromCaseFirst(value) {
switch (value) {
case "upper":
return $intl.CaseFirst$Upper();
case "lower":
return $intl.CaseFirst$Lower();
default:
return $intl.CaseFirst$Neither();
}
}
export {
fromCaseFirst,
fromHourCycle,
fromLabelStyle,
fromRangeSource,
supportedLocalesOf,
toCaseFirst,
toHourCycle,
toLabelStyle,
toLocaleMatcher
};