Skip to content

Commit 43daa8c

Browse files
authored
fix(intl): expose Intl.Common types (#197)
* fix(intl): expose Intl.Common types * docs: update change log * chore: add js artifacts for tests
1 parent 1931b9c commit 43daa8c

12 files changed

+600
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Next version
44

5+
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
6+
57
## 1.1.0
68

79
- BREAKING: Align List api with other modules (`List.getBy` -> `List.find` etc.). https://github.com/rescript-association/rescript-core/pull/195

src/Core__Intl.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33

4+
var Common;
5+
46
var Collator;
57

68
var DateTimeFormat;
@@ -20,6 +22,7 @@ var Segmenter;
2022
var Segments;
2123

2224
export {
25+
Common ,
2326
Collator ,
2427
DateTimeFormat ,
2528
ListFormat ,

src/Core__Intl.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module Common = Core__Intl__Common
12
module Collator = Core__Intl__Collator
23
module DateTimeFormat = Core__Intl__DateTimeFormat
34
module ListFormat = Core__Intl__ListFormat

test/intl/IntlTests.mjs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as Js_exn from "rescript/lib/es6/js_exn.js";
4+
import * as Caml_option from "rescript/lib/es6/caml_option.js";
5+
import * as Core__Option from "../../src/Core__Option.mjs";
6+
import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs";
7+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
8+
import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs";
9+
import * as Intl__SegmenterTest from "./Intl__SegmenterTest.mjs";
10+
import * as Intl__ListFormatTest from "./Intl__ListFormatTest.mjs";
11+
import * as Intl__PluralRulesTest from "./Intl__PluralRulesTest.mjs";
12+
import * as Intl__NumberFormatTest from "./Intl__NumberFormatTest.mjs";
13+
import * as Intl__DateTimeFormatTest from "./Intl__DateTimeFormatTest.mjs";
14+
import * as Intl__RelativeTimeFormatTest from "./Intl__RelativeTimeFormatTest.mjs";
15+
16+
console.log("---");
17+
18+
console.log("Intl");
19+
20+
console.log(Intl.getCanonicalLocales("EN-US"));
21+
22+
console.log(Intl.getCanonicalLocales([
23+
"EN-US",
24+
"Fr"
25+
]));
26+
27+
try {
28+
console.log(Intl.getCanonicalLocales("bloop"));
29+
}
30+
catch (raw_e){
31+
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
32+
if (e.RE_EXN_ID === Js_exn.$$Error) {
33+
console.error(e._1);
34+
} else {
35+
throw e;
36+
}
37+
}
38+
39+
try {
40+
console.log(Intl.supportedValuesOf("calendar"));
41+
console.log(Intl.supportedValuesOf("collation"));
42+
console.log(Intl.supportedValuesOf("currency"));
43+
console.log(Intl.supportedValuesOf("numberingSystem"));
44+
console.log(Intl.supportedValuesOf("timeZone"));
45+
console.log(Intl.supportedValuesOf("unit"));
46+
}
47+
catch (raw_e$1){
48+
var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$1);
49+
if (e$1.RE_EXN_ID === Js_exn.$$Error) {
50+
console.error(e$1._1);
51+
} else {
52+
throw e$1;
53+
}
54+
}
55+
56+
try {
57+
Intl.supportedValuesOf("someInvalidKey");
58+
console.error("Shouldn't have been hit");
59+
}
60+
catch (raw_e$2){
61+
var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2);
62+
if (e$2.RE_EXN_ID === Js_exn.$$Error) {
63+
var e$3 = e$2._1;
64+
var message = Core__Option.map(e$3.message, (function (prim) {
65+
return prim.toLowerCase();
66+
}));
67+
var exit = 0;
68+
if (message === "invalid key : someinvalidkey") {
69+
console.log("Caught expected error");
70+
} else {
71+
exit = 1;
72+
}
73+
if (exit === 1) {
74+
console.warn("Unexpected error message: \"" + message + "\"");
75+
throw e$3;
76+
}
77+
78+
} else {
79+
var e$4 = Caml_js_exceptions.as_js_exn(e$2);
80+
if (e$4 !== undefined) {
81+
throw Caml_option.valFromOption(e$4);
82+
}
83+
console.error("Unexpected error");
84+
}
85+
}
86+
87+
var _collator = Intl__CollatorTest._collator;
88+
89+
var collator = Intl__CollatorTest.collator;
90+
91+
var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions;
92+
93+
var timeZone = Intl__DateTimeFormatTest.timeZone;
94+
95+
var _locale = Intl__LocaleTest._locale;
96+
97+
var locale = Intl__LocaleTest.locale;
98+
99+
var currencyFormatter = Intl__NumberFormatTest.currencyFormatter;
100+
101+
var roundingFormatter = Intl__NumberFormatTest.roundingFormatter;
102+
103+
var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1;
104+
105+
var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2;
106+
107+
var sigFormatter = Intl__NumberFormatTest.sigFormatter;
108+
109+
var options = Intl__NumberFormatTest.options;
110+
111+
var _formatter = Intl__SegmenterTest._formatter;
112+
113+
var formatter = Intl__SegmenterTest.formatter;
114+
115+
var segments = Intl__SegmenterTest.segments;
116+
117+
export {
118+
_collator ,
119+
collator ,
120+
resolvedOptions ,
121+
timeZone ,
122+
_locale ,
123+
locale ,
124+
currencyFormatter ,
125+
roundingFormatter ,
126+
groupingFormatter1 ,
127+
groupingFormatter2 ,
128+
sigFormatter ,
129+
options ,
130+
_formatter ,
131+
formatter ,
132+
segments ,
133+
}
134+
/* Not a pure module */

test/intl/Intl__CollatorTest.mjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
console.log("---");
5+
6+
console.log("Intl.Collator");
7+
8+
new Intl.Collator();
9+
10+
new Intl.Collator("en-US");
11+
12+
var _collator = new Intl.Collator([
13+
"en-US",
14+
"en-GB"
15+
]);
16+
17+
var collator = new Intl.Collator("en-US", {
18+
sensitivity: "base",
19+
ignorePunctuation: true,
20+
numeric: true,
21+
caseFirst: "upper"
22+
});
23+
24+
Intl.Collator.supportedLocalesOf([
25+
"en-US",
26+
"en-GB"
27+
]);
28+
29+
Intl.Collator.supportedLocalesOf([
30+
"en-US",
31+
"en-GB"
32+
], {
33+
localeMatcher: "lookup"
34+
});
35+
36+
console.log(collator.resolvedOptions());
37+
38+
console.log(collator.compare("hi", "hï"));
39+
40+
console.log(Intl.Collator.supportedLocalesOf(["hi"]));
41+
42+
export {
43+
_collator ,
44+
collator ,
45+
}
46+
/* Not a pure module */
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
4+
5+
console.log("---");
6+
7+
console.log("Intl.DateTimeFormat");
8+
9+
Intl.DateTimeFormat.supportedLocalesOf([
10+
"en-US",
11+
"en-GB"
12+
]);
13+
14+
Intl.DateTimeFormat.supportedLocalesOf([
15+
"en-US",
16+
"en-GB"
17+
], {
18+
localeMatcher: "lookup"
19+
});
20+
21+
var formatter = new Intl.DateTimeFormat(undefined, {
22+
dateStyle: "full",
23+
timeStyle: "full"
24+
});
25+
26+
console.log(formatter.format(new Date(Date.now())));
27+
28+
console.log(formatter.formatRange(new Date(2023, 1, 1), new Date(2023, 12, 31)));
29+
30+
var options = {
31+
timeZone: "UTC",
32+
hour12: false,
33+
hourCycle: "h24",
34+
weekday: "narrow",
35+
era: "narrow",
36+
year: "2-digit",
37+
month: "2-digit",
38+
day: "2-digit",
39+
hour: "2-digit",
40+
minute: "2-digit",
41+
second: "2-digit",
42+
fractionalSecondDigits: 3,
43+
timeZoneName: "longGeneric"
44+
};
45+
46+
var formatter$1 = new Intl.DateTimeFormat(undefined, options);
47+
48+
console.log(formatter$1.format(new Date(Date.now())));
49+
50+
var newrecord = Caml_obj.obj_dup(options);
51+
52+
var formatter$2 = new Intl.DateTimeFormat(undefined, (newrecord.timeZoneName = "long", newrecord));
53+
54+
console.log(formatter$2.format(new Date(Date.now())));
55+
56+
var newrecord$1 = Caml_obj.obj_dup(options);
57+
58+
var formatter$3 = new Intl.DateTimeFormat(undefined, (newrecord$1.timeZoneName = "longOffset", newrecord$1));
59+
60+
console.log(formatter$3.format(new Date(Date.now())));
61+
62+
var newrecord$2 = Caml_obj.obj_dup(options);
63+
64+
var formatter$4 = new Intl.DateTimeFormat(undefined, (newrecord$2.timeZoneName = "short", newrecord$2));
65+
66+
console.log(formatter$4.format(new Date(Date.now())));
67+
68+
var newrecord$3 = Caml_obj.obj_dup(options);
69+
70+
var formatter$5 = new Intl.DateTimeFormat(undefined, (newrecord$3.timeZoneName = "shortGeneric", newrecord$3));
71+
72+
console.log(formatter$5.format(new Date(Date.now())));
73+
74+
var newrecord$4 = Caml_obj.obj_dup(options);
75+
76+
var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName = "shortOffset", newrecord$4));
77+
78+
console.log(formatter$6.format(new Date(Date.now())));
79+
80+
var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions();
81+
82+
var timeZone = resolvedOptions.timeZone;
83+
84+
export {
85+
options ,
86+
formatter$6 as formatter,
87+
resolvedOptions ,
88+
timeZone ,
89+
}
90+
/* Not a pure module */

test/intl/Intl__ListFormatTest.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
console.log("---");
5+
6+
console.log("Intl.ListFormat");
7+
8+
new Intl.ListFormat();
9+
10+
new Intl.ListFormat("en-US");
11+
12+
new Intl.ListFormat([
13+
"en-US",
14+
"en-GB"
15+
]);
16+
17+
new Intl.ListFormat("en-US", {
18+
type: "conjunction",
19+
style: "long"
20+
});
21+
22+
var _formatter = new Intl.ListFormat([
23+
"en-US",
24+
"en-GB"
25+
], {
26+
type: "conjunction",
27+
style: "long"
28+
});
29+
30+
Intl.ListFormat.supportedLocalesOf([
31+
"en-US",
32+
"en-GB"
33+
]);
34+
35+
Intl.ListFormat.supportedLocalesOf([
36+
"en-US",
37+
"en-GB"
38+
], {
39+
localeMatcher: "lookup"
40+
});
41+
42+
var formatter = new Intl.ListFormat(undefined, {
43+
type: "conjunction",
44+
style: "long"
45+
});
46+
47+
console.log(formatter.resolvedOptions());
48+
49+
console.log(formatter.format([
50+
"one",
51+
"two",
52+
"three"
53+
]));
54+
55+
console.log(formatter.formatToParts([
56+
"one",
57+
"two",
58+
"three"
59+
]));
60+
61+
export {
62+
_formatter ,
63+
formatter ,
64+
}
65+
/* Not a pure module */

0 commit comments

Comments
 (0)