Skip to content

Commit 55cb16d

Browse files
committed
feat(Intl.NumberFormat): strongly typed options
1 parent bc18ff7 commit 55cb16d

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/intl/Core__Intl__NumberFormat.res

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
type t
22

3+
type options = {
4+
localeMathcer?: [#lookup | #"best fit"],
5+
numberingSystem?: string,
6+
compactDisplay?: [#compact | #short | #long],
7+
currency?: string,
8+
currencyDisplay?: [#symbol | #narrowSymbol | #code | #name],
9+
currencySign?: [#standard | #accounting],
10+
notation?: [#standard | #scientific | #engineering | #compact],
11+
signDisplay?: [#auto | #always | #exceptZero | #negative | #never],
12+
style?: [#decimal | #currency | #percent | #unit],
13+
unit?: string,
14+
unitDisplay?: [#long | #short | #narrow],
15+
useGrouping?: bool, // TODO: also [#always | #auto | #min2]
16+
roundingMode?: [
17+
| #ceil
18+
| #floot
19+
| #expand
20+
| #trunc
21+
| #halfCeil
22+
| #halfFloor
23+
| #haldExpand
24+
| #halfTrunc
25+
| #halfEven
26+
],
27+
roundingPriority?: [#auto | #morePrecision | #lessPrecision],
28+
roundingIncrement?: int,
29+
trailingZeroDisplay?: [#auto | #stripIfInteger],
30+
minimumIntegerDigits?: int,
31+
minimumFractionDigits?: int,
32+
maximumFractionDigits?: int,
33+
minimumSignificantDigits?: int,
34+
maximumSignificantDigits?: int,
35+
}
36+
337
@new external make: unit => t = "Intl.NumberFormat"
438
@new external makeWithLocale: string => t = "Intl.NumberFormat"
539
@new external makeWithLocales: array<string> => t = "Intl.NumberFormat"
6-
@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.NumberFormat"
7-
@new external makeWithLocalesAndOptions: (array<string>, {..}) => t = "Intl.NumberFormat"
8-
@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.NumberFormat"
40+
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.NumberFormat"
41+
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.NumberFormat"
42+
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.NumberFormat"
943

1044
@val external supportedLocalesOf: array<string> => t = "Intl.NumberFormat.supportedLocalesOf"
1145
@val
12-
external supportedLocalesOfWithOptions: (array<string>, {..}) => t =
46+
external supportedLocalesOfWithOptions: (array<string>, options) => t =
1347
"Intl.NumberFormat.supportedLocalesOf"
1448

15-
@send external resolvedOptions: t => {..} = "resolvedOptions"
49+
@send external resolvedOptions: t => options = "resolvedOptions"
1650

1751
@send external format: (t, float) => string = "format"
1852
@send

test/TempTests.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Console.info("Intl")
4646
Console.info("---")
4747
let currencyFormatter = Intl.NumberFormat.makeWithLocaleAndOptions(
4848
"fr-FR",
49-
{"currency": "EUR", "style": "currency"},
49+
{currency: "EUR", style: #currency},
5050
)
5151

5252
Console.log(Intl.NumberFormat.supportedLocalesOf(["fr-FR", "en-US"]))

0 commit comments

Comments
 (0)