From e068641ee709ae051702aa3ae338b08c405c2415 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 23:43:37 -0500 Subject: [PATCH 01/18] feat: common Intl polymorphic variants --- src/intl/Core__Intl__Common.mjs | 2 + src/intl/Core__Intl__Common.res | 121 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/intl/Core__Intl__Common.mjs create mode 100644 src/intl/Core__Intl__Common.res diff --git a/src/intl/Core__Intl__Common.mjs b/src/intl/Core__Intl__Common.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/intl/Core__Intl__Common.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/intl/Core__Intl__Common.res b/src/intl/Core__Intl__Common.res new file mode 100644 index 00000000..f6c4165a --- /dev/null +++ b/src/intl/Core__Intl__Common.res @@ -0,0 +1,121 @@ +type localeMatcher = [#lookup | @as("best fit") #bestFit] + +type numberingSystem = [ + | #adlm + | #ahom + | #arab + | #arabext + | #bali + | #beng + | #bhks + | #brah + | #cakm + | #cham + | #deva + | #diak + | #fullwide + | #gong + | #gonm + | #gujr + | #guru + | #hanidec + | #hmng + | #hmnp + | #java + | #kali + | #kawi + | #khmr + | #knda + | #lana + | #lanatham + | #laoo + | #latn + | #lepc + | #limb + | #mathbold + | #mathdbl + | #mathmono + | #mathsanb + | #mathsans + | #mlym + | #modi + | #mong + | #mroo + | #mtei + | #mymr + | #mymrshan + | #mymrtlng + | #nagm + | #newa + | #nkoo + | #olck + | #orya + | #osma + | #rohg + | #saur + | #segment + | #shrd + | #sind + | #sinh + | #sora + | #sund + | #takr + | #talu + | #tamldec + | #telu + | #thai + | #tibt + | #tirh + | #tnsa + | #vaii + | #wara + | #wcho +] + +type oneTo21 = [ + | #1 + | #2 + | #3 + | #4 + | #5 + | #6 + | #7 + | #8 + | #9 + | #10 + | #11 + | #12 + | #13 + | #14 + | #15 + | #16 + | #17 + | #18 + | #19 + | #20 + | #21 +] + +type zeroTo20 = [ + | #0 + | #1 + | #2 + | #3 + | #4 + | #5 + | #6 + | #7 + | #8 + | #9 + | #10 + | #11 + | #12 + | #13 + | #14 + | #15 + | #16 + | #17 + | #18 + | #19 + | #20 +] From 50b6c02806c4751fb4b31e4d4a7f27a7bce8d245 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 22:09:46 -0500 Subject: [PATCH 02/18] feat: type-safe Intl.NumberFormat bindings --- src/intl/Core__Intl__NumberFormat.mjs | 9 +- src/intl/Core__Intl__NumberFormat.res | 225 +++++++++++++++++- .../Core__Intl__NumberFormat__Grouping.mjs | 2 + .../Core__Intl__NumberFormat__Grouping.res | 5 + test/Intl__NumberFormatTest.mjs | 51 ++++ test/Intl__NumberFormatTest.res | 32 +++ test/TempTests.mjs | 19 -- test/TempTests.res | 11 - 8 files changed, 314 insertions(+), 40 deletions(-) create mode 100644 src/intl/Core__Intl__NumberFormat__Grouping.mjs create mode 100644 src/intl/Core__Intl__NumberFormat__Grouping.res create mode 100644 test/Intl__NumberFormatTest.mjs create mode 100644 test/Intl__NumberFormatTest.res diff --git a/src/intl/Core__Intl__NumberFormat.mjs b/src/intl/Core__Intl__NumberFormat.mjs index d856702b..88f119a6 100644 --- a/src/intl/Core__Intl__NumberFormat.mjs +++ b/src/intl/Core__Intl__NumberFormat.mjs @@ -1,2 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ + + +var Grouping; + +export { + Grouping , +} +/* No side effect */ diff --git a/src/intl/Core__Intl__NumberFormat.res b/src/intl/Core__Intl__NumberFormat.res index 50f9866a..d5c3743f 100644 --- a/src/intl/Core__Intl__NumberFormat.res +++ b/src/intl/Core__Intl__NumberFormat.res @@ -1,28 +1,235 @@ +module Grouping = Core__Intl__NumberFormat__Grouping + type t +/** +An ISO 4217 currency code. e.g. USD, EUR, CNY +*/ +type currency = string +type currencyDisplay = [#symbol | #narrowSymbol | #code | #name] +type currencySign = [#accounting | #standard] +type notation = [#scientific | #standard | #engineering | #compact] + +/** +Used only when notation is #compact +*/ +type compactDisplay = [#short | #long] + +// TODO: "negative" is not yet well supported +type signDisplay = [ + | #auto + | #always + | #exceptZero + | #never +] + +type style = [#decimal | #currency | #percent | #unit] + +/** +Defined in https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier +Only used when style is #unit +*/ +type unitSystem = string + +/** +Only used when style is #unit +*/ +type unitDisplay = [#long | #short | #narrow] + +type rounding = [ + | #ceil + | #floor + | #expand + | #trunc + | #halfCeil + | #halfFloor + | #halfExpand + | #halfTrunc + | #halfEven +] + +type roundingPriority = [#auto | #morePrecision | #lessPrecision] + +type roundingIncrement = [ + | #1 + | #2 + | #5 + | #10 + | #20 + | #25 + | #50 + | #100 + | #200 + | #250 + | #500 + | #1000 + | #2000 + | #2500 + | #5000 +] + +type trailingZeroDisplay = [#auto | #stripIfInteger | #lessPrecision] + +type options = { + compactDisplay?: compactDisplay, + numberingSystem?: Core__Intl__Common.numberingSystem, + currency?: currency, + currencyDisplay?: currencyDisplay, + currencySign?: currencySign, + localeMatcher?: Core__Intl__Common.localeMatcher, + notation?: notation, + signDisplay?: signDisplay, + style?: style, + /** + required if style == #unit + */ + unit?: unitSystem, + unitDisplay?: unitDisplay, + useGrouping?: Grouping.t, + roundingMode?: rounding, // not available in firefox v110 + roundingPriority?: roundingPriority, // not available in firefox v110 + roundingIncrement?: roundingIncrement, // not available in firefox v110 + /** + Supported everywhere but Firefox as of v110 + */ + trailingZeroDisplay?: trailingZeroDisplay, + // use either this group + minimumIntegerDigits?: Core__Intl__Common.oneTo21, + minimumFractionDigits?: Core__Intl__Common.zeroTo20, + maximumFractionDigits?: Core__Intl__Common.zeroTo20, + // OR these + minimumSignificantDigits?: Core__Intl__Common.oneTo21, + maximumSignificantDigits?: Core__Intl__Common.oneTo21, +} + +type resolvedOptions = { + // only when style == "currency" + currency?: currency, + currencyDisplay?: currencyDisplay, + currencySign?: currencySign, + // only when notation == "compact" + compactDisplay?: compactDisplay, + // only when style == "unit" + unit: unitSystem, + unitDisplay: unitDisplay, + roundingMode?: rounding, // not available in firefox v110 + roundingPriority?: roundingPriority, // not available in firefox v110 + roundingIncrement?: roundingIncrement, // not available in firefox v110 + // either this group + minimumIntegerDigits?: Core__Intl__Common.oneTo21, + minimumFractionDigits?: Core__Intl__Common.zeroTo20, + maximumFractionDigits?: Core__Intl__Common.zeroTo20, + // OR these + minimumSignificantDigits?: Core__Intl__Common.oneTo21, + maximumSignificantDigits?: Core__Intl__Common.oneTo21, + // always present + locale: string, + notation: notation, + numberingSystem: Core__Intl__Common.numberingSystem, + signDisplay: signDisplay, + style: style, + useGrouping: Grouping.t, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + +type numberFormatPartType = [ + | #compact + | #currency + | #decimal + | #exponentInteger + | #exponentMinusSign + | #exponentSeparator + | #fraction + | #group + | #infinity + | #integer + | #literal + | #minusSign + | #nan + | #plusSign + | #percentSign + | #unit + | #unknown +] + +type numberFormatPart = { + \"type": numberFormatPartType, + value: string, +} + +type rangeSource = [#startRange | #endRange | #shared] + +type numberFormatRangePart = { + \"type": numberFormatPartType, + value: string, + source: rangeSource, +} + @new external make: unit => t = "Intl.NumberFormat" @new external makeWithLocale: string => t = "Intl.NumberFormat" @new external makeWithLocales: array => t = "Intl.NumberFormat" -@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.NumberFormat" -@new external makeWithLocalesAndOptions: (array, {..}) => t = "Intl.NumberFormat" -@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.NumberFormat" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.NumberFormat" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.NumberFormat" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.NumberFormat" @val external supportedLocalesOf: array => t = "Intl.NumberFormat.supportedLocalesOf" +// TODO @val -external supportedLocalesOfWithOptions: (array, {..}) => t = +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.NumberFormat.supportedLocalesOf" -@send external resolvedOptions: t => {..} = "resolvedOptions" +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" @send external format: (t, float) => string = "format" +/** +Not available in firefox v110 +*/ +@send +external formatRange: (t, ~start: float, ~end: float) => array = "formatRange" +@send +external formatToParts: (t, float) => array = "formatToParts" +/** +Not available in firefox v110 +*/ @send -external formatToParts: (t, float) => array<{"type": string, "value": string}> = "formatToParts" +external formatRangeToParts: (t, ~start: float, ~end: float) => array = + "formatRange" @send external formatInt: (t, int) => string = "format" +/** +Not available in firefox v110 +*/ @send -external formatIntToParts: (t, int) => array<{"type": string, "value": string}> = "formatToParts" +external formatIntRange: (t, ~start: int, ~end: int) => array = "formatRange" +@send +external formatIntToParts: (t, int) => array = "formatToParts" +/** +Not available in firefox v110 +*/ +@send +external formatIntRangeToParts: (t, ~start: int, ~end: int) => array = + "formatRange" @send external formatBigInt: (t, Core__BigInt.t) => string = "format" +/** +Not available in firefox v110 +*/ +@send +external formatBigIntRange: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => array = + "formatRange" +@send +external formatBigIntToParts: (t, Core__BigInt.t) => array = "formatToParts" +/** +Not available in firefox v110 +*/ +@send +external formatBigIntRangeToParts: ( + t, + ~start: Core__BigInt.t, + ~end: Core__BigInt.t, +) => array = "formatRange" + +@send external formatString: (t, string) => string = "format" @send -external formatBigIntToParts: (t, Core__BigInt.t) => array<{"type": string, "value": string}> = - "formatToParts" +external formatStringToParts: (t, string) => array = "formatToParts" diff --git a/src/intl/Core__Intl__NumberFormat__Grouping.mjs b/src/intl/Core__Intl__NumberFormat__Grouping.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/intl/Core__Intl__NumberFormat__Grouping.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/intl/Core__Intl__NumberFormat__Grouping.res b/src/intl/Core__Intl__NumberFormat__Grouping.res new file mode 100644 index 00000000..58f45ae1 --- /dev/null +++ b/src/intl/Core__Intl__NumberFormat__Grouping.res @@ -0,0 +1,5 @@ +type t + +external fromBool: bool => t = "%identity" +external fromString: [#always | #auto | #min2] => t = "%identity" +// TODO: unwrap this for consumption coming back in resolvedOptions diff --git a/test/Intl__NumberFormatTest.mjs b/test/Intl__NumberFormatTest.mjs new file mode 100644 index 00000000..b97ac1d5 --- /dev/null +++ b/test/Intl__NumberFormatTest.mjs @@ -0,0 +1,51 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Caml_option from "rescript/lib/es6/caml_option.js"; + +console.info(""); + +console.info("Intl"); + +console.info("---"); + +var currencyFormatter = new Intl.NumberFormat("fr-FR", { + currency: "EUR", + style: "currency" + }); + +console.log(Intl.NumberFormat.supportedLocalesOf([ + "fr-FR", + "en-US" + ])); + +console.log(currencyFormatter.format(123.23)); + +var roundingFormatter = new Intl.NumberFormat(undefined, { + roundingPriority: "lessPrecision", + roundingIncrement: 500 + }); + +var groupingFormatter1 = new Intl.NumberFormat(undefined, { + useGrouping: Caml_option.some(true) + }); + +var groupingFormatter2 = new Intl.NumberFormat(undefined, { + useGrouping: "auto" + }); + +var sigFormatter = new Intl.NumberFormat(undefined, { + minimumIntegerDigits: 1, + minimumFractionDigits: 1, + maximumFractionDigits: 1, + minimumSignificantDigits: 1, + maximumSignificantDigits: 1 + }); + +export { + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , +} +/* Not a pure module */ diff --git a/test/Intl__NumberFormatTest.res b/test/Intl__NumberFormatTest.res new file mode 100644 index 00000000..8c332bb2 --- /dev/null +++ b/test/Intl__NumberFormatTest.res @@ -0,0 +1,32 @@ +open RescriptCore + +Console.info("") +Console.info("Intl") +Console.info("---") +let currencyFormatter = Intl.NumberFormat.makeWithLocaleAndOptions( + "fr-FR", + {currency: "EUR", style: #currency}, +) + +Console.log(Intl.NumberFormat.supportedLocalesOf(["fr-FR", "en-US"])) +Console.log(currencyFormatter->Intl.NumberFormat.format(123.23)) + +let roundingFormatter = Intl.NumberFormat.makeWithOptions({ + roundingPriority: #lessPrecision, + roundingIncrement: #500, +}) + +let groupingFormatter1 = Intl.NumberFormat.makeWithOptions({ + useGrouping: Intl.NumberFormat.Grouping.fromBool(true), +}) +let groupingFormatter2 = Intl.NumberFormat.makeWithOptions({ + useGrouping: Intl.NumberFormat.Grouping.fromString(#auto), +}) + +let sigFormatter = Intl.NumberFormat.makeWithOptions({ + minimumIntegerDigits: #1, + minimumFractionDigits: #1, + maximumFractionDigits: #1, + minimumSignificantDigits: #1, + maximumSignificantDigits: #1, +}) diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 753da260..740eb798 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -93,24 +93,6 @@ console.log(Core__Float.fromString("0.1")); console.info(""); -console.info("Intl"); - -console.info("---"); - -var currencyFormatter = new Intl.NumberFormat("fr-FR", { - currency: "EUR", - style: "currency" - }); - -console.log(Intl.NumberFormat.supportedLocalesOf([ - "fr-FR", - "en-US" - ])); - -console.log(currencyFormatter.format(123.23)); - -console.info(""); - console.info("JSON"); console.info("---"); @@ -335,7 +317,6 @@ export { dict , dict2 , f , - currencyFormatter , json , map , myObject , diff --git a/test/TempTests.res b/test/TempTests.res index 56bdcc40..cf60a18b 100644 --- a/test/TempTests.res +++ b/test/TempTests.res @@ -41,17 +41,6 @@ Console.log(10->Int.toFixedWithPrecision(~digits=2)) Console.log("0"->Int.fromString) Console.log("0.1"->Float.fromString) -Console.info("") -Console.info("Intl") -Console.info("---") -let currencyFormatter = Intl.NumberFormat.makeWithLocaleAndOptions( - "fr-FR", - {"currency": "EUR", "style": "currency"}, -) - -Console.log(Intl.NumberFormat.supportedLocalesOf(["fr-FR", "en-US"])) -Console.log(currencyFormatter->Intl.NumberFormat.format(123.23)) - Console.info("") Console.info("JSON") Console.info("---") From 1b1472cf2769b40cb9d4d9b6bec1d55d0310f071 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 23:19:49 -0500 Subject: [PATCH 03/18] feat: Intl.DateTimeFormat options --- src/intl/Core__Intl__DateTimeFormat.res | 132 +++++++++++++++++++++++- test/Intl__DateTimeFormatTest.mjs | 40 +++++++ test/Intl__DateTimeFormatTest.res | 33 ++++++ test/TempTests.mjs | 6 -- test/TempTests.res | 3 - 5 files changed, 200 insertions(+), 14 deletions(-) create mode 100644 test/Intl__DateTimeFormatTest.mjs create mode 100644 test/Intl__DateTimeFormatTest.res diff --git a/src/intl/Core__Intl__DateTimeFormat.res b/src/intl/Core__Intl__DateTimeFormat.res index 97a5b158..f93a64e5 100644 --- a/src/intl/Core__Intl__DateTimeFormat.res +++ b/src/intl/Core__Intl__DateTimeFormat.res @@ -1,18 +1,140 @@ type t +type dateStyle = [#full | #long | #medium | #short] +type timeStyle = [#full | #long | #medium | #short] +type calendar = [ + | #buddhist + | #chinese + | #coptic + | #dangi + | #ethioaa + | #ethiopic + | #gregory + | #hebrew + | #indian + | #islamic + | #"islamic-umalqura" + | #"islamic-tbla" + | #"islamic-civil" + | #"islamic-rgsa" + | #iso8601 + | #japanese + | #persian + | #roc +] +type dayPeriod = [#narrow | #short | #long] +type weekday = [#narrow | #short | #long] +type era = [#narrow | #short | #long] +type year = [#numeric | #"2-digit"] +type month = [#numeric | #"2-digit" | #narrow | #short | #long] +type day = [#numeric | #"2-digit"] +type hour = [#numeric | #"2-digit"] +type minute = [#numeric | #"2-digit"] +type second = [#numeric | #"2-digit"] +// Firefox also supports IANA time zone names here +type timeZoneName = [ + | #short + | #long +] +// TODO unsupported in node? +// | #shortOffset +// | #shortGeneric +// | #longOffset +// | #longGeneric + +type hourCycle = [#h11 | #h12 | #h23 | #h24] +type formatMatcher = [#basic | @as("best fit") #bestFit] +type fractionalSecondDigits = [#0 | #1 | #2 | #3] + +type options = { + dateStyle?: dateStyle, // can be used with timeStyle, but not other options + timeStyle?: timeStyle, // can be used with dateStyle, but not other options + calendar?: calendar, + dayPeriod?: dayPeriod, // only has an effect if a 12-hour clock is used + numberingSystem?: Core__Intl__Common.numberingSystem, + localeMatcher?: Core__Intl__Common.localeMatcher, + timeZone?: string, + hour12?: bool, + hourCycle?: hourCycle, + formatMatcher?: formatMatcher, + // date-time components + weekday?: weekday, + era?: era, + year?: year, + month?: month, + day?: day, + hour?: hour, + minute?: minute, + second?: second, + fractionalSecondDigits?: fractionalSecondDigits, + timeZoneName?: timeZoneName, +} + +type resolvedOptions = { + dateStyle?: dateStyle, + timeStyle?: timeStyle, + weekday?: weekday, + era?: era, + year?: year, + month?: month, + day?: day, + hour?: hour, + minute?: minute, + second?: second, + fractionalSecondDigits?: fractionalSecondDigits, + timeZoneName?: timeZoneName, + calendar: calendar, + hour12: bool, + hourCycle: hourCycle, + locale: string, + numberingSystem: Core__Intl__Common.numberingSystem, + timeZone: string, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + +type dateTimeComponent = [ + | #day + | #dayPeriod + | #era + | #fractionalSecond + | #hour + | #literal + | #minute + | #month + | #relatedYear + | #second + | #timeZone + | #weekday + | #year + | #yearName +] + +type dateTimePart = { + \"type": dateTimeComponent, + value: string, +} + +type dateTimeRangeSource = [#startRange | #shared | #endRange] +type dateTimeRangePart = { + \"type": dateTimeComponent, + value: string, + source: dateTimeRangeSource, +} + @new external make: unit => t = "Intl.DateTimeFormat" @new external makeWithLocale: string => t = "Intl.DateTimeFormat" @new external makeWithLocales: array => t = "Intl.DateTimeFormat" -@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.DateTimeFormat" -@new external makeWithLocalesAndOptions: (array, {..}) => t = "Intl.DateTimeFormat" -@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.DateTimeFormat" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.DateTimeFormat" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.DateTimeFormat" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.DateTimeFormat" @val external supportedLocalesOf: array => t = "Intl.DateTimeFormat.supportedLocalesOf" @val -external supportedLocalesOfWithOptions: (array, {..}) => t = +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.DateTimeFormat.supportedLocalesOf" -@send external resolvedOptions: t => {..} = "resolvedOptions" +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" @send external format: (t, Core__Date.t) => string = "format" @send diff --git a/test/Intl__DateTimeFormatTest.mjs b/test/Intl__DateTimeFormatTest.mjs new file mode 100644 index 00000000..6f1833a5 --- /dev/null +++ b/test/Intl__DateTimeFormatTest.mjs @@ -0,0 +1,40 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +var formatter = new Intl.DateTimeFormat(undefined, { + dateStyle: "full", + timeStyle: "full" + }); + +console.log(formatter.format(new Date(Date.now()))); + +console.log(formatter.formatRange(new Date(2023, 1, 1), new Date(2023, 12, 31))); + +var formatter$1 = new Intl.DateTimeFormat(undefined, { + timeZone: "UTC", + hour12: false, + hourCycle: "h24", + weekday: "narrow", + era: "narrow", + year: "2-digit", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + fractionalSecondDigits: 3, + timeZoneName: "short" + }); + +console.log(formatter$1.format(new Date(Date.now()))); + +var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); + +var timeZone = resolvedOptions.timeZone; + +export { + formatter$1 as formatter, + resolvedOptions , + timeZone , +} +/* formatter Not a pure module */ diff --git a/test/Intl__DateTimeFormatTest.res b/test/Intl__DateTimeFormatTest.res new file mode 100644 index 00000000..0b283236 --- /dev/null +++ b/test/Intl__DateTimeFormatTest.res @@ -0,0 +1,33 @@ +open RescriptCore + +let formatter = Intl.DateTimeFormat.makeWithOptions({dateStyle: #full, timeStyle: #full}) + +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +Console.log( + formatter->Intl.DateTimeFormat.formatRange( + ~startDate=Date.makeWithYMD(~year=2023, ~date=1, ~month=1), + ~endDate=Date.makeWithYMD(~year=2023, ~date=31, ~month=12), + ), +) + +let formatter = Intl.DateTimeFormat.makeWithOptions({ + hour12: false, + hourCycle: #h24, + timeZone: "UTC", + weekday: #narrow, + era: #narrow, + year: #"2-digit", + month: #"2-digit", + day: #"2-digit", + hour: #"2-digit", + minute: #"2-digit", + second: #"2-digit", + fractionalSecondDigits: #3, + timeZoneName: #short, +}) + +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions +let {Intl.DateTimeFormat.timeZone: timeZone, _} = resolvedOptions diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 740eb798..8d79517a 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -288,10 +288,6 @@ if (globalThis.hello !== undefined) { console.log("hello"); } -var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); - -var timeZone = resolvedOptions.timeZone; - var z = 1.2 % 1.4; var intFromBigInt = Core__BigInt.toInt(BigInt("10000000000")); @@ -331,8 +327,6 @@ export { x , array$1 as array, timeout , - resolvedOptions , - timeZone , z , intFromBigInt , Bugfix , diff --git a/test/TempTests.res b/test/TempTests.res index cf60a18b..1792ab40 100644 --- a/test/TempTests.res +++ b/test/TempTests.res @@ -180,9 +180,6 @@ if globalThis["hello"] !== undefined { Console.log("hello") } -let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions -let timeZone = resolvedOptions["timeZone"] - let z = Float.mod(1.2, 1.4) let intFromBigInt = BigInt.fromString("10000000000")->BigInt.toInt From f80e027afa0e421f844d0d10e5843da228d010de Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 23:28:41 -0500 Subject: [PATCH 04/18] feat: Intl.Collator --- src/intl/Core__Intl__Collator.res | 54 ++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/intl/Core__Intl__Collator.res b/src/intl/Core__Intl__Collator.res index dce5716c..ee3191a1 100644 --- a/src/intl/Core__Intl__Collator.res +++ b/src/intl/Core__Intl__Collator.res @@ -1,17 +1,61 @@ type t +type usage = [#sort | #search] +type sensitivity = [#base | #accent | #case | #variant] +type caseFirst = [#upper | #lower | #"false"] +type collation = [ + | #big5han // (Chinese; do not use; not available in Firefox, Chrome or Edge) + | #compat // (Arabic) + | #dict // (Sinhala) + | #direct // (deprecated, do not use) + | #ducet // (not available, do not use) + | #emoji // (root) + | #eor // (root) + | #gb2312 // (Chinese; do not use; not available in Chrome or Edge) + | #phonebk // (German) + | #phonetic // (Lingala) + | #pinyin // (Chinese) + | #reformed // (formerly Swedish; do not specify explicitly as this was the old name for the default for Swedish) + | #searchjl // (Korean; do not use as this is for searching rather than sorting, and the API covers only sorting) + | #stroke // (Chinese) + | #trad + | #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge) + | #zhuyin +] // (Chinese) + +type options = { + localeMatcher?: Core__Intl__Common.localeMatcher, + usage?: usage, + sensitivity?: sensitivity, + ignorePunctuation?: bool, + numeric?: bool, + caseFirst?: caseFirst, +} + +type resolvedOptions = { + locale: string, + usage: usage, + sensitivity: sensitivity, + ignorePunctuation: bool, + collation: [collation | #default], + numeric?: bool, + caseFirst?: caseFirst, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + @new external make: unit => t = "Intl.Collator" @new external makeWithLocale: string => t = "Intl.Collator" @new external makeWithLocales: array => t = "Intl.Collator" -@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.Collator" -@new external makeWithLocalesAndOptions: (array, {..}) => t = "Intl.Collator" -@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.Collator" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.Collator" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.Collator" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Collator" @val external supportedLocalesOf: array => t = "Intl.Collator.supportedLocalesOf" @val -external supportedLocalesOfWithOptions: (array, {..}) => t = +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.Collator.supportedLocalesOf" -@send external resolvedOptions: t => {..} = "resolvedOptions" +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" @send external compare: (t, string, string) => int = "compare" From 5b20ca3d38a67435e745fe5b8e925c5261e36f16 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 23:28:54 -0500 Subject: [PATCH 05/18] feat: Intl.ListFormat --- src/intl/Core__Intl__ListFormat.mjs | 2 ++ src/intl/Core__Intl__ListFormat.res | 53 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/intl/Core__Intl__ListFormat.mjs create mode 100644 src/intl/Core__Intl__ListFormat.res diff --git a/src/intl/Core__Intl__ListFormat.mjs b/src/intl/Core__Intl__ListFormat.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/intl/Core__Intl__ListFormat.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/intl/Core__Intl__ListFormat.res b/src/intl/Core__Intl__ListFormat.res new file mode 100644 index 00000000..43a6174a --- /dev/null +++ b/src/intl/Core__Intl__ListFormat.res @@ -0,0 +1,53 @@ +type t + +type listType = [ + | #conjunction + | #disjunction + | #unit +] +type style = [ + | #long + | #short + | #narrow +] + +type options = { + localeMatcher?: Core__Intl__Common.localeMatcher, + \"type"?: listType, + style?: style, +} + +type listPartComponentType = [ + | #element + | #literal +] + +type listPart = { + \"type": listPartComponentType, + value: string, +} + +type resolvedOptions = { + locale: string, + style: style, + \"type": listType, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + +@new external make: unit => t = "Intl.ListFormat" +@new external makeWithLocale: string => t = "Intl.ListFormat" +@new external makeWithLocales: array => t = "Intl.ListFormat" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.ListFormat" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.ListFormat" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.ListFormat" + +@val external supportedLocalesOf: array => t = "Intl.ListFormat.supportedLocalesOf" +@val +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = + "Intl.ListFormat.supportedLocalesOf" + +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" + +@send external format: (t, array) => string = "format" +@send external formatToParts: (t, array) => array = "formatToParts" From 9ef5767efb23de75fcd2f175d66754d95a1d4ee3 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 21 Feb 2023 23:53:55 -0500 Subject: [PATCH 06/18] feat: Intl.RelativeTimeFormat --- src/intl/Core__Intl__RelativeTimeFormat.res | 48 ++++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/intl/Core__Intl__RelativeTimeFormat.res b/src/intl/Core__Intl__RelativeTimeFormat.res index 8a561977..8cbf2138 100644 --- a/src/intl/Core__Intl__RelativeTimeFormat.res +++ b/src/intl/Core__Intl__RelativeTimeFormat.res @@ -1,30 +1,46 @@ type t +type numeric = [#always | #auto] +type style = [#long | #short | #narrow] +type timeUnit = [#year | #quarter | #month | #week | #day | #hour | #minute | #second] + +type options = { + localeMatcher?: Core__Intl__Common.localeMatcher, + numeric?: numeric, + style?: style, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + +type resolvedOptions = { + locale: string, + numeric: numeric, + style: style, + numberingSystem: string, +} + +type relativeTimePartComponent = [#literal | #integer] +type relativeTimePart = { + \"type": relativeTimePartComponent, + value: string, + unit?: timeUnit, +} + @new external make: unit => t = "Intl.RelativeTimeFormat" @new external makeWithLocale: string => t = "Intl.RelativeTimeFormat" @new external makeWithLocales: array => t = "Intl.RelativeTimeFormat" -@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.RelativeTimeFormat" -@new external makeWithLocalesAndOptions: (array, {..}) => t = "Intl.RelativeTimeFormat" -@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.RelativeTimeFormat" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.RelativeTimeFormat" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.RelativeTimeFormat" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.RelativeTimeFormat" @val external supportedLocalesOf: array => t = "Intl.RelativeTimeFormat.supportedLocalesOf" @val -external supportedLocalesOfWithOptions: (array, {..}) => t = +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.RelativeTimeFormat.supportedLocalesOf" -@send external resolvedOptions: t => {..} = "resolvedOptions" - -type timeUnit = [#year | #quarter | #month | #week | #day | #hour | #minute | #second] +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" @send external format: (t, int, timeUnit) => string = "format" @send -external formatToParts: ( - t, - int, - timeUnit, -) => array<{ - "type": string, - "value": string, - "unit": option, -}> = "formatToParts" +external formatToParts: (t, int, timeUnit) => array = "formatToParts" From be3375a7ecd13707afd19ce5dfcb518c0dff4277 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 22 Feb 2023 00:01:58 -0500 Subject: [PATCH 07/18] feat: Intl.Segmenter --- src/intl/Core__Intl__Segmenter.mjs | 2 ++ src/intl/Core__Intl__Segmenter.res | 40 ++++++++++++++++++++++++++++++ src/intl/Core__Intl__Segments.mjs | 2 ++ src/intl/Core__Intl__Segments.res | 18 ++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 src/intl/Core__Intl__Segmenter.mjs create mode 100644 src/intl/Core__Intl__Segmenter.res create mode 100644 src/intl/Core__Intl__Segments.mjs create mode 100644 src/intl/Core__Intl__Segments.res diff --git a/src/intl/Core__Intl__Segmenter.mjs b/src/intl/Core__Intl__Segmenter.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/intl/Core__Intl__Segmenter.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/intl/Core__Intl__Segmenter.res b/src/intl/Core__Intl__Segmenter.res new file mode 100644 index 00000000..c6def395 --- /dev/null +++ b/src/intl/Core__Intl__Segmenter.res @@ -0,0 +1,40 @@ +/*** +Not supported in Firefox +*/ +type t + +type granularity = [#grapheme | #word | #sentence] + +type options = { + localeMatcher?: Core__Intl__Common.localeMatcher, + granularity?: granularity, +} + +type pluralCategories = [ + | #zero + | #one + | #two + | #few + | #many + | #other +] + +type resolvedOptions = {locale: string, granularity: granularity} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + +@new external make: unit => t = "Intl.Segmenter" +@new external makeWithLocale: string => t = "Intl.Segmenter" +@new external makeWithLocales: array => t = "Intl.Segmenter" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.Segmenter" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.Segmenter" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Segmenter" + +@val external supportedLocalesOf: array => t = "Intl.Segmenter.supportedLocalesOf" +@val +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = + "Intl.Segmenter.supportedLocalesOf" + +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" + +@send external segment: (t, string) => Core__Intl__Segments.t = "segment" diff --git a/src/intl/Core__Intl__Segments.mjs b/src/intl/Core__Intl__Segments.mjs new file mode 100644 index 00000000..d856702b --- /dev/null +++ b/src/intl/Core__Intl__Segments.mjs @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/intl/Core__Intl__Segments.res b/src/intl/Core__Intl__Segments.res new file mode 100644 index 00000000..7183f456 --- /dev/null +++ b/src/intl/Core__Intl__Segments.res @@ -0,0 +1,18 @@ +/*** + A Segments instance is an object that represents the segments of a specific string, subject to the locale and options of its constructing Intl.Segmenter instance. +https://tc39.es/ecma402/#sec-segments-objects +*/ +type t + +type segmentData = { + segment: string, + index: int, + isWordLike: option, + input: string, +} + +@send +external containing: unit => segmentData = "containing" + +@send +external containingWithIndex: int => segmentData = "containing" From b5a4bd2a0d31f7aa136768ffa949002038dc1579 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 22 Feb 2023 00:18:14 -0500 Subject: [PATCH 08/18] feat: Intl.Locale --- src/intl/Core__Intl__Locale.res | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/intl/Core__Intl__Locale.res b/src/intl/Core__Intl__Locale.res index b2ecec9b..2cae1746 100644 --- a/src/intl/Core__Intl__Locale.res +++ b/src/intl/Core__Intl__Locale.res @@ -1,7 +1,20 @@ type t +type options = { + baseName?: string, + calendar?: string, // TODO: probably the same as Core__Intl__DateTimeFormat.calendar? + collation?: string, // TODO: probably the same as Core__Intl__Collator.collation? + hourCycle?: [#h11 | #h12 | #h23 | #h24], + caseFirst?: [#upper | #lower | #"false"], + numberingSystem?: Core__Intl__Common.numberingSystem, + numeric?: bool, + language?: string, + script?: string, + region?: string, +} + @new external make: string => t = "Intl.Locale" -@new external makeWithOptions: (string, {..}) => t = "Intl.Locale" +@new external makeWithOptions: (string, options) => t = "Intl.Locale" @get external baseName: t => string = "baseName" @get external calendar: t => option = "calendar" From a651f7862e2f7a45021b980aab1edc577c872387 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 1 Mar 2023 20:27:50 -0500 Subject: [PATCH 09/18] feat: Intl.getCanonicalLocales & supportedValuesOf --- src/Core__Intl.res | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Core__Intl.res b/src/Core__Intl.res index 90f0015d..08e8e47c 100644 --- a/src/Core__Intl.res +++ b/src/Core__Intl.res @@ -4,3 +4,18 @@ module Locale = Core__Intl__Locale module NumberFormat = Core__Intl__NumberFormat module PluralRules = Core__Intl__PluralRules module RelativeTimeFormat = Core__Intl__RelativeTimeFormat + +/** +@throws RangeError +*/ +external getCanonicalLocalesExn: string => array = "Intl.getCanonicalLocales" + +/** +@throws RangeError +*/ +external getCanonicalLocalesManyExn: array => array = "Intl.getCanonicalLocales" + +/** +@throws RangeError +*/ +external supportedValuesOfExn: string => array = "Intl.supportedValuesOf" From 51ad73d8e0c4ae3e65609dc160dc614b7b51f95b Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 1 Mar 2023 23:24:26 -0500 Subject: [PATCH 10/18] feat: tests --- src/Core__Intl.mjs | 9 ++ src/Core__Intl.res | 3 + src/intl/Core__Intl__Collator.res | 21 +--- src/intl/Core__Intl__Common.res | 35 +++++++ src/intl/Core__Intl__DateTimeFormat.res | 24 +---- src/intl/Core__Intl__Locale.res | 4 +- src/intl/Core__Intl__Segments.res | 4 +- test/Intl/IntlTests.mjs | 102 +++++++++++++++++++ test/Intl/IntlTests.res | 42 ++++++++ test/Intl/Intl__CollatorTest.mjs | 45 ++++++++ test/Intl/Intl__CollatorTest.res | 18 ++++ test/{ => Intl}/Intl__DateTimeFormatTest.mjs | 18 +++- test/{ => Intl}/Intl__DateTimeFormatTest.res | 9 ++ test/Intl/Intl__ListFormatTest.mjs | 64 ++++++++++++ test/Intl/Intl__ListFormatTest.res | 24 +++++ test/Intl/Intl__LocaleTest.mjs | 45 ++++++++ test/Intl/Intl__LocaleTest.res | 29 ++++++ test/{ => Intl}/Intl__NumberFormatTest.mjs | 6 +- test/{ => Intl}/Intl__NumberFormatTest.res | 6 +- test/Intl/Intl__PluralRulesTest.mjs | 44 ++++++++ test/Intl/Intl__PluralRulesTest.res | 42 ++++++++ test/Intl/Intl__RelativeTimeFormatTest.mjs | 53 ++++++++++ test/Intl/Intl__RelativeTimeFormatTest.res | 37 +++++++ test/Intl/Intl__SegmenterTest.mjs | 55 ++++++++++ test/Intl/Intl__SegmenterTest.res | 34 +++++++ test/TempTests.mjs | 34 +++++++ test/TempTests.res | 2 + 27 files changed, 755 insertions(+), 54 deletions(-) create mode 100644 test/Intl/IntlTests.mjs create mode 100644 test/Intl/IntlTests.res create mode 100644 test/Intl/Intl__CollatorTest.mjs create mode 100644 test/Intl/Intl__CollatorTest.res rename test/{ => Intl}/Intl__DateTimeFormatTest.mjs (76%) rename test/{ => Intl}/Intl__DateTimeFormatTest.res (80%) create mode 100644 test/Intl/Intl__ListFormatTest.mjs create mode 100644 test/Intl/Intl__ListFormatTest.res create mode 100644 test/Intl/Intl__LocaleTest.mjs create mode 100644 test/Intl/Intl__LocaleTest.res rename test/{ => Intl}/Intl__NumberFormatTest.mjs (94%) rename test/{ => Intl}/Intl__NumberFormatTest.res (93%) create mode 100644 test/Intl/Intl__PluralRulesTest.mjs create mode 100644 test/Intl/Intl__PluralRulesTest.res create mode 100644 test/Intl/Intl__RelativeTimeFormatTest.mjs create mode 100644 test/Intl/Intl__RelativeTimeFormatTest.res create mode 100644 test/Intl/Intl__SegmenterTest.mjs create mode 100644 test/Intl/Intl__SegmenterTest.res diff --git a/src/Core__Intl.mjs b/src/Core__Intl.mjs index ffed57db..0d8e8a98 100644 --- a/src/Core__Intl.mjs +++ b/src/Core__Intl.mjs @@ -5,6 +5,8 @@ var Collator; var DateTimeFormat; +var ListFormat; + var Locale; var NumberFormat; @@ -13,12 +15,19 @@ var PluralRules; var RelativeTimeFormat; +var Segmenter; + +var Segments; + export { Collator , DateTimeFormat , + ListFormat , Locale , NumberFormat , PluralRules , RelativeTimeFormat , + Segmenter , + Segments , } /* No side effect */ diff --git a/src/Core__Intl.res b/src/Core__Intl.res index 08e8e47c..822b4a4f 100644 --- a/src/Core__Intl.res +++ b/src/Core__Intl.res @@ -1,9 +1,12 @@ module Collator = Core__Intl__Collator module DateTimeFormat = Core__Intl__DateTimeFormat +module ListFormat = Core__Intl__ListFormat module Locale = Core__Intl__Locale module NumberFormat = Core__Intl__NumberFormat module PluralRules = Core__Intl__PluralRules module RelativeTimeFormat = Core__Intl__RelativeTimeFormat +module Segmenter = Core__Intl__Segmenter +module Segments = Core__Intl__Segments /** @throws RangeError diff --git a/src/intl/Core__Intl__Collator.res b/src/intl/Core__Intl__Collator.res index ee3191a1..300b8766 100644 --- a/src/intl/Core__Intl__Collator.res +++ b/src/intl/Core__Intl__Collator.res @@ -3,25 +3,6 @@ type t type usage = [#sort | #search] type sensitivity = [#base | #accent | #case | #variant] type caseFirst = [#upper | #lower | #"false"] -type collation = [ - | #big5han // (Chinese; do not use; not available in Firefox, Chrome or Edge) - | #compat // (Arabic) - | #dict // (Sinhala) - | #direct // (deprecated, do not use) - | #ducet // (not available, do not use) - | #emoji // (root) - | #eor // (root) - | #gb2312 // (Chinese; do not use; not available in Chrome or Edge) - | #phonebk // (German) - | #phonetic // (Lingala) - | #pinyin // (Chinese) - | #reformed // (formerly Swedish; do not specify explicitly as this was the old name for the default for Swedish) - | #searchjl // (Korean; do not use as this is for searching rather than sorting, and the API covers only sorting) - | #stroke // (Chinese) - | #trad - | #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge) - | #zhuyin -] // (Chinese) type options = { localeMatcher?: Core__Intl__Common.localeMatcher, @@ -37,7 +18,7 @@ type resolvedOptions = { usage: usage, sensitivity: sensitivity, ignorePunctuation: bool, - collation: [collation | #default], + collation: [Core__Intl__Common.collation | #default], numeric?: bool, caseFirst?: caseFirst, } diff --git a/src/intl/Core__Intl__Common.res b/src/intl/Core__Intl__Common.res index f6c4165a..e0cea141 100644 --- a/src/intl/Core__Intl__Common.res +++ b/src/intl/Core__Intl__Common.res @@ -1,5 +1,40 @@ type localeMatcher = [#lookup | @as("best fit") #bestFit] +type calendar = [ + | #buddhist + | #chinese + | #coptic + | #dangi + | #ethioaa + | #ethiopic + | #gregory + | #hebrew + | #indian + | #islamic + | #"islamic-umalqura" + | #"islamic-tbla" + | #"islamic-civil" + | #"islamic-rgsa" + | #iso8601 + | #japanese + | #persian + | #roc +] + +type collation = [ + | #compat // (Arabic) + | #dict // (Sinhala) + | #emoji // (root) + | #eor // (root) + | #phonebk // (German) + | #phonetic // (Lingala) + | #pinyin // (Chinese) + | #stroke // (Chinese) + | #trad + | #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge) + | #zhuyin +] // (Chinese) + type numberingSystem = [ | #adlm | #ahom diff --git a/src/intl/Core__Intl__DateTimeFormat.res b/src/intl/Core__Intl__DateTimeFormat.res index f93a64e5..5cc63424 100644 --- a/src/intl/Core__Intl__DateTimeFormat.res +++ b/src/intl/Core__Intl__DateTimeFormat.res @@ -2,26 +2,6 @@ type t type dateStyle = [#full | #long | #medium | #short] type timeStyle = [#full | #long | #medium | #short] -type calendar = [ - | #buddhist - | #chinese - | #coptic - | #dangi - | #ethioaa - | #ethiopic - | #gregory - | #hebrew - | #indian - | #islamic - | #"islamic-umalqura" - | #"islamic-tbla" - | #"islamic-civil" - | #"islamic-rgsa" - | #iso8601 - | #japanese - | #persian - | #roc -] type dayPeriod = [#narrow | #short | #long] type weekday = [#narrow | #short | #long] type era = [#narrow | #short | #long] @@ -49,7 +29,7 @@ type fractionalSecondDigits = [#0 | #1 | #2 | #3] type options = { dateStyle?: dateStyle, // can be used with timeStyle, but not other options timeStyle?: timeStyle, // can be used with dateStyle, but not other options - calendar?: calendar, + calendar?: Core__Intl__Common.calendar, dayPeriod?: dayPeriod, // only has an effect if a 12-hour clock is used numberingSystem?: Core__Intl__Common.numberingSystem, localeMatcher?: Core__Intl__Common.localeMatcher, @@ -83,7 +63,7 @@ type resolvedOptions = { second?: second, fractionalSecondDigits?: fractionalSecondDigits, timeZoneName?: timeZoneName, - calendar: calendar, + calendar: Core__Intl__Common.calendar, hour12: bool, hourCycle: hourCycle, locale: string, diff --git a/src/intl/Core__Intl__Locale.res b/src/intl/Core__Intl__Locale.res index 2cae1746..5d6afb47 100644 --- a/src/intl/Core__Intl__Locale.res +++ b/src/intl/Core__Intl__Locale.res @@ -2,8 +2,8 @@ type t type options = { baseName?: string, - calendar?: string, // TODO: probably the same as Core__Intl__DateTimeFormat.calendar? - collation?: string, // TODO: probably the same as Core__Intl__Collator.collation? + calendar?: Core__Intl__Common.calendar, + collation?: Core__Intl__Common.collation, hourCycle?: [#h11 | #h12 | #h23 | #h24], caseFirst?: [#upper | #lower | #"false"], numberingSystem?: Core__Intl__Common.numberingSystem, diff --git a/src/intl/Core__Intl__Segments.res b/src/intl/Core__Intl__Segments.res index 7183f456..33b06ea1 100644 --- a/src/intl/Core__Intl__Segments.res +++ b/src/intl/Core__Intl__Segments.res @@ -12,7 +12,7 @@ type segmentData = { } @send -external containing: unit => segmentData = "containing" +external containing: t => segmentData = "containing" @send -external containingWithIndex: int => segmentData = "containing" +external containingWithIndex: (t, int) => segmentData = "containing" diff --git a/test/Intl/IntlTests.mjs b/test/Intl/IntlTests.mjs new file mode 100644 index 00000000..e6abdbc4 --- /dev/null +++ b/test/Intl/IntlTests.mjs @@ -0,0 +1,102 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs"; +import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; +import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs"; +import * as Intl__SegmenterTest from "./Intl__SegmenterTest.mjs"; +import * as Intl__ListFormatTest from "./Intl__ListFormatTest.mjs"; +import * as Intl__PluralRulesTest from "./Intl__PluralRulesTest.mjs"; +import * as Intl__NumberFormatTest from "./Intl__NumberFormatTest.mjs"; +import * as Intl__DateTimeFormatTest from "./Intl__DateTimeFormatTest.mjs"; +import * as Intl__RelativeTimeFormatTest from "./Intl__RelativeTimeFormatTest.mjs"; + +console.log("---"); + +console.log("Intl"); + +console.log(Intl.getCanonicalLocales("EN-US")); + +console.log(Intl.getCanonicalLocales([ + "EN-US", + "Fr" + ])); + +try { + console.log(Intl.getCanonicalLocales("bloop")); +} +catch (raw_e){ + var e = Caml_js_exceptions.internalToOCamlException(raw_e); + if (e.RE_EXN_ID === Js_exn.$$Error) { + console.error(e._1); + } else { + throw e; + } +} + +try { + console.log(Intl.supportedValuesOf("calendar")); + console.log(Intl.supportedValuesOf("collation")); + console.log(Intl.supportedValuesOf("currency")); + console.log(Intl.supportedValuesOf("numberingSystem")); + console.log(Intl.supportedValuesOf("timeZone")); + console.log(Intl.supportedValuesOf("unit")); +} +catch (raw_e$1){ + var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$1); + if (e$1.RE_EXN_ID === Js_exn.$$Error) { + console.error(e$1._1); + } else { + throw e$1; + } +} + +try { + Intl.supportedValuesOf("someInvalidKey"); + console.error("Shouldn't have been hit"); +} +catch (raw_e$2){ + var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2); + if (e$2.RE_EXN_ID === Js_exn.$$Error) { + console.error(e$2._1); + } else { + throw e$2; + } +} + +var collator = Intl__CollatorTest.collator; + +var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions; + +var timeZone = Intl__DateTimeFormatTest.timeZone; + +var locale = Intl__LocaleTest.locale; + +var currencyFormatter = Intl__NumberFormatTest.currencyFormatter; + +var roundingFormatter = Intl__NumberFormatTest.roundingFormatter; + +var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1; + +var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2; + +var sigFormatter = Intl__NumberFormatTest.sigFormatter; + +var formatter = Intl__SegmenterTest.formatter; + +var segments = Intl__SegmenterTest.segments; + +export { + collator , + resolvedOptions , + timeZone , + locale , + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , + formatter , + segments , +} +/* Not a pure module */ diff --git a/test/Intl/IntlTests.res b/test/Intl/IntlTests.res new file mode 100644 index 00000000..44afcde6 --- /dev/null +++ b/test/Intl/IntlTests.res @@ -0,0 +1,42 @@ +include Intl__CollatorTest +include Intl__DateTimeFormatTest +include Intl__ListFormatTest +include Intl__LocaleTest +include Intl__NumberFormatTest +include Intl__PluralRulesTest +include Intl__RelativeTimeFormatTest +include Intl__SegmenterTest + +open RescriptCore + +Console.log("---") +Console.log("Intl") + +Intl.getCanonicalLocalesExn("EN-US")->Console.log +Intl.getCanonicalLocalesManyExn(["EN-US", "Fr"])->Console.log + +try { + Intl.getCanonicalLocalesExn("bloop")->Console.log +} catch { +| Exn.Error(e) => Console.error(e) +} + +try { + Intl.supportedValuesOfExn("calendar")->Console.log + Intl.supportedValuesOfExn("collation")->Console.log + Intl.supportedValuesOfExn("currency")->Console.log + Intl.supportedValuesOfExn("numberingSystem")->Console.log + Intl.supportedValuesOfExn("timeZone")->Console.log + Intl.supportedValuesOfExn("unit")->Console.log +} catch { +| Exn.Error(e) => Console.error(e) +} + +try { + Intl.supportedValuesOfExn("someInvalidKey")->ignore + + Console.error("Shouldn't have been hit") +} catch { +| Exn.Error(e) => Console.error(e) +// Expected output: RangeError: invalid key: "someInvalidKey" +} diff --git a/test/Intl/Intl__CollatorTest.mjs b/test/Intl/Intl__CollatorTest.mjs new file mode 100644 index 00000000..1628b3f4 --- /dev/null +++ b/test/Intl/Intl__CollatorTest.mjs @@ -0,0 +1,45 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Collator"); + +new Intl.Collator(); + +new Intl.Collator("en-US"); + +new Intl.Collator([ + "en-US", + "en-GB" + ]); + +var collator = new Intl.Collator("en-US", { + sensitivity: "base", + ignorePunctuation: true, + numeric: true, + caseFirst: "upper" + }); + +Intl.Collator.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.Collator.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +console.log(collator.resolvedOptions()); + +console.log(collator.compare("hi", "hï")); + +console.log(Intl.Collator.supportedLocalesOf(["hi"])); + +export { + collator , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__CollatorTest.res b/test/Intl/Intl__CollatorTest.res new file mode 100644 index 00000000..f339e1d1 --- /dev/null +++ b/test/Intl/Intl__CollatorTest.res @@ -0,0 +1,18 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Collator") + +let collator = Intl.Collator.make() +let collator = Intl.Collator.makeWithLocale("en-US") +let collator = Intl.Collator.makeWithLocales(["en-US", "en-GB"]) +let collator = Intl.Collator.makeWithLocaleAndOptions( + "en-US", + {caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true}, +) +Intl.Collator.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.Collator.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore + +collator->Intl.Collator.resolvedOptions->Console.log +collator->Intl.Collator.compare("hi", "hï")->Console.log +Intl.Collator.supportedLocalesOf(["hi"])->Console.log diff --git a/test/Intl__DateTimeFormatTest.mjs b/test/Intl/Intl__DateTimeFormatTest.mjs similarity index 76% rename from test/Intl__DateTimeFormatTest.mjs rename to test/Intl/Intl__DateTimeFormatTest.mjs index 6f1833a5..566cb9fc 100644 --- a/test/Intl__DateTimeFormatTest.mjs +++ b/test/Intl/Intl__DateTimeFormatTest.mjs @@ -1,6 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +console.log("---"); + +console.log("Intl.DateTimeFormat"); + +Intl.DateTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.DateTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + var formatter = new Intl.DateTimeFormat(undefined, { dateStyle: "full", timeStyle: "full" @@ -37,4 +53,4 @@ export { resolvedOptions , timeZone , } -/* formatter Not a pure module */ +/* Not a pure module */ diff --git a/test/Intl__DateTimeFormatTest.res b/test/Intl/Intl__DateTimeFormatTest.res similarity index 80% rename from test/Intl__DateTimeFormatTest.res rename to test/Intl/Intl__DateTimeFormatTest.res index 0b283236..4dba8c5e 100644 --- a/test/Intl__DateTimeFormatTest.res +++ b/test/Intl/Intl__DateTimeFormatTest.res @@ -1,5 +1,14 @@ open RescriptCore +Console.log("---") +Console.log("Intl.DateTimeFormat") + +Intl.DateTimeFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.DateTimeFormat.supportedLocalesOfWithOptions( + ["en-US", "en-GB"], + {localeMatcher: #lookup}, +)->ignore + let formatter = Intl.DateTimeFormat.makeWithOptions({dateStyle: #full, timeStyle: #full}) Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) diff --git a/test/Intl/Intl__ListFormatTest.mjs b/test/Intl/Intl__ListFormatTest.mjs new file mode 100644 index 00000000..4e763403 --- /dev/null +++ b/test/Intl/Intl__ListFormatTest.mjs @@ -0,0 +1,64 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.ListFormat"); + +new Intl.ListFormat(); + +new Intl.ListFormat("en-US"); + +new Intl.ListFormat([ + "en-US", + "en-GB" + ]); + +new Intl.ListFormat("en-US", { + type: "conjunction", + style: "long" + }); + +new Intl.ListFormat([ + "en-US", + "en-GB" + ], { + type: "conjunction", + style: "long" + }); + +Intl.ListFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.ListFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +var formatter = new Intl.ListFormat(undefined, { + type: "conjunction", + style: "long" + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.format([ + "one", + "two", + "three" + ])); + +console.log(formatter.formatToParts([ + "one", + "two", + "three" + ])); + +export { + formatter , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__ListFormatTest.res b/test/Intl/Intl__ListFormatTest.res new file mode 100644 index 00000000..b2ed3cf4 --- /dev/null +++ b/test/Intl/Intl__ListFormatTest.res @@ -0,0 +1,24 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.ListFormat") + +let formatter = Intl.ListFormat.make() +let formatter = Intl.ListFormat.makeWithLocale("en-US") +let formatter = Intl.ListFormat.makeWithLocales(["en-US", "en-GB"]) +let formatter = Intl.ListFormat.makeWithLocaleAndOptions( + "en-US", + {style: #long, \"type": #conjunction}, +) +let formatter = Intl.ListFormat.makeWithLocalesAndOptions( + ["en-US", "en-GB"], + {style: #long, \"type": #conjunction}, +) +Intl.ListFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.ListFormat.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore + +let formatter = Intl.ListFormat.makeWithOptions({style: #long, \"type": #conjunction}) + +formatter->Intl.ListFormat.resolvedOptions->Console.log +formatter->Intl.ListFormat.format(["one", "two", "three"])->Console.log +formatter->Intl.ListFormat.formatToParts(["one", "two", "three"])->Console.log diff --git a/test/Intl/Intl__LocaleTest.mjs b/test/Intl/Intl__LocaleTest.mjs new file mode 100644 index 00000000..eb1df8d1 --- /dev/null +++ b/test/Intl/Intl__LocaleTest.mjs @@ -0,0 +1,45 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Locale"); + +new Intl.Locale("en-US"); + +var locale = new Intl.Locale("en-US", { + calendar: "hebrew", + collation: "compat", + hourCycle: "h24", + caseFirst: "upper", + numeric: true + }); + +console.log(locale.baseName); + +console.log(locale.calendar); + +console.log(locale.caseFirst); + +console.log(locale.collation); + +console.log(locale.hourCycle); + +console.log(locale.language); + +console.log(locale.numberingSystem); + +console.log(locale.numeric); + +console.log(locale.region); + +console.log(locale.script); + +console.log(locale.maximize()); + +console.log(locale.minimize()); + +export { + locale , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__LocaleTest.res b/test/Intl/Intl__LocaleTest.res new file mode 100644 index 00000000..5938e192 --- /dev/null +++ b/test/Intl/Intl__LocaleTest.res @@ -0,0 +1,29 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Locale") + +let locale = Intl.Locale.make("en-US") +let locale = Intl.Locale.makeWithOptions( + "en-US", + { + calendar: #hebrew, + collation: #compat, + hourCycle: #h24, + caseFirst: #upper, + numeric: true, + }, +) + +locale->Intl.Locale.baseName->Console.log +locale->Intl.Locale.calendar->Console.log +locale->Intl.Locale.caseFirst->Console.log +locale->Intl.Locale.collation->Console.log +locale->Intl.Locale.hourCycle->Console.log +locale->Intl.Locale.language->Console.log +locale->Intl.Locale.numberingSystem->Console.log +locale->Intl.Locale.numeric->Console.log +locale->Intl.Locale.region->Console.log +locale->Intl.Locale.script->Console.log +locale->Intl.Locale.maximize->Console.log +locale->Intl.Locale.minimize->Console.log diff --git a/test/Intl__NumberFormatTest.mjs b/test/Intl/Intl__NumberFormatTest.mjs similarity index 94% rename from test/Intl__NumberFormatTest.mjs rename to test/Intl/Intl__NumberFormatTest.mjs index b97ac1d5..7ff591c5 100644 --- a/test/Intl__NumberFormatTest.mjs +++ b/test/Intl/Intl__NumberFormatTest.mjs @@ -2,11 +2,9 @@ import * as Caml_option from "rescript/lib/es6/caml_option.js"; -console.info(""); +console.log("---"); -console.info("Intl"); - -console.info("---"); +console.log("Intl.NumberFormat"); var currencyFormatter = new Intl.NumberFormat("fr-FR", { currency: "EUR", diff --git a/test/Intl__NumberFormatTest.res b/test/Intl/Intl__NumberFormatTest.res similarity index 93% rename from test/Intl__NumberFormatTest.res rename to test/Intl/Intl__NumberFormatTest.res index 8c332bb2..7e97ad11 100644 --- a/test/Intl__NumberFormatTest.res +++ b/test/Intl/Intl__NumberFormatTest.res @@ -1,8 +1,8 @@ open RescriptCore -Console.info("") -Console.info("Intl") -Console.info("---") +Console.log("---") +Console.log("Intl.NumberFormat") + let currencyFormatter = Intl.NumberFormat.makeWithLocaleAndOptions( "fr-FR", {currency: "EUR", style: #currency}, diff --git a/test/Intl/Intl__PluralRulesTest.mjs b/test/Intl/Intl__PluralRulesTest.mjs new file mode 100644 index 00000000..3c92a119 --- /dev/null +++ b/test/Intl/Intl__PluralRulesTest.mjs @@ -0,0 +1,44 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.PluralRules"); + +new Intl.PluralRules(); + +new Intl.PluralRules("en-US"); + +new Intl.PluralRules([ + "en-US", + "en-GB" + ]); + +new Intl.PluralRules(undefined, { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +new Intl.PluralRules("en-US", { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +var formatter = new Intl.PluralRules(["en-US"], { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.select(2.0)); + +console.log(formatter.select(2)); + +export { + formatter , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__PluralRulesTest.res b/test/Intl/Intl__PluralRulesTest.res new file mode 100644 index 00000000..d8912521 --- /dev/null +++ b/test/Intl/Intl__PluralRulesTest.res @@ -0,0 +1,42 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.PluralRules") + +let formatter = Intl.PluralRules.make() +let formatter = Intl.PluralRules.makeWithLocale("en-US") +let formatter = Intl.PluralRules.makeWithLocales(["en-US", "en-GB"]) +let formatter = Intl.PluralRules.makeWithOptions({ + \"type": #ordinal, + maximumSignificantDigits: #5, + minimumSignificantDigits: #3, +}) +let formatter = Intl.PluralRules.makeWithLocaleAndOptions( + "en-US", + { + \"type": #ordinal, + maximumSignificantDigits: #5, + minimumSignificantDigits: #3, + }, +) +let formatter = Intl.PluralRules.makeWithLocalesAndOptions( + ["en-US"], + { + \"type": #ordinal, + maximumSignificantDigits: #5, + minimumSignificantDigits: #3, + }, +) + +formatter->Intl.PluralRules.resolvedOptions->Console.log + +formatter->Intl.PluralRules.select(2.0)->Console.log +formatter->Intl.PluralRules.selectInt(2)->Console.log + +// doesn't appear to work in node v16 +// formatter->Intl.PluralRules.selectBigInt(BigInt.fromInt(2))->Console.log +// formatter +// ->Intl.PluralRules.selectRangeBigInt(~start=BigInt.fromInt(1), ~end=BigInt.fromInt(3)) +// ->Console.log +// formatter->Intl.PluralRules.selectRange(~start=1., ~end=3.)->Console.log +// formatter->Intl.PluralRules.selectRangeInt(~start=1, ~end=3)->Console.log diff --git a/test/Intl/Intl__RelativeTimeFormatTest.mjs b/test/Intl/Intl__RelativeTimeFormatTest.mjs new file mode 100644 index 00000000..a0316d2a --- /dev/null +++ b/test/Intl/Intl__RelativeTimeFormatTest.mjs @@ -0,0 +1,53 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.RelativeTimeFormat"); + +Intl.RelativeTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.RelativeTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +new Intl.RelativeTimeFormat(); + +new Intl.RelativeTimeFormat("en-US"); + +new Intl.RelativeTimeFormat([ + "en-US", + "en-GB" + ]); + +new Intl.RelativeTimeFormat(undefined, { + numeric: "always", + style: "narrow" + }); + +new Intl.RelativeTimeFormat("en-US", { + numeric: "always", + style: "narrow" + }); + +var formatter = new Intl.RelativeTimeFormat(["en-US"], { + numeric: "always", + style: "narrow" + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.format(3, "hour")); + +console.log(formatter.formatToParts(3, "hour")); + +export { + formatter , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__RelativeTimeFormatTest.res b/test/Intl/Intl__RelativeTimeFormatTest.res new file mode 100644 index 00000000..4ba96df6 --- /dev/null +++ b/test/Intl/Intl__RelativeTimeFormatTest.res @@ -0,0 +1,37 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.RelativeTimeFormat") + +Intl.RelativeTimeFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.RelativeTimeFormat.supportedLocalesOfWithOptions( + ["en-US", "en-GB"], + {localeMatcher: #lookup}, +)->ignore + +let formatter = Intl.RelativeTimeFormat.make() +let formatter = Intl.RelativeTimeFormat.makeWithLocale("en-US") +let formatter = Intl.RelativeTimeFormat.makeWithLocales(["en-US", "en-GB"]) +let formatter = Intl.RelativeTimeFormat.makeWithOptions({ + numeric: #always, + style: #narrow, +}) +let formatter = Intl.RelativeTimeFormat.makeWithLocaleAndOptions( + "en-US", + { + numeric: #always, + style: #narrow, + }, +) +let formatter = Intl.RelativeTimeFormat.makeWithLocalesAndOptions( + ["en-US"], + { + numeric: #always, + style: #narrow, + }, +) + +formatter->Intl.RelativeTimeFormat.resolvedOptions->Console.log + +formatter->Intl.RelativeTimeFormat.format(3, #hour)->Console.log +formatter->Intl.RelativeTimeFormat.formatToParts(3, #hour)->Console.log diff --git a/test/Intl/Intl__SegmenterTest.mjs b/test/Intl/Intl__SegmenterTest.mjs new file mode 100644 index 00000000..2ab8686c --- /dev/null +++ b/test/Intl/Intl__SegmenterTest.mjs @@ -0,0 +1,55 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Segmenter"); + +Intl.Segmenter.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.Segmenter.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +new Intl.Segmenter(); + +new Intl.Segmenter("en-US"); + +new Intl.Segmenter([ + "en-US", + "en-GB" + ]); + +new Intl.Segmenter(undefined, { + granularity: "word" + }); + +new Intl.Segmenter("en-US", { + granularity: "word" + }); + +var formatter = new Intl.Segmenter(["en-US"], { + granularity: "word" + }); + +console.log(formatter.resolvedOptions()); + +var segments = formatter.segment("This is a sentence with several words"); + +console.log(segments); + +console.log(segments.containing()); + +console.log(segments.containing(1)); + +export { + formatter , + segments , +} +/* Not a pure module */ diff --git a/test/Intl/Intl__SegmenterTest.res b/test/Intl/Intl__SegmenterTest.res new file mode 100644 index 00000000..25d2caca --- /dev/null +++ b/test/Intl/Intl__SegmenterTest.res @@ -0,0 +1,34 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Segmenter") + +Intl.Segmenter.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.Segmenter.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore + +let formatter = Intl.Segmenter.make() +let formatter = Intl.Segmenter.makeWithLocale("en-US") +let formatter = Intl.Segmenter.makeWithLocales(["en-US", "en-GB"]) +let formatter = Intl.Segmenter.makeWithOptions({ + granularity: #word, +}) +let formatter = Intl.Segmenter.makeWithLocaleAndOptions( + "en-US", + { + granularity: #word, + }, +) +let formatter = Intl.Segmenter.makeWithLocalesAndOptions( + ["en-US"], + { + granularity: #word, + }, +) + +formatter->Intl.Segmenter.resolvedOptions->Console.log +let segments = formatter->Intl.Segmenter.segment("This is a sentence with several words") + +Console.log(segments) + +Intl.Segments.containing(segments)->Console.log +Intl.Segments.containingWithIndex(segments, 1)->Console.log diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 8d79517a..95c691dd 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Core__Int from "../src/Core__Int.mjs"; +import * as IntlTests from "./Intl/IntlTests.mjs"; import * as Core__Dict from "../src/Core__Dict.mjs"; import * as Core__JSON from "../src/Core__JSON.mjs"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; @@ -308,7 +309,40 @@ console.log(Core__Int.fromString(undefined, "99999999999999999")); console.log(Core__Int.fromString(2, "010101")); +var collator = IntlTests.collator; + +var resolvedOptions = IntlTests.resolvedOptions; + +var timeZone = IntlTests.timeZone; + +var locale = IntlTests.locale; + +var currencyFormatter = IntlTests.currencyFormatter; + +var roundingFormatter = IntlTests.roundingFormatter; + +var groupingFormatter1 = IntlTests.groupingFormatter1; + +var groupingFormatter2 = IntlTests.groupingFormatter2; + +var sigFormatter = IntlTests.sigFormatter; + +var formatter = IntlTests.formatter; + +var segments = IntlTests.segments; + export { + collator , + resolvedOptions , + timeZone , + locale , + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , + formatter , + segments , date , dict , dict2 , diff --git a/test/TempTests.res b/test/TempTests.res index 1792ab40..d2d25f8e 100644 --- a/test/TempTests.res +++ b/test/TempTests.res @@ -1,5 +1,7 @@ open RescriptCore +include IntlTests + Console.info("") Console.info("Array") Console.info("---") From 6490c23e16c3b6d2e45e572140364ae8877e2c7d Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 7 Mar 2023 21:56:47 -0500 Subject: [PATCH 11/18] feat: grouping parse --- .../Core__Intl__NumberFormat__Grouping.mjs | 35 ++++++++++++++++++- .../Core__Intl__NumberFormat__Grouping.res | 12 ++++++- test/Intl/IntlTests.mjs | 3 ++ test/Intl/Intl__NumberFormatTest.mjs | 8 +++++ test/Intl/Intl__NumberFormatTest.res | 4 +++ test/TempTests.mjs | 3 ++ 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/intl/Core__Intl__NumberFormat__Grouping.mjs b/src/intl/Core__Intl__NumberFormat__Grouping.mjs index d856702b..0e302fd8 100644 --- a/src/intl/Core__Intl__NumberFormat__Grouping.mjs +++ b/src/intl/Core__Intl__NumberFormat__Grouping.mjs @@ -1,2 +1,35 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ + +import * as Core__Type from "../Core__Type.mjs"; + +function parseJsValue(value) { + var value$1 = Core__Type.Classify.classify(value); + if (typeof value$1 === "number") { + return ; + } + switch (value$1.TAG | 0) { + case /* Bool */0 : + return { + NAME: "bool", + VAL: value$1._0 + }; + case /* String */1 : + switch (value$1._0) { + case "always" : + return "always"; + case "auto" : + return "auto"; + case "min2" : + return "min2"; + default: + return ; + } + default: + return ; + } +} + +export { + parseJsValue , +} +/* No side effect */ diff --git a/src/intl/Core__Intl__NumberFormat__Grouping.res b/src/intl/Core__Intl__NumberFormat__Grouping.res index 58f45ae1..a65f5296 100644 --- a/src/intl/Core__Intl__NumberFormat__Grouping.res +++ b/src/intl/Core__Intl__NumberFormat__Grouping.res @@ -1,5 +1,15 @@ type t +type parsed = [#bool(bool) | #always | #auto | #min2] + external fromBool: bool => t = "%identity" external fromString: [#always | #auto | #min2] => t = "%identity" -// TODO: unwrap this for consumption coming back in resolvedOptions + +let parseJsValue = value => + switch Core__Type.Classify.classify(value) { + | String("always") => Some(#always) + | String("auto") => Some(#auto) + | String("min2") => Some(#min2) + | Bool(value) => Some(#bool(value)) + | _ => None + } diff --git a/test/Intl/IntlTests.mjs b/test/Intl/IntlTests.mjs index e6abdbc4..66addb8f 100644 --- a/test/Intl/IntlTests.mjs +++ b/test/Intl/IntlTests.mjs @@ -82,6 +82,8 @@ var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2; var sigFormatter = Intl__NumberFormatTest.sigFormatter; +var options = Intl__NumberFormatTest.options; + var formatter = Intl__SegmenterTest.formatter; var segments = Intl__SegmenterTest.segments; @@ -96,6 +98,7 @@ export { groupingFormatter1 , groupingFormatter2 , sigFormatter , + options , formatter , segments , } diff --git a/test/Intl/Intl__NumberFormatTest.mjs b/test/Intl/Intl__NumberFormatTest.mjs index 7ff591c5..512a930a 100644 --- a/test/Intl/Intl__NumberFormatTest.mjs +++ b/test/Intl/Intl__NumberFormatTest.mjs @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Intl__NumberFormat__Grouping from "../../src/intl/Core__Intl__NumberFormat__Grouping.mjs"; console.log("---"); @@ -39,11 +40,18 @@ var sigFormatter = new Intl.NumberFormat(undefined, { maximumSignificantDigits: 1 }); +var options = sigFormatter.resolvedOptions(); + +console.log(options); + +console.log(Core__Intl__NumberFormat__Grouping.parseJsValue(options.useGrouping)); + export { currencyFormatter , roundingFormatter , groupingFormatter1 , groupingFormatter2 , sigFormatter , + options , } /* Not a pure module */ diff --git a/test/Intl/Intl__NumberFormatTest.res b/test/Intl/Intl__NumberFormatTest.res index 7e97ad11..91a7f2cb 100644 --- a/test/Intl/Intl__NumberFormatTest.res +++ b/test/Intl/Intl__NumberFormatTest.res @@ -30,3 +30,7 @@ let sigFormatter = Intl.NumberFormat.makeWithOptions({ minimumSignificantDigits: #1, maximumSignificantDigits: #1, }) + +let options = sigFormatter->Intl.NumberFormat.resolvedOptions +Console.log(options) +options.useGrouping->Core__Intl__NumberFormat.Grouping.parseJsValue->Console.log diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 95c691dd..23de08c4 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -327,6 +327,8 @@ var groupingFormatter2 = IntlTests.groupingFormatter2; var sigFormatter = IntlTests.sigFormatter; +var options = IntlTests.options; + var formatter = IntlTests.formatter; var segments = IntlTests.segments; @@ -341,6 +343,7 @@ export { groupingFormatter1 , groupingFormatter2 , sigFormatter , + options , formatter , segments , date , From ae61148a8bd4b34f3ba92da7da09934e2fc84eaa Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 16 Jan 2024 23:36:44 -0500 Subject: [PATCH 12/18] feat: Intl.PluralRules --- rescript.json | 1 + src/intl/Core__Intl__PluralRules.res | 65 +++++++++++++++++++++++++--- test/TempTests.mjs | 2 +- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/rescript.json b/rescript.json index f5c04d1e..ab02df12 100644 --- a/rescript.json +++ b/rescript.json @@ -8,6 +8,7 @@ }, { "dir": "test", + "subdirs": ["intl"], "type": "dev" } ], diff --git a/src/intl/Core__Intl__PluralRules.res b/src/intl/Core__Intl__PluralRules.res index 6d71bcbf..62d877b8 100644 --- a/src/intl/Core__Intl__PluralRules.res +++ b/src/intl/Core__Intl__PluralRules.res @@ -1,21 +1,76 @@ type t +type localeType = [#cardinal | #ordinal] + +type options = { + localeMatcher?: Core__Intl__Common.localeMatcher, + \"type"?: localeType, + // use either this group + minimumIntegerDigits?: Core__Intl__Common.oneTo21, + minimumFractionDigits?: Core__Intl__Common.zeroTo20, + maximumFractionDigits?: Core__Intl__Common.zeroTo20, + // OR this group + minimumSignificantDigits?: Core__Intl__Common.oneTo21, + maximumSignificantDigits?: Core__Intl__Common.oneTo21, +} + +type pluralCategories = [ + | #zero + | #one + | #two + | #few + | #many + | #other +] + +type resolvedOptions = { + locale: string, + pluralCategories: array, + \"type": localeType, + // either this group + minimumIntegerDigits?: Core__Intl__Common.oneTo21, + minimumFractionDigits?: Core__Intl__Common.zeroTo20, + maximumFractionDigits?: Core__Intl__Common.zeroTo20, + // OR this group + minimumSignificantDigits?: Core__Intl__Common.oneTo21, + maximumSignificantDigits?: Core__Intl__Common.oneTo21, +} + +type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher} + @new external make: unit => t = "Intl.PluralRules" @new external makeWithLocale: string => t = "Intl.PluralRules" @new external makeWithLocales: array => t = "Intl.PluralRules" -@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.PluralRules" -@new external makeWithLocalesAndOptions: (array, {..}) => t = "Intl.PluralRules" -@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.PluralRules" +@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.PluralRules" +@new external makeWithLocalesAndOptions: (array, options) => t = "Intl.PluralRules" +@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.PluralRules" @val external supportedLocalesOf: array => t = "Intl.PluralRules.supportedLocalesOf" @val -external supportedLocalesOfWithOptions: (array, {..}) => t = +external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.PluralRules.supportedLocalesOf" -@send external resolvedOptions: t => {..} = "resolvedOptions" +@send external resolvedOptions: t => resolvedOptions = "resolvedOptions" type rule = [#zero | #one | #two | #few | #many | #other] @send external select: (t, float) => rule = "select" @send external selectInt: (t, int) => rule = "select" @send external selectBigInt: (t, Core__BigInt.t) => rule = "select" + +/** +Not supported in Firefox v110 +*/ +@send +external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange" +/** +Not supported in Firefox v110 +*/ +@send +external selectRangeInt: (t, ~start: int, ~end: int) => rule = "selectRange" +/** +Not supported in Firefox v110 +*/ +@send +external selectRangeBigInt: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => rule = + "selectRange" diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 23de08c4..f9ac2519 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Core__Int from "../src/Core__Int.mjs"; -import * as IntlTests from "./Intl/IntlTests.mjs"; +import * as IntlTests from "./intl/IntlTests.mjs"; import * as Core__Dict from "../src/Core__Dict.mjs"; import * as Core__JSON from "../src/Core__JSON.mjs"; import * as Caml_option from "rescript/lib/es6/caml_option.js"; From 57ec0d9e1c0ee4579a6b3e5cdc4e77d514938bb4 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 16 Jan 2024 23:41:09 -0500 Subject: [PATCH 13/18] case-sensitive :( --- test/{Intl => intl}/IntlTests.res | 0 test/{Intl => intl}/Intl__CollatorTest.res | 0 test/{Intl => intl}/Intl__DateTimeFormatTest.res | 0 test/{Intl => intl}/Intl__ListFormatTest.res | 0 test/{Intl => intl}/Intl__LocaleTest.res | 0 test/{Intl => intl}/Intl__NumberFormatTest.res | 0 test/{Intl => intl}/Intl__PluralRulesTest.res | 0 test/{Intl => intl}/Intl__RelativeTimeFormatTest.res | 0 test/{Intl => intl}/Intl__SegmenterTest.res | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename test/{Intl => intl}/IntlTests.res (100%) rename test/{Intl => intl}/Intl__CollatorTest.res (100%) rename test/{Intl => intl}/Intl__DateTimeFormatTest.res (100%) rename test/{Intl => intl}/Intl__ListFormatTest.res (100%) rename test/{Intl => intl}/Intl__LocaleTest.res (100%) rename test/{Intl => intl}/Intl__NumberFormatTest.res (100%) rename test/{Intl => intl}/Intl__PluralRulesTest.res (100%) rename test/{Intl => intl}/Intl__RelativeTimeFormatTest.res (100%) rename test/{Intl => intl}/Intl__SegmenterTest.res (100%) diff --git a/test/Intl/IntlTests.res b/test/intl/IntlTests.res similarity index 100% rename from test/Intl/IntlTests.res rename to test/intl/IntlTests.res diff --git a/test/Intl/Intl__CollatorTest.res b/test/intl/Intl__CollatorTest.res similarity index 100% rename from test/Intl/Intl__CollatorTest.res rename to test/intl/Intl__CollatorTest.res diff --git a/test/Intl/Intl__DateTimeFormatTest.res b/test/intl/Intl__DateTimeFormatTest.res similarity index 100% rename from test/Intl/Intl__DateTimeFormatTest.res rename to test/intl/Intl__DateTimeFormatTest.res diff --git a/test/Intl/Intl__ListFormatTest.res b/test/intl/Intl__ListFormatTest.res similarity index 100% rename from test/Intl/Intl__ListFormatTest.res rename to test/intl/Intl__ListFormatTest.res diff --git a/test/Intl/Intl__LocaleTest.res b/test/intl/Intl__LocaleTest.res similarity index 100% rename from test/Intl/Intl__LocaleTest.res rename to test/intl/Intl__LocaleTest.res diff --git a/test/Intl/Intl__NumberFormatTest.res b/test/intl/Intl__NumberFormatTest.res similarity index 100% rename from test/Intl/Intl__NumberFormatTest.res rename to test/intl/Intl__NumberFormatTest.res diff --git a/test/Intl/Intl__PluralRulesTest.res b/test/intl/Intl__PluralRulesTest.res similarity index 100% rename from test/Intl/Intl__PluralRulesTest.res rename to test/intl/Intl__PluralRulesTest.res diff --git a/test/Intl/Intl__RelativeTimeFormatTest.res b/test/intl/Intl__RelativeTimeFormatTest.res similarity index 100% rename from test/Intl/Intl__RelativeTimeFormatTest.res rename to test/intl/Intl__RelativeTimeFormatTest.res diff --git a/test/Intl/Intl__SegmenterTest.res b/test/intl/Intl__SegmenterTest.res similarity index 100% rename from test/Intl/Intl__SegmenterTest.res rename to test/intl/Intl__SegmenterTest.res From ed938d9a72e0055aeefe9a28aa48e9d292f98a17 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 20 Feb 2024 08:45:28 -0500 Subject: [PATCH 14/18] fix type error in node 20+ tests --- src/intl/Core__Intl__NumberFormat__Grouping.mjs | 8 ++++---- test/Intl/Intl__NumberFormatTest.mjs | 5 +++-- test/intl/Intl__NumberFormatTest.res | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/intl/Core__Intl__NumberFormat__Grouping.mjs b/src/intl/Core__Intl__NumberFormat__Grouping.mjs index 0e302fd8..73c227aa 100644 --- a/src/intl/Core__Intl__NumberFormat__Grouping.mjs +++ b/src/intl/Core__Intl__NumberFormat__Grouping.mjs @@ -4,16 +4,16 @@ import * as Core__Type from "../Core__Type.mjs"; function parseJsValue(value) { var value$1 = Core__Type.Classify.classify(value); - if (typeof value$1 === "number") { + if (typeof value$1 !== "object") { return ; } - switch (value$1.TAG | 0) { - case /* Bool */0 : + switch (value$1.TAG) { + case "Bool" : return { NAME: "bool", VAL: value$1._0 }; - case /* String */1 : + case "String" : switch (value$1._0) { case "always" : return "always"; diff --git a/test/Intl/Intl__NumberFormatTest.mjs b/test/Intl/Intl__NumberFormatTest.mjs index 512a930a..d19804e9 100644 --- a/test/Intl/Intl__NumberFormatTest.mjs +++ b/test/Intl/Intl__NumberFormatTest.mjs @@ -20,8 +20,9 @@ console.log(Intl.NumberFormat.supportedLocalesOf([ console.log(currencyFormatter.format(123.23)); var roundingFormatter = new Intl.NumberFormat(undefined, { - roundingPriority: "lessPrecision", - roundingIncrement: 500 + roundingIncrement: 500, + minimumFractionDigits: 2, + maximumFractionDigits: 2 }); var groupingFormatter1 = new Intl.NumberFormat(undefined, { diff --git a/test/intl/Intl__NumberFormatTest.res b/test/intl/Intl__NumberFormatTest.res index 91a7f2cb..51829077 100644 --- a/test/intl/Intl__NumberFormatTest.res +++ b/test/intl/Intl__NumberFormatTest.res @@ -12,8 +12,9 @@ Console.log(Intl.NumberFormat.supportedLocalesOf(["fr-FR", "en-US"])) Console.log(currencyFormatter->Intl.NumberFormat.format(123.23)) let roundingFormatter = Intl.NumberFormat.makeWithOptions({ - roundingPriority: #lessPrecision, roundingIncrement: #500, + minimumFractionDigits: #2, + maximumFractionDigits: #2, }) let groupingFormatter1 = Intl.NumberFormat.makeWithOptions({ From b6d4691a9cd829ce42db5ae0f8fe92061d105306 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 20 Feb 2024 08:50:13 -0500 Subject: [PATCH 15/18] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ce313b..3289de50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next version +- BREAKING: Adds typed bindings to `Intl`, replacing the options type of `{..}` with records. https://github.com/rescript-association/rescript-core/pull/65 - Add `Dict.forEach`, `Dict.forEachWithKey` and `Dict.mapValues` https://github.com/rescript-association/rescript-core/pull/181 - Remove internal xxxU helper functions that are not needed anymore in uncurried mode. https://github.com/rescript-association/rescript-core/pull/191 - Rename `Object.empty` to `Object.make` for consistency. From 77ed9b7a110dbc0e7e28f7f026a814de37a822ad Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 20 Feb 2024 09:40:43 -0500 Subject: [PATCH 16/18] cleanup: remove firefox v110 comments --- src/intl/Core__Intl__DateTimeFormat.res | 14 +++++++------ src/intl/Core__Intl__NumberFormat.res | 27 +++++++------------------ src/intl/Core__Intl__PluralRules.res | 11 ++-------- test/Intl/Intl__DateTimeFormatTest.mjs | 2 +- test/intl/IntlTests.res | 7 +++++-- test/intl/Intl__DateTimeFormatTest.res | 22 +++++++++++++++++--- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/intl/Core__Intl__DateTimeFormat.res b/src/intl/Core__Intl__DateTimeFormat.res index 5cc63424..7a79372c 100644 --- a/src/intl/Core__Intl__DateTimeFormat.res +++ b/src/intl/Core__Intl__DateTimeFormat.res @@ -11,16 +11,18 @@ type day = [#numeric | #"2-digit"] type hour = [#numeric | #"2-digit"] type minute = [#numeric | #"2-digit"] type second = [#numeric | #"2-digit"] -// Firefox also supports IANA time zone names here + +/** +Firefox also supports IANA time zone names here +*/ type timeZoneName = [ | #short | #long + | #shortOffset + | #shortGeneric + | #longOffset + | #longGeneric ] -// TODO unsupported in node? -// | #shortOffset -// | #shortGeneric -// | #longOffset -// | #longGeneric type hourCycle = [#h11 | #h12 | #h23 | #h24] type formatMatcher = [#basic | @as("best fit") #bestFit] diff --git a/src/intl/Core__Intl__NumberFormat.res b/src/intl/Core__Intl__NumberFormat.res index d5c3743f..f229a3f5 100644 --- a/src/intl/Core__Intl__NumberFormat.res +++ b/src/intl/Core__Intl__NumberFormat.res @@ -15,12 +15,12 @@ Used only when notation is #compact */ type compactDisplay = [#short | #long] -// TODO: "negative" is not yet well supported type signDisplay = [ | #auto | #always | #exceptZero | #never + | #negative ] type style = [#decimal | #currency | #percent | #unit] @@ -174,7 +174,7 @@ type numberFormatRangePart = { @new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.NumberFormat" @val external supportedLocalesOf: array => t = "Intl.NumberFormat.supportedLocalesOf" -// TODO + @val external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) => t = "Intl.NumberFormat.supportedLocalesOf" @@ -182,47 +182,33 @@ external supportedLocalesOfWithOptions: (array, supportedLocalesOptions) @send external resolvedOptions: t => resolvedOptions = "resolvedOptions" @send external format: (t, float) => string = "format" -/** -Not available in firefox v110 -*/ @send external formatRange: (t, ~start: float, ~end: float) => array = "formatRange" @send external formatToParts: (t, float) => array = "formatToParts" -/** -Not available in firefox v110 -*/ @send external formatRangeToParts: (t, ~start: float, ~end: float) => array = "formatRange" @send external formatInt: (t, int) => string = "format" -/** -Not available in firefox v110 -*/ + @send external formatIntRange: (t, ~start: int, ~end: int) => array = "formatRange" @send external formatIntToParts: (t, int) => array = "formatToParts" -/** -Not available in firefox v110 -*/ + @send external formatIntRangeToParts: (t, ~start: int, ~end: int) => array = "formatRange" @send external formatBigInt: (t, Core__BigInt.t) => string = "format" -/** -Not available in firefox v110 -*/ + @send external formatBigIntRange: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => array = "formatRange" @send external formatBigIntToParts: (t, Core__BigInt.t) => array = "formatToParts" -/** -Not available in firefox v110 -*/ + @send external formatBigIntRangeToParts: ( t, @@ -231,5 +217,6 @@ external formatBigIntRangeToParts: ( ) => array = "formatRange" @send external formatString: (t, string) => string = "format" + @send external formatStringToParts: (t, string) => array = "formatToParts" diff --git a/src/intl/Core__Intl__PluralRules.res b/src/intl/Core__Intl__PluralRules.res index 62d877b8..008f5ab3 100644 --- a/src/intl/Core__Intl__PluralRules.res +++ b/src/intl/Core__Intl__PluralRules.res @@ -58,19 +58,12 @@ type rule = [#zero | #one | #two | #few | #many | #other] @send external selectInt: (t, int) => rule = "select" @send external selectBigInt: (t, Core__BigInt.t) => rule = "select" -/** -Not supported in Firefox v110 -*/ @send external selectRange: (t, ~start: float, ~end: float) => rule = "selectRange" -/** -Not supported in Firefox v110 -*/ + @send external selectRangeInt: (t, ~start: int, ~end: int) => rule = "selectRange" -/** -Not supported in Firefox v110 -*/ + @send external selectRangeBigInt: (t, ~start: Core__BigInt.t, ~end: Core__BigInt.t) => rule = "selectRange" diff --git a/test/Intl/Intl__DateTimeFormatTest.mjs b/test/Intl/Intl__DateTimeFormatTest.mjs index 566cb9fc..0dc281ad 100644 --- a/test/Intl/Intl__DateTimeFormatTest.mjs +++ b/test/Intl/Intl__DateTimeFormatTest.mjs @@ -39,7 +39,7 @@ var formatter$1 = new Intl.DateTimeFormat(undefined, { minute: "2-digit", second: "2-digit", fractionalSecondDigits: 3, - timeZoneName: "short" + timeZoneName: "longGeneric" }); console.log(formatter$1.format(new Date(Date.now()))); diff --git a/test/intl/IntlTests.res b/test/intl/IntlTests.res index 44afcde6..cf079677 100644 --- a/test/intl/IntlTests.res +++ b/test/intl/IntlTests.res @@ -37,6 +37,9 @@ try { Console.error("Shouldn't have been hit") } catch { -| Exn.Error(e) => Console.error(e) -// Expected output: RangeError: invalid key: "someInvalidKey" +| Exn.Error(e) => + switch Exn.message(e)->String.toLowerCase { + | "rangeerror: invalid key: \"someinvalidkey\"" => Console.log("Caught expected error") + | _ => Error.raise(e) + } } diff --git a/test/intl/Intl__DateTimeFormatTest.res b/test/intl/Intl__DateTimeFormatTest.res index 4dba8c5e..b9359ff3 100644 --- a/test/intl/Intl__DateTimeFormatTest.res +++ b/test/intl/Intl__DateTimeFormatTest.res @@ -20,7 +20,7 @@ Console.log( ), ) -let formatter = Intl.DateTimeFormat.makeWithOptions({ +let options = { hour12: false, hourCycle: #h24, timeZone: "UTC", @@ -33,10 +33,26 @@ let formatter = Intl.DateTimeFormat.makeWithOptions({ minute: #"2-digit", second: #"2-digit", fractionalSecondDigits: #3, - timeZoneName: #short, -}) + timeZoneName: #longGeneric, +} +let formatter = Intl.DateTimeFormat.makeWithOptions(options) Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) +let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #long}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #longOffset}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #short}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #shortGeneric}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #shortOffset}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions let {Intl.DateTimeFormat.timeZone: timeZone, _} = resolvedOptions From 8ce2eb05f15c5e67bbc9bb92567ec43e57e39a2c Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 20 Feb 2024 09:42:33 -0500 Subject: [PATCH 17/18] docs: add node runtime comment --- src/intl/Core__Intl__DateTimeFormat.res | 1 + 1 file changed, 1 insertion(+) diff --git a/src/intl/Core__Intl__DateTimeFormat.res b/src/intl/Core__Intl__DateTimeFormat.res index 7a79372c..009445e3 100644 --- a/src/intl/Core__Intl__DateTimeFormat.res +++ b/src/intl/Core__Intl__DateTimeFormat.res @@ -14,6 +14,7 @@ type second = [#numeric | #"2-digit"] /** Firefox also supports IANA time zone names here +Node v19+ supports "shortOffset", "shortGeneric", "longOffset", and "longGeneric". */ type timeZoneName = [ | #short From 7fca684ec7fad43afb1273dae9d3a8eb77d356d0 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 20 Feb 2024 10:05:23 -0500 Subject: [PATCH 18/18] fix tests --- test/Intl/IntlTests.mjs | 33 ++++++++++- test/Intl/Intl__CollatorTest.mjs | 3 +- test/Intl/Intl__DateTimeFormatTest.mjs | 66 ++++++++++++++++------ test/Intl/Intl__ListFormatTest.mjs | 3 +- test/Intl/Intl__LocaleTest.mjs | 3 +- test/Intl/Intl__PluralRulesTest.mjs | 3 +- test/Intl/Intl__RelativeTimeFormatTest.mjs | 3 +- test/Intl/Intl__SegmenterTest.mjs | 3 +- test/TempTests.mjs | 9 +++ test/intl/IntlTests.res | 14 ++++- test/intl/Intl__CollatorTest.res | 6 +- test/intl/Intl__DateTimeFormatTest.res | 2 +- test/intl/Intl__ListFormatTest.res | 10 ++-- test/intl/Intl__LocaleTest.res | 2 +- test/intl/Intl__PluralRulesTest.res | 10 ++-- test/intl/Intl__RelativeTimeFormatTest.res | 10 ++-- test/intl/Intl__SegmenterTest.res | 10 ++-- 17 files changed, 138 insertions(+), 52 deletions(-) diff --git a/test/Intl/IntlTests.mjs b/test/Intl/IntlTests.mjs index 66addb8f..6fcf5875 100644 --- a/test/Intl/IntlTests.mjs +++ b/test/Intl/IntlTests.mjs @@ -1,6 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Option from "../../src/Core__Option.mjs"; import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs"; import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs"; @@ -58,18 +60,40 @@ try { catch (raw_e$2){ var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2); if (e$2.RE_EXN_ID === Js_exn.$$Error) { - console.error(e$2._1); + var e$3 = e$2._1; + var message = Core__Option.map(e$3.message, (function (prim) { + return prim.toLowerCase(); + })); + var exit = 0; + if (message === "invalid key : someinvalidkey") { + console.log("Caught expected error"); + } else { + exit = 1; + } + if (exit === 1) { + console.warn("Unexpected error message: \"" + message + "\""); + throw e$3; + } + } else { - throw e$2; + var e$4 = Caml_js_exceptions.as_js_exn(e$2); + if (e$4 !== undefined) { + throw Caml_option.valFromOption(e$4); + } + console.error("Unexpected error"); } } +var _collator = Intl__CollatorTest._collator; + var collator = Intl__CollatorTest.collator; var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions; var timeZone = Intl__DateTimeFormatTest.timeZone; +var _locale = Intl__LocaleTest._locale; + var locale = Intl__LocaleTest.locale; var currencyFormatter = Intl__NumberFormatTest.currencyFormatter; @@ -84,14 +108,18 @@ var sigFormatter = Intl__NumberFormatTest.sigFormatter; var options = Intl__NumberFormatTest.options; +var _formatter = Intl__SegmenterTest._formatter; + var formatter = Intl__SegmenterTest.formatter; var segments = Intl__SegmenterTest.segments; export { + _collator , collator , resolvedOptions , timeZone , + _locale , locale , currencyFormatter , roundingFormatter , @@ -99,6 +127,7 @@ export { groupingFormatter2 , sigFormatter , options , + _formatter , formatter , segments , } diff --git a/test/Intl/Intl__CollatorTest.mjs b/test/Intl/Intl__CollatorTest.mjs index 1628b3f4..3945f3a8 100644 --- a/test/Intl/Intl__CollatorTest.mjs +++ b/test/Intl/Intl__CollatorTest.mjs @@ -9,7 +9,7 @@ new Intl.Collator(); new Intl.Collator("en-US"); -new Intl.Collator([ +var _collator = new Intl.Collator([ "en-US", "en-GB" ]); @@ -40,6 +40,7 @@ console.log(collator.compare("hi", "hï")); console.log(Intl.Collator.supportedLocalesOf(["hi"])); export { + _collator , collator , } /* Not a pure module */ diff --git a/test/Intl/Intl__DateTimeFormatTest.mjs b/test/Intl/Intl__DateTimeFormatTest.mjs index 0dc281ad..140ae17c 100644 --- a/test/Intl/Intl__DateTimeFormatTest.mjs +++ b/test/Intl/Intl__DateTimeFormatTest.mjs @@ -1,5 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; console.log("---"); @@ -26,30 +27,63 @@ console.log(formatter.format(new Date(Date.now()))); console.log(formatter.formatRange(new Date(2023, 1, 1), new Date(2023, 12, 31))); -var formatter$1 = new Intl.DateTimeFormat(undefined, { - timeZone: "UTC", - hour12: false, - hourCycle: "h24", - weekday: "narrow", - era: "narrow", - year: "2-digit", - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - fractionalSecondDigits: 3, - timeZoneName: "longGeneric" - }); +var options = { + timeZone: "UTC", + hour12: false, + hourCycle: "h24", + weekday: "narrow", + era: "narrow", + year: "2-digit", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + fractionalSecondDigits: 3, + timeZoneName: "longGeneric" +}; + +var formatter$1 = new Intl.DateTimeFormat(undefined, options); console.log(formatter$1.format(new Date(Date.now()))); +var newrecord = Caml_obj.obj_dup(options); + +var formatter$2 = new Intl.DateTimeFormat(undefined, (newrecord.timeZoneName = "long", newrecord)); + +console.log(formatter$2.format(new Date(Date.now()))); + +var newrecord$1 = Caml_obj.obj_dup(options); + +var formatter$3 = new Intl.DateTimeFormat(undefined, (newrecord$1.timeZoneName = "longOffset", newrecord$1)); + +console.log(formatter$3.format(new Date(Date.now()))); + +var newrecord$2 = Caml_obj.obj_dup(options); + +var formatter$4 = new Intl.DateTimeFormat(undefined, (newrecord$2.timeZoneName = "short", newrecord$2)); + +console.log(formatter$4.format(new Date(Date.now()))); + +var newrecord$3 = Caml_obj.obj_dup(options); + +var formatter$5 = new Intl.DateTimeFormat(undefined, (newrecord$3.timeZoneName = "shortGeneric", newrecord$3)); + +console.log(formatter$5.format(new Date(Date.now()))); + +var newrecord$4 = Caml_obj.obj_dup(options); + +var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName = "shortOffset", newrecord$4)); + +console.log(formatter$6.format(new Date(Date.now()))); + var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); var timeZone = resolvedOptions.timeZone; export { - formatter$1 as formatter, + options , + formatter$6 as formatter, resolvedOptions , timeZone , } diff --git a/test/Intl/Intl__ListFormatTest.mjs b/test/Intl/Intl__ListFormatTest.mjs index 4e763403..592a5eb7 100644 --- a/test/Intl/Intl__ListFormatTest.mjs +++ b/test/Intl/Intl__ListFormatTest.mjs @@ -19,7 +19,7 @@ new Intl.ListFormat("en-US", { style: "long" }); -new Intl.ListFormat([ +var _formatter = new Intl.ListFormat([ "en-US", "en-GB" ], { @@ -59,6 +59,7 @@ console.log(formatter.formatToParts([ ])); export { + _formatter , formatter , } /* Not a pure module */ diff --git a/test/Intl/Intl__LocaleTest.mjs b/test/Intl/Intl__LocaleTest.mjs index eb1df8d1..a8349a84 100644 --- a/test/Intl/Intl__LocaleTest.mjs +++ b/test/Intl/Intl__LocaleTest.mjs @@ -5,7 +5,7 @@ console.log("---"); console.log("Intl.Locale"); -new Intl.Locale("en-US"); +var _locale = new Intl.Locale("en-US"); var locale = new Intl.Locale("en-US", { calendar: "hebrew", @@ -40,6 +40,7 @@ console.log(locale.maximize()); console.log(locale.minimize()); export { + _locale , locale , } /* Not a pure module */ diff --git a/test/Intl/Intl__PluralRulesTest.mjs b/test/Intl/Intl__PluralRulesTest.mjs index 3c92a119..b4fe8030 100644 --- a/test/Intl/Intl__PluralRulesTest.mjs +++ b/test/Intl/Intl__PluralRulesTest.mjs @@ -20,7 +20,7 @@ new Intl.PluralRules(undefined, { maximumSignificantDigits: 5 }); -new Intl.PluralRules("en-US", { +var _formatter = new Intl.PluralRules("en-US", { type: "ordinal", minimumSignificantDigits: 3, maximumSignificantDigits: 5 @@ -39,6 +39,7 @@ console.log(formatter.select(2.0)); console.log(formatter.select(2)); export { + _formatter , formatter , } /* Not a pure module */ diff --git a/test/Intl/Intl__RelativeTimeFormatTest.mjs b/test/Intl/Intl__RelativeTimeFormatTest.mjs index a0316d2a..062d89be 100644 --- a/test/Intl/Intl__RelativeTimeFormatTest.mjs +++ b/test/Intl/Intl__RelativeTimeFormatTest.mjs @@ -31,7 +31,7 @@ new Intl.RelativeTimeFormat(undefined, { style: "narrow" }); -new Intl.RelativeTimeFormat("en-US", { +var _formatter = new Intl.RelativeTimeFormat("en-US", { numeric: "always", style: "narrow" }); @@ -48,6 +48,7 @@ console.log(formatter.format(3, "hour")); console.log(formatter.formatToParts(3, "hour")); export { + _formatter , formatter , } /* Not a pure module */ diff --git a/test/Intl/Intl__SegmenterTest.mjs b/test/Intl/Intl__SegmenterTest.mjs index 2ab8686c..757c7c4d 100644 --- a/test/Intl/Intl__SegmenterTest.mjs +++ b/test/Intl/Intl__SegmenterTest.mjs @@ -30,7 +30,7 @@ new Intl.Segmenter(undefined, { granularity: "word" }); -new Intl.Segmenter("en-US", { +var _formatter = new Intl.Segmenter("en-US", { granularity: "word" }); @@ -49,6 +49,7 @@ console.log(segments.containing()); console.log(segments.containing(1)); export { + _formatter , formatter , segments , } diff --git a/test/TempTests.mjs b/test/TempTests.mjs index f9ac2519..4239421f 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -309,12 +309,16 @@ console.log(Core__Int.fromString(undefined, "99999999999999999")); console.log(Core__Int.fromString(2, "010101")); +var _collator = IntlTests._collator; + var collator = IntlTests.collator; var resolvedOptions = IntlTests.resolvedOptions; var timeZone = IntlTests.timeZone; +var _locale = IntlTests._locale; + var locale = IntlTests.locale; var currencyFormatter = IntlTests.currencyFormatter; @@ -329,14 +333,18 @@ var sigFormatter = IntlTests.sigFormatter; var options = IntlTests.options; +var _formatter = IntlTests._formatter; + var formatter = IntlTests.formatter; var segments = IntlTests.segments; export { + _collator , collator , resolvedOptions , timeZone , + _locale , locale , currencyFormatter , roundingFormatter , @@ -344,6 +352,7 @@ export { groupingFormatter2 , sigFormatter , options , + _formatter , formatter , segments , date , diff --git a/test/intl/IntlTests.res b/test/intl/IntlTests.res index cf079677..d5fa1c6d 100644 --- a/test/intl/IntlTests.res +++ b/test/intl/IntlTests.res @@ -38,8 +38,16 @@ try { Console.error("Shouldn't have been hit") } catch { | Exn.Error(e) => - switch Exn.message(e)->String.toLowerCase { - | "rangeerror: invalid key: \"someinvalidkey\"" => Console.log("Caught expected error") - | _ => Error.raise(e) + switch Error.message(e)->Option.map(String.toLowerCase) { + | Some("invalid key : someinvalidkey") => Console.log("Caught expected error") + | message => { + Console.warn(`Unexpected error message: "${message->Option.getUnsafe}"`) + Error.raise(e) + } + } +| e => + switch Error.fromException(e) { + | Some(e) => Error.raise(e) + | None => Console.error("Unexpected error") } } diff --git a/test/intl/Intl__CollatorTest.res b/test/intl/Intl__CollatorTest.res index f339e1d1..45ea8d7b 100644 --- a/test/intl/Intl__CollatorTest.res +++ b/test/intl/Intl__CollatorTest.res @@ -3,9 +3,9 @@ open RescriptCore Console.log("---") Console.log("Intl.Collator") -let collator = Intl.Collator.make() -let collator = Intl.Collator.makeWithLocale("en-US") -let collator = Intl.Collator.makeWithLocales(["en-US", "en-GB"]) +let _collator = Intl.Collator.make() +let _collator = Intl.Collator.makeWithLocale("en-US") +let _collator = Intl.Collator.makeWithLocales(["en-US", "en-GB"]) let collator = Intl.Collator.makeWithLocaleAndOptions( "en-US", {caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true}, diff --git a/test/intl/Intl__DateTimeFormatTest.res b/test/intl/Intl__DateTimeFormatTest.res index b9359ff3..f98b75c1 100644 --- a/test/intl/Intl__DateTimeFormatTest.res +++ b/test/intl/Intl__DateTimeFormatTest.res @@ -20,7 +20,7 @@ Console.log( ), ) -let options = { +let options: Intl.DateTimeFormat.options = { hour12: false, hourCycle: #h24, timeZone: "UTC", diff --git a/test/intl/Intl__ListFormatTest.res b/test/intl/Intl__ListFormatTest.res index b2ed3cf4..8bb9a479 100644 --- a/test/intl/Intl__ListFormatTest.res +++ b/test/intl/Intl__ListFormatTest.res @@ -3,14 +3,14 @@ open RescriptCore Console.log("---") Console.log("Intl.ListFormat") -let formatter = Intl.ListFormat.make() -let formatter = Intl.ListFormat.makeWithLocale("en-US") -let formatter = Intl.ListFormat.makeWithLocales(["en-US", "en-GB"]) -let formatter = Intl.ListFormat.makeWithLocaleAndOptions( +let _formatter = Intl.ListFormat.make() +let _formatter = Intl.ListFormat.makeWithLocale("en-US") +let _formatter = Intl.ListFormat.makeWithLocales(["en-US", "en-GB"]) +let _formatter = Intl.ListFormat.makeWithLocaleAndOptions( "en-US", {style: #long, \"type": #conjunction}, ) -let formatter = Intl.ListFormat.makeWithLocalesAndOptions( +let _formatter = Intl.ListFormat.makeWithLocalesAndOptions( ["en-US", "en-GB"], {style: #long, \"type": #conjunction}, ) diff --git a/test/intl/Intl__LocaleTest.res b/test/intl/Intl__LocaleTest.res index 5938e192..543d8004 100644 --- a/test/intl/Intl__LocaleTest.res +++ b/test/intl/Intl__LocaleTest.res @@ -3,7 +3,7 @@ open RescriptCore Console.log("---") Console.log("Intl.Locale") -let locale = Intl.Locale.make("en-US") +let _locale = Intl.Locale.make("en-US") let locale = Intl.Locale.makeWithOptions( "en-US", { diff --git a/test/intl/Intl__PluralRulesTest.res b/test/intl/Intl__PluralRulesTest.res index d8912521..4f56404c 100644 --- a/test/intl/Intl__PluralRulesTest.res +++ b/test/intl/Intl__PluralRulesTest.res @@ -3,15 +3,15 @@ open RescriptCore Console.log("---") Console.log("Intl.PluralRules") -let formatter = Intl.PluralRules.make() -let formatter = Intl.PluralRules.makeWithLocale("en-US") -let formatter = Intl.PluralRules.makeWithLocales(["en-US", "en-GB"]) -let formatter = Intl.PluralRules.makeWithOptions({ +let _formatter = Intl.PluralRules.make() +let _formatter = Intl.PluralRules.makeWithLocale("en-US") +let _formatter = Intl.PluralRules.makeWithLocales(["en-US", "en-GB"]) +let _formatter = Intl.PluralRules.makeWithOptions({ \"type": #ordinal, maximumSignificantDigits: #5, minimumSignificantDigits: #3, }) -let formatter = Intl.PluralRules.makeWithLocaleAndOptions( +let _formatter = Intl.PluralRules.makeWithLocaleAndOptions( "en-US", { \"type": #ordinal, diff --git a/test/intl/Intl__RelativeTimeFormatTest.res b/test/intl/Intl__RelativeTimeFormatTest.res index 4ba96df6..e8833d7c 100644 --- a/test/intl/Intl__RelativeTimeFormatTest.res +++ b/test/intl/Intl__RelativeTimeFormatTest.res @@ -9,14 +9,14 @@ Intl.RelativeTimeFormat.supportedLocalesOfWithOptions( {localeMatcher: #lookup}, )->ignore -let formatter = Intl.RelativeTimeFormat.make() -let formatter = Intl.RelativeTimeFormat.makeWithLocale("en-US") -let formatter = Intl.RelativeTimeFormat.makeWithLocales(["en-US", "en-GB"]) -let formatter = Intl.RelativeTimeFormat.makeWithOptions({ +let _formatter = Intl.RelativeTimeFormat.make() +let _formatter = Intl.RelativeTimeFormat.makeWithLocale("en-US") +let _formatter = Intl.RelativeTimeFormat.makeWithLocales(["en-US", "en-GB"]) +let _formatter = Intl.RelativeTimeFormat.makeWithOptions({ numeric: #always, style: #narrow, }) -let formatter = Intl.RelativeTimeFormat.makeWithLocaleAndOptions( +let _formatter = Intl.RelativeTimeFormat.makeWithLocaleAndOptions( "en-US", { numeric: #always, diff --git a/test/intl/Intl__SegmenterTest.res b/test/intl/Intl__SegmenterTest.res index 25d2caca..aaca4153 100644 --- a/test/intl/Intl__SegmenterTest.res +++ b/test/intl/Intl__SegmenterTest.res @@ -6,13 +6,13 @@ Console.log("Intl.Segmenter") Intl.Segmenter.supportedLocalesOf(["en-US", "en-GB"])->ignore Intl.Segmenter.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore -let formatter = Intl.Segmenter.make() -let formatter = Intl.Segmenter.makeWithLocale("en-US") -let formatter = Intl.Segmenter.makeWithLocales(["en-US", "en-GB"]) -let formatter = Intl.Segmenter.makeWithOptions({ +let _formatter = Intl.Segmenter.make() +let _formatter = Intl.Segmenter.makeWithLocale("en-US") +let _formatter = Intl.Segmenter.makeWithLocales(["en-US", "en-GB"]) +let _formatter = Intl.Segmenter.makeWithOptions({ granularity: #word, }) -let formatter = Intl.Segmenter.makeWithLocaleAndOptions( +let _formatter = Intl.Segmenter.makeWithLocaleAndOptions( "en-US", { granularity: #word,