Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(intl): expose Intl.Common types #197

Merged
merged 3 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Next version

- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197

## 1.1.0

- BREAKING: Align List api with other modules (`List.getBy` -> `List.find` etc.). https://github.com/rescript-association/rescript-core/pull/195
Expand Down
3 changes: 3 additions & 0 deletions src/Core__Intl.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


var Common;

var Collator;

var DateTimeFormat;
Expand All @@ -20,6 +22,7 @@ var Segmenter;
var Segments;

export {
Common ,
Collator ,
DateTimeFormat ,
ListFormat ,
Expand Down
1 change: 1 addition & 0 deletions src/Core__Intl.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Common = Core__Intl__Common
module Collator = Core__Intl__Collator
module DateTimeFormat = Core__Intl__DateTimeFormat
module ListFormat = Core__Intl__ListFormat
Expand Down
134 changes: 134 additions & 0 deletions test/intl/IntlTests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Js_exn from "rescript/lib/es6/js_exn.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as Core__Option from "../../src/Core__Option.mjs";
import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs";
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs";
import * as Intl__SegmenterTest from "./Intl__SegmenterTest.mjs";
import * as Intl__ListFormatTest from "./Intl__ListFormatTest.mjs";
import * as Intl__PluralRulesTest from "./Intl__PluralRulesTest.mjs";
import * as Intl__NumberFormatTest from "./Intl__NumberFormatTest.mjs";
import * as Intl__DateTimeFormatTest from "./Intl__DateTimeFormatTest.mjs";
import * as Intl__RelativeTimeFormatTest from "./Intl__RelativeTimeFormatTest.mjs";

console.log("---");

console.log("Intl");

console.log(Intl.getCanonicalLocales("EN-US"));

console.log(Intl.getCanonicalLocales([
"EN-US",
"Fr"
]));

try {
console.log(Intl.getCanonicalLocales("bloop"));
}
catch (raw_e){
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
if (e.RE_EXN_ID === Js_exn.$$Error) {
console.error(e._1);
} else {
throw e;
}
}

try {
console.log(Intl.supportedValuesOf("calendar"));
console.log(Intl.supportedValuesOf("collation"));
console.log(Intl.supportedValuesOf("currency"));
console.log(Intl.supportedValuesOf("numberingSystem"));
console.log(Intl.supportedValuesOf("timeZone"));
console.log(Intl.supportedValuesOf("unit"));
}
catch (raw_e$1){
var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$1);
if (e$1.RE_EXN_ID === Js_exn.$$Error) {
console.error(e$1._1);
} else {
throw e$1;
}
}

try {
Intl.supportedValuesOf("someInvalidKey");
console.error("Shouldn't have been hit");
}
catch (raw_e$2){
var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2);
if (e$2.RE_EXN_ID === Js_exn.$$Error) {
var e$3 = e$2._1;
var message = Core__Option.map(e$3.message, (function (prim) {
return prim.toLowerCase();
}));
var exit = 0;
if (message === "invalid key : someinvalidkey") {
console.log("Caught expected error");
} else {
exit = 1;
}
if (exit === 1) {
console.warn("Unexpected error message: \"" + message + "\"");
throw e$3;
}

} else {
var e$4 = Caml_js_exceptions.as_js_exn(e$2);
if (e$4 !== undefined) {
throw Caml_option.valFromOption(e$4);
}
console.error("Unexpected error");
}
}

var _collator = Intl__CollatorTest._collator;

var collator = Intl__CollatorTest.collator;

var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions;

var timeZone = Intl__DateTimeFormatTest.timeZone;

var _locale = Intl__LocaleTest._locale;

var locale = Intl__LocaleTest.locale;

var currencyFormatter = Intl__NumberFormatTest.currencyFormatter;

var roundingFormatter = Intl__NumberFormatTest.roundingFormatter;

var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1;

var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2;

var sigFormatter = Intl__NumberFormatTest.sigFormatter;

var options = Intl__NumberFormatTest.options;

var _formatter = Intl__SegmenterTest._formatter;

var formatter = Intl__SegmenterTest.formatter;

var segments = Intl__SegmenterTest.segments;

export {
_collator ,
collator ,
resolvedOptions ,
timeZone ,
_locale ,
locale ,
currencyFormatter ,
roundingFormatter ,
groupingFormatter1 ,
groupingFormatter2 ,
sigFormatter ,
options ,
_formatter ,
formatter ,
segments ,
}
/* Not a pure module */
46 changes: 46 additions & 0 deletions test/intl/Intl__CollatorTest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


console.log("---");

console.log("Intl.Collator");

new Intl.Collator();

new Intl.Collator("en-US");

var _collator = new Intl.Collator([
"en-US",
"en-GB"
]);

var collator = new Intl.Collator("en-US", {
sensitivity: "base",
ignorePunctuation: true,
numeric: true,
caseFirst: "upper"
});

Intl.Collator.supportedLocalesOf([
"en-US",
"en-GB"
]);

Intl.Collator.supportedLocalesOf([
"en-US",
"en-GB"
], {
localeMatcher: "lookup"
});

console.log(collator.resolvedOptions());

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

console.log(Intl.Collator.supportedLocalesOf(["hi"]));

export {
_collator ,
collator ,
}
/* Not a pure module */
90 changes: 90 additions & 0 deletions test/intl/Intl__DateTimeFormatTest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Caml_obj from "rescript/lib/es6/caml_obj.js";

console.log("---");

console.log("Intl.DateTimeFormat");

Intl.DateTimeFormat.supportedLocalesOf([
"en-US",
"en-GB"
]);

Intl.DateTimeFormat.supportedLocalesOf([
"en-US",
"en-GB"
], {
localeMatcher: "lookup"
});

var formatter = new Intl.DateTimeFormat(undefined, {
dateStyle: "full",
timeStyle: "full"
});

console.log(formatter.format(new Date(Date.now())));

console.log(formatter.formatRange(new Date(2023, 1, 1), new Date(2023, 12, 31)));

var options = {
timeZone: "UTC",
hour12: false,
hourCycle: "h24",
weekday: "narrow",
era: "narrow",
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 3,
timeZoneName: "longGeneric"
};

var formatter$1 = new Intl.DateTimeFormat(undefined, options);

console.log(formatter$1.format(new Date(Date.now())));

var newrecord = Caml_obj.obj_dup(options);

var formatter$2 = new Intl.DateTimeFormat(undefined, (newrecord.timeZoneName = "long", newrecord));

console.log(formatter$2.format(new Date(Date.now())));

var newrecord$1 = Caml_obj.obj_dup(options);

var formatter$3 = new Intl.DateTimeFormat(undefined, (newrecord$1.timeZoneName = "longOffset", newrecord$1));

console.log(formatter$3.format(new Date(Date.now())));

var newrecord$2 = Caml_obj.obj_dup(options);

var formatter$4 = new Intl.DateTimeFormat(undefined, (newrecord$2.timeZoneName = "short", newrecord$2));

console.log(formatter$4.format(new Date(Date.now())));

var newrecord$3 = Caml_obj.obj_dup(options);

var formatter$5 = new Intl.DateTimeFormat(undefined, (newrecord$3.timeZoneName = "shortGeneric", newrecord$3));

console.log(formatter$5.format(new Date(Date.now())));

var newrecord$4 = Caml_obj.obj_dup(options);

var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName = "shortOffset", newrecord$4));

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

var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions();

var timeZone = resolvedOptions.timeZone;

export {
options ,
formatter$6 as formatter,
resolvedOptions ,
timeZone ,
}
/* Not a pure module */
65 changes: 65 additions & 0 deletions test/intl/Intl__ListFormatTest.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


console.log("---");

console.log("Intl.ListFormat");

new Intl.ListFormat();

new Intl.ListFormat("en-US");

new Intl.ListFormat([
"en-US",
"en-GB"
]);

new Intl.ListFormat("en-US", {
type: "conjunction",
style: "long"
});

var _formatter = new Intl.ListFormat([
"en-US",
"en-GB"
], {
type: "conjunction",
style: "long"
});

Intl.ListFormat.supportedLocalesOf([
"en-US",
"en-GB"
]);

Intl.ListFormat.supportedLocalesOf([
"en-US",
"en-GB"
], {
localeMatcher: "lookup"
});

var formatter = new Intl.ListFormat(undefined, {
type: "conjunction",
style: "long"
});

console.log(formatter.resolvedOptions());

console.log(formatter.format([
"one",
"two",
"three"
]));

console.log(formatter.formatToParts([
"one",
"two",
"three"
]));

export {
_formatter ,
formatter ,
}
/* Not a pure module */
Loading
Loading