Skip to content

Commit 40431ec

Browse files
committed
Simplify constructors for Intl types
1 parent 248cfc5 commit 40431ec

25 files changed

+118
-204
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next version
44

5+
- BREAKING: Intl types: simplify bindings for constructors / functions with optional arguments. https://github.com/rescript-association/rescript-core/pull/198
56
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
67

78
## 1.1.0

src/intl/Core__Intl__Collator.res

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@ type resolvedOptions = {
2525

2626
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
2727

28-
@new external make: unit => t = "Intl.Collator"
29-
@new external makeWithLocale: string => t = "Intl.Collator"
30-
@new external makeWithLocales: array<string> => 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"
34-
35-
@val external supportedLocalesOf: array<string> => t = "Intl.Collator.supportedLocalesOf"
28+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Collator"
29+
3630
@val
37-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
31+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
3832
"Intl.Collator.supportedLocalesOf"
3933

4034
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__DateTimeFormat.res

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,10 @@ type dateTimeRangePart = {
105105
source: dateTimeRangeSource,
106106
}
107107

108-
@new external make: unit => t = "Intl.DateTimeFormat"
109-
@new external makeWithLocale: string => t = "Intl.DateTimeFormat"
110-
@new external makeWithLocales: array<string> => t = "Intl.DateTimeFormat"
111-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.DateTimeFormat"
112-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.DateTimeFormat"
113-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.DateTimeFormat"
108+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.DateTimeFormat"
114109

115-
@val external supportedLocalesOf: array<string> => t = "Intl.DateTimeFormat.supportedLocalesOf"
116110
@val
117-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
111+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
118112
"Intl.DateTimeFormat.supportedLocalesOf"
119113

120114
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__ListFormat.res

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@ type resolvedOptions = {
3535

3636
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
3737

38-
@new external make: unit => t = "Intl.ListFormat"
39-
@new external makeWithLocale: string => t = "Intl.ListFormat"
40-
@new external makeWithLocales: array<string> => t = "Intl.ListFormat"
41-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.ListFormat"
42-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.ListFormat"
43-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.ListFormat"
44-
45-
@val external supportedLocalesOf: array<string> => t = "Intl.ListFormat.supportedLocalesOf"
38+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.ListFormat"
39+
4640
@val
47-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
41+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
4842
"Intl.ListFormat.supportedLocalesOf"
4943

5044
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__Locale.res

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ type options = {
1313
region?: string,
1414
}
1515

16-
@new external make: string => t = "Intl.Locale"
17-
@new external makeWithOptions: (string, options) => t = "Intl.Locale"
16+
@new external make: (string, ~options: options=?) => t = "Intl.Locale"
1817

1918
@get external baseName: t => string = "baseName"
2019
@get external calendar: t => option<string> = "calendar"

src/intl/Core__Intl__NumberFormat.res

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,10 @@ type numberFormatRangePart = {
166166
source: rangeSource,
167167
}
168168

169-
@new external make: unit => t = "Intl.NumberFormat"
170-
@new external makeWithLocale: string => t = "Intl.NumberFormat"
171-
@new external makeWithLocales: array<string> => t = "Intl.NumberFormat"
172-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.NumberFormat"
173-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.NumberFormat"
174-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.NumberFormat"
175-
176-
@val external supportedLocalesOf: array<string> => t = "Intl.NumberFormat.supportedLocalesOf"
169+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.NumberFormat"
177170

178171
@val
179-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
172+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
180173
"Intl.NumberFormat.supportedLocalesOf"
181174

182175
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__PluralRules.res

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ type resolvedOptions = {
3838

3939
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
4040

41-
@new external make: unit => t = "Intl.PluralRules"
42-
@new external makeWithLocale: string => t = "Intl.PluralRules"
43-
@new external makeWithLocales: array<string> => t = "Intl.PluralRules"
44-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.PluralRules"
45-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.PluralRules"
46-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.PluralRules"
41+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.PluralRules"
4742

48-
@val external supportedLocalesOf: array<string> => t = "Intl.PluralRules.supportedLocalesOf"
4943
@val
50-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
44+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
5145
"Intl.PluralRules.supportedLocalesOf"
5246

5347
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__RelativeTimeFormat.res

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,11 @@ type relativeTimePart = {
2626
unit?: timeUnit,
2727
}
2828

29-
@new external make: unit => t = "Intl.RelativeTimeFormat"
30-
@new external makeWithLocale: string => t = "Intl.RelativeTimeFormat"
31-
@new external makeWithLocales: array<string> => t = "Intl.RelativeTimeFormat"
32-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.RelativeTimeFormat"
33-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.RelativeTimeFormat"
34-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.RelativeTimeFormat"
29+
@new
30+
external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.RelativeTimeFormat"
3531

3632
@val
37-
external supportedLocalesOf: array<string> => t = "Intl.RelativeTimeFormat.supportedLocalesOf"
38-
@val
39-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
33+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
4034
"Intl.RelativeTimeFormat.supportedLocalesOf"
4135

4236
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

src/intl/Core__Intl__Segmenter.res

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ type resolvedOptions = {locale: string, granularity: granularity}
2323

2424
type supportedLocalesOptions = {localeMatcher: Core__Intl__Common.localeMatcher}
2525

26-
@new external make: unit => t = "Intl.Segmenter"
27-
@new external makeWithLocale: string => t = "Intl.Segmenter"
28-
@new external makeWithLocales: array<string> => t = "Intl.Segmenter"
29-
@new external makeWithLocaleAndOptions: (string, options) => t = "Intl.Segmenter"
30-
@new external makeWithLocalesAndOptions: (array<string>, options) => t = "Intl.Segmenter"
31-
@new external makeWithOptions: (@as(json`undefined`) _, options) => t = "Intl.Segmenter"
32-
33-
@val external supportedLocalesOf: array<string> => t = "Intl.Segmenter.supportedLocalesOf"
26+
@new external make: (~locales: array<string>=?, ~options: options=?) => t = "Intl.Segmenter"
27+
3428
@val
35-
external supportedLocalesOfWithOptions: (array<string>, supportedLocalesOptions) => t =
29+
external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?) => t =
3630
"Intl.Segmenter.supportedLocalesOf"
3731

3832
@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

test/intl/Intl__CollatorTest.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ console.log("---");
55

66
console.log("Intl.Collator");
77

8-
new Intl.Collator();
8+
new Intl.Collator(undefined, undefined);
99

10-
new Intl.Collator("en-US");
10+
new Intl.Collator(["en-US"], undefined);
1111

1212
var _collator = new Intl.Collator([
1313
"en-US",
1414
"en-GB"
15-
]);
15+
], undefined);
1616

17-
var collator = new Intl.Collator("en-US", {
17+
var collator = new Intl.Collator(["en-US"], {
1818
sensitivity: "base",
1919
ignorePunctuation: true,
2020
numeric: true,
@@ -24,7 +24,7 @@ var collator = new Intl.Collator("en-US", {
2424
Intl.Collator.supportedLocalesOf([
2525
"en-US",
2626
"en-GB"
27-
]);
27+
], undefined);
2828

2929
Intl.Collator.supportedLocalesOf([
3030
"en-US",
@@ -37,7 +37,7 @@ console.log(collator.resolvedOptions());
3737

3838
console.log(collator.compare("hi", "hï"));
3939

40-
console.log(Intl.Collator.supportedLocalesOf(["hi"]));
40+
console.log(Intl.Collator.supportedLocalesOf(["hi"], undefined));
4141

4242
export {
4343
_collator ,

0 commit comments

Comments
 (0)