Skip to content

Commit 8a425e7

Browse files
committed
Simplify constructors for Intl types
1 parent 248cfc5 commit 8a425e7

24 files changed

+117
-204
lines changed

src/intl/Core__Intl__Collator.res

+3-9
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

+2-8
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

+3-9
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

+1-2
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

+2-9
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

+2-8
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

+3-9
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

+3-9
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

+6-6
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 ,

test/intl/Intl__CollatorTest.res

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Console.log("---")
44
Console.log("Intl.Collator")
55

66
let _collator = Intl.Collator.make()
7-
let _collator = Intl.Collator.makeWithLocale("en-US")
8-
let _collator = Intl.Collator.makeWithLocales(["en-US", "en-GB"])
9-
let collator = Intl.Collator.makeWithLocaleAndOptions(
10-
"en-US",
11-
{caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true},
7+
let _collator = Intl.Collator.make(~locales=["en-US"])
8+
let _collator = Intl.Collator.make(~locales=["en-US", "en-GB"])
9+
let collator = Intl.Collator.make(
10+
~locales=["en-US"],
11+
~options={caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true},
1212
)
1313
Intl.Collator.supportedLocalesOf(["en-US", "en-GB"])->ignore
14-
Intl.Collator.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore
14+
Intl.Collator.supportedLocalesOf(["en-US", "en-GB"], ~options={localeMatcher: #lookup})->ignore
1515

1616
collator->Intl.Collator.resolvedOptions->Console.log
1717
collator->Intl.Collator.compare("hi", "hï")->Console.log

test/intl/Intl__DateTimeFormatTest.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ console.log("Intl.DateTimeFormat");
99
Intl.DateTimeFormat.supportedLocalesOf([
1010
"en-US",
1111
"en-GB"
12-
]);
12+
], undefined);
1313

1414
Intl.DateTimeFormat.supportedLocalesOf([
1515
"en-US",
@@ -77,7 +77,7 @@ var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName =
7777

7878
console.log(formatter$6.format(new Date(Date.now())));
7979

80-
var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions();
80+
var resolvedOptions = new Intl.DateTimeFormat(undefined, undefined).resolvedOptions();
8181

8282
var timeZone = resolvedOptions.timeZone;
8383

test/intl/Intl__DateTimeFormatTest.res

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Console.log("---")
44
Console.log("Intl.DateTimeFormat")
55

66
Intl.DateTimeFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore
7-
Intl.DateTimeFormat.supportedLocalesOfWithOptions(
7+
Intl.DateTimeFormat.supportedLocalesOf(
88
["en-US", "en-GB"],
9-
{localeMatcher: #lookup},
9+
~options={localeMatcher: #lookup},
1010
)->ignore
1111

12-
let formatter = Intl.DateTimeFormat.makeWithOptions({dateStyle: #full, timeStyle: #full})
12+
let formatter = Intl.DateTimeFormat.make(~options={dateStyle: #full, timeStyle: #full})
1313

1414
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
1515

@@ -35,23 +35,23 @@ let options: Intl.DateTimeFormat.options = {
3535
fractionalSecondDigits: #3,
3636
timeZoneName: #longGeneric,
3737
}
38-
let formatter = Intl.DateTimeFormat.makeWithOptions(options)
38+
let formatter = Intl.DateTimeFormat.make(~options)
3939

4040
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
4141

42-
let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #long})
42+
let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #long})
4343
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
4444

45-
let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #longOffset})
45+
let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #longOffset})
4646
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
4747

48-
let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #short})
48+
let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #short})
4949
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
5050

51-
let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #shortGeneric})
51+
let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #shortGeneric})
5252
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
5353

54-
let formatter = Intl.DateTimeFormat.makeWithOptions({...options, timeZoneName: #shortOffset})
54+
let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #shortOffset})
5555
Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now())))
5656

5757
let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions

test/intl/Intl__ListFormatTest.mjs

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ console.log("---");
55

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

8-
new Intl.ListFormat();
9-
10-
new Intl.ListFormat("en-US");
8+
new Intl.ListFormat(undefined, undefined);
119

1210
new Intl.ListFormat([
1311
"en-US",
1412
"en-GB"
15-
]);
16-
17-
new Intl.ListFormat("en-US", {
18-
type: "conjunction",
19-
style: "long"
20-
});
13+
], undefined);
2114

2215
var _formatter = new Intl.ListFormat([
2316
"en-US",
@@ -30,7 +23,7 @@ var _formatter = new Intl.ListFormat([
3023
Intl.ListFormat.supportedLocalesOf([
3124
"en-US",
3225
"en-GB"
33-
]);
26+
], undefined);
3427

3528
Intl.ListFormat.supportedLocalesOf([
3629
"en-US",

test/intl/Intl__ListFormatTest.res

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ Console.log("---")
44
Console.log("Intl.ListFormat")
55

66
let _formatter = Intl.ListFormat.make()
7-
let _formatter = Intl.ListFormat.makeWithLocale("en-US")
8-
let _formatter = Intl.ListFormat.makeWithLocales(["en-US", "en-GB"])
9-
let _formatter = Intl.ListFormat.makeWithLocaleAndOptions(
10-
"en-US",
11-
{style: #long, \"type": #conjunction},
12-
)
13-
let _formatter = Intl.ListFormat.makeWithLocalesAndOptions(
14-
["en-US", "en-GB"],
15-
{style: #long, \"type": #conjunction},
7+
let _formatter = Intl.ListFormat.make(~locales=["en-US", "en-GB"])
8+
let _formatter = Intl.ListFormat.make(
9+
~locales=["en-US", "en-GB"],
10+
~options={style: #long, \"type": #conjunction},
1611
)
1712
Intl.ListFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore
18-
Intl.ListFormat.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore
13+
Intl.ListFormat.supportedLocalesOf(["en-US", "en-GB"], ~options={localeMatcher: #lookup})->ignore
1914

20-
let formatter = Intl.ListFormat.makeWithOptions({style: #long, \"type": #conjunction})
15+
let formatter = Intl.ListFormat.make(~options={style: #long, \"type": #conjunction})
2116

2217
formatter->Intl.ListFormat.resolvedOptions->Console.log
2318
formatter->Intl.ListFormat.format(["one", "two", "three"])->Console.log

test/intl/Intl__LocaleTest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ console.log("---");
55

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

8-
var _locale = new Intl.Locale("en-US");
8+
var _locale = new Intl.Locale("en-US", undefined);
99

1010
var locale = new Intl.Locale("en-US", {
1111
calendar: "hebrew",

test/intl/Intl__LocaleTest.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Console.log("---")
44
Console.log("Intl.Locale")
55

66
let _locale = Intl.Locale.make("en-US")
7-
let locale = Intl.Locale.makeWithOptions(
7+
let locale = Intl.Locale.make(
88
"en-US",
9-
{
9+
~options={
1010
calendar: #hebrew,
1111
collation: #compat,
1212
hourCycle: #h24,

test/intl/Intl__NumberFormatTest.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ console.log("---");
77

88
console.log("Intl.NumberFormat");
99

10-
var currencyFormatter = new Intl.NumberFormat("fr-FR", {
10+
var currencyFormatter = new Intl.NumberFormat(["fr-FR"], {
1111
currency: "EUR",
1212
style: "currency"
1313
});
1414

1515
console.log(Intl.NumberFormat.supportedLocalesOf([
1616
"fr-FR",
1717
"en-US"
18-
]));
18+
], undefined));
1919

2020
console.log(currencyFormatter.format(123.23));
2121

0 commit comments

Comments
 (0)