Skip to content

Commit 09ca99b

Browse files
Stricter Intl Bindings (rescript-lang#65)
* feat: common Intl polymorphic variants * feat: type-safe Intl.NumberFormat bindings * feat: Intl.DateTimeFormat options * feat: Intl.Collator * feat: Intl.ListFormat * feat: Intl.RelativeTimeFormat * feat: Intl.Segmenter * feat: Intl.Locale * feat: Intl.getCanonicalLocales & supportedValuesOf * feat: tests * feat: grouping parse * feat: Intl.PluralRules * case-sensitive :( * fix type error in node 20+ tests * docs: add changelog entry * cleanup: remove firefox v110 comments * docs: add node runtime comment * fix tests
1 parent 25aa2a6 commit 09ca99b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1778
-81
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next version
44

55
- BREAKING: Fixes the type of `RegExp.Result.t` to be `array<option<string>>` instead of `array<string>`. https://github.com/rescript-association/rescript-core/pull/233.
6+
- BREAKING: Adds typed bindings to `Intl`, replacing the options type of `{..}` with records. https://github.com/rescript-association/rescript-core/pull/65
67
- Add `Dict.forEach`, `Dict.forEachWithKey` and `Dict.mapValues` https://github.com/rescript-association/rescript-core/pull/181
78
- Remove internal xxxU helper functions that are not needed anymore in uncurried mode. https://github.com/rescript-association/rescript-core/pull/191
89
- Rename `Object.empty` to `Object.make` for consistency.

bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
{
1010
"dir": "test",
11+
"subdirs": ["intl"],
1112
"type": "dev"
1213
}
1314
],

src/Core__Intl.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var Collator;
55

66
var DateTimeFormat;
77

8+
var ListFormat;
9+
810
var Locale;
911

1012
var NumberFormat;
@@ -13,12 +15,19 @@ var PluralRules;
1315

1416
var RelativeTimeFormat;
1517

18+
var Segmenter;
19+
20+
var Segments;
21+
1622
export {
1723
Collator ,
1824
DateTimeFormat ,
25+
ListFormat ,
1926
Locale ,
2027
NumberFormat ,
2128
PluralRules ,
2229
RelativeTimeFormat ,
30+
Segmenter ,
31+
Segments ,
2332
}
2433
/* No side effect */

src/Core__Intl.res

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
module Collator = Core__Intl__Collator
22
module DateTimeFormat = Core__Intl__DateTimeFormat
3+
module ListFormat = Core__Intl__ListFormat
34
module Locale = Core__Intl__Locale
45
module NumberFormat = Core__Intl__NumberFormat
56
module PluralRules = Core__Intl__PluralRules
67
module RelativeTimeFormat = Core__Intl__RelativeTimeFormat
8+
module Segmenter = Core__Intl__Segmenter
9+
module Segments = Core__Intl__Segments
10+
11+
/**
12+
@throws RangeError
13+
*/
14+
external getCanonicalLocalesExn: string => array<string> = "Intl.getCanonicalLocales"
15+
16+
/**
17+
@throws RangeError
18+
*/
19+
external getCanonicalLocalesManyExn: array<string> => array<string> = "Intl.getCanonicalLocales"
20+
21+
/**
22+
@throws RangeError
23+
*/
24+
external supportedValuesOfExn: string => array<string> = "Intl.supportedValuesOf"

src/intl/Core__Intl__Collator.res

+30-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
type t
22

3+
type usage = [#sort | #search]
4+
type sensitivity = [#base | #accent | #case | #variant]
5+
type caseFirst = [#upper | #lower | #"false"]
6+
7+
type options = {
8+
localeMatcher?: Core__Intl__Common.localeMatcher,
9+
usage?: usage,
10+
sensitivity?: sensitivity,
11+
ignorePunctuation?: bool,
12+
numeric?: bool,
13+
caseFirst?: caseFirst,
14+
}
15+
16+
type resolvedOptions = {
17+
locale: string,
18+
usage: usage,
19+
sensitivity: sensitivity,
20+
ignorePunctuation: bool,
21+
collation: [Core__Intl__Common.collation | #default],
22+
numeric?: bool,
23+
caseFirst?: caseFirst,
24+
}
25+
26+
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
27+
328
@new external make: unit => t = "Intl.Collator"
429
@new external makeWithLocale: string => t = "Intl.Collator"
530
@new external makeWithLocales: array<string> => t = "Intl.Collator"
6-
@new external makeWithLocaleAndOptions: (string, {..}) => t = "Intl.Collator"
7-
@new external makeWithLocalesAndOptions: (array<string>, {..}) => t = "Intl.Collator"
8-
@new external makeWithOptions: (@as(json`undefined`) _, {..}) => t = "Intl.Collator"
31+
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.Collator"
32+
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.Collator"
33+
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Collator"
934

1035
@val external supportedLocalesOf: array<string> => t = "Intl.Collator.supportedLocalesOf"
1136
@val
12-
external supportedLocalesOfWithOptions: (array<string>, {..}) => t =
37+
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
1338
"Intl.Collator.supportedLocalesOf"
1439

15-
@send external resolvedOptions: t => {..} = "resolvedOptions"
40+
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"
1641

1742
@send external compare: (t, string, string) => int = "compare"

src/intl/Core__Intl__Common.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

src/intl/Core__Intl__Common.res

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
type localeMatcher = [#lookup | @as("best fit") #bestFit]
2+
3+
type calendar = [
4+
| #buddhist
5+
| #chinese
6+
| #coptic
7+
| #dangi
8+
| #ethioaa
9+
| #ethiopic
10+
| #gregory
11+
| #hebrew
12+
| #indian
13+
| #islamic
14+
| #"islamic-umalqura"
15+
| #"islamic-tbla"
16+
| #"islamic-civil"
17+
| #"islamic-rgsa"
18+
| #iso8601
19+
| #japanese
20+
| #persian
21+
| #roc
22+
]
23+
24+
type collation = [
25+
| #compat // (Arabic)
26+
| #dict // (Sinhala)
27+
| #emoji // (root)
28+
| #eor // (root)
29+
| #phonebk // (German)
30+
| #phonetic // (Lingala)
31+
| #pinyin // (Chinese)
32+
| #stroke // (Chinese)
33+
| #trad
34+
| #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge)
35+
| #zhuyin
36+
] // (Chinese)
37+
38+
type numberingSystem = [
39+
| #adlm
40+
| #ahom
41+
| #arab
42+
| #arabext
43+
| #bali
44+
| #beng
45+
| #bhks
46+
| #brah
47+
| #cakm
48+
| #cham
49+
| #deva
50+
| #diak
51+
| #fullwide
52+
| #gong
53+
| #gonm
54+
| #gujr
55+
| #guru
56+
| #hanidec
57+
| #hmng
58+
| #hmnp
59+
| #java
60+
| #kali
61+
| #kawi
62+
| #khmr
63+
| #knda
64+
| #lana
65+
| #lanatham
66+
| #laoo
67+
| #latn
68+
| #lepc
69+
| #limb
70+
| #mathbold
71+
| #mathdbl
72+
| #mathmono
73+
| #mathsanb
74+
| #mathsans
75+
| #mlym
76+
| #modi
77+
| #mong
78+
| #mroo
79+
| #mtei
80+
| #mymr
81+
| #mymrshan
82+
| #mymrtlng
83+
| #nagm
84+
| #newa
85+
| #nkoo
86+
| #olck
87+
| #orya
88+
| #osma
89+
| #rohg
90+
| #saur
91+
| #segment
92+
| #shrd
93+
| #sind
94+
| #sinh
95+
| #sora
96+
| #sund
97+
| #takr
98+
| #talu
99+
| #tamldec
100+
| #telu
101+
| #thai
102+
| #tibt
103+
| #tirh
104+
| #tnsa
105+
| #vaii
106+
| #wara
107+
| #wcho
108+
]
109+
110+
type oneTo21 = [
111+
| #1
112+
| #2
113+
| #3
114+
| #4
115+
| #5
116+
| #6
117+
| #7
118+
| #8
119+
| #9
120+
| #10
121+
| #11
122+
| #12
123+
| #13
124+
| #14
125+
| #15
126+
| #16
127+
| #17
128+
| #18
129+
| #19
130+
| #20
131+
| #21
132+
]
133+
134+
type zeroTo20 = [
135+
| #0
136+
| #1
137+
| #2
138+
| #3
139+
| #4
140+
| #5
141+
| #6
142+
| #7
143+
| #8
144+
| #9
145+
| #10
146+
| #11
147+
| #12
148+
| #13
149+
| #14
150+
| #15
151+
| #16
152+
| #17
153+
| #18
154+
| #19
155+
| #20
156+
]

0 commit comments

Comments
 (0)