Skip to content

Commit fa62ee1

Browse files
feat: grouping parse
1 parent 675bec4 commit fa62ee1

6 files changed

+63
-2
lines changed
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
11
// 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. */
2+
3+
import * as Core__Type from "../Core__Type.mjs";
4+
5+
function parseJsValue(value) {
6+
var value$1 = Core__Type.Classify.classify(value);
7+
if (typeof value$1 === "number") {
8+
return ;
9+
}
10+
switch (value$1.TAG | 0) {
11+
case /* Bool */0 :
12+
return {
13+
NAME: "bool",
14+
VAL: value$1._0
15+
};
16+
case /* String */1 :
17+
switch (value$1._0) {
18+
case "always" :
19+
return "always";
20+
case "auto" :
21+
return "auto";
22+
case "min2" :
23+
return "min2";
24+
default:
25+
return ;
26+
}
27+
default:
28+
return ;
29+
}
30+
}
31+
32+
export {
33+
parseJsValue ,
34+
}
35+
/* No side effect */
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
type t
22

3+
type parsed = [#bool(bool) | #always | #auto | #min2]
4+
35
external fromBool: bool => t = "%identity"
46
external fromString: [#always | #auto | #min2] => t = "%identity"
5-
// TODO: unwrap this for consumption coming back in resolvedOptions
7+
8+
let parseJsValue = value =>
9+
switch Core__Type.Classify.classify(value) {
10+
| String("always") => Some(#always)
11+
| String("auto") => Some(#auto)
12+
| String("min2") => Some(#min2)
13+
| Bool(value) => Some(#bool(value))
14+
| _ => None
15+
}

test/Intl/IntlTests.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2;
8282

8383
var sigFormatter = Intl__NumberFormatTest.sigFormatter;
8484

85+
var options = Intl__NumberFormatTest.options;
86+
8587
var formatter = Intl__SegmenterTest.formatter;
8688

8789
var segments = Intl__SegmenterTest.segments;
@@ -96,6 +98,7 @@ export {
9698
groupingFormatter1 ,
9799
groupingFormatter2 ,
98100
sigFormatter ,
101+
options ,
99102
formatter ,
100103
segments ,
101104
}

test/Intl/Intl__NumberFormatTest.mjs

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

33
import * as Caml_option from "rescript/lib/es6/caml_option.js";
4+
import * as Core__Intl__NumberFormat__Grouping from "../../src/intl/Core__Intl__NumberFormat__Grouping.mjs";
45

56
console.log("---");
67

@@ -39,11 +40,18 @@ var sigFormatter = new Intl.NumberFormat(undefined, {
3940
maximumSignificantDigits: 1
4041
});
4142

43+
var options = sigFormatter.resolvedOptions();
44+
45+
console.log(options);
46+
47+
console.log(Core__Intl__NumberFormat__Grouping.parseJsValue(options.useGrouping));
48+
4249
export {
4350
currencyFormatter ,
4451
roundingFormatter ,
4552
groupingFormatter1 ,
4653
groupingFormatter2 ,
4754
sigFormatter ,
55+
options ,
4856
}
4957
/* Not a pure module */

test/Intl/Intl__NumberFormatTest.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ let sigFormatter = Intl.NumberFormat.makeWithOptions({
3030
minimumSignificantDigits: #1,
3131
maximumSignificantDigits: #1,
3232
})
33+
34+
let options = sigFormatter->Intl.NumberFormat.resolvedOptions
35+
Console.log(options)
36+
options.useGrouping->Core__Intl__NumberFormat.Grouping.parseJsValue->Console.log

test/TempTests.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ var groupingFormatter2 = IntlTests.groupingFormatter2;
327327

328328
var sigFormatter = IntlTests.sigFormatter;
329329

330+
var options = IntlTests.options;
331+
330332
var formatter = IntlTests.formatter;
331333

332334
var segments = IntlTests.segments;
@@ -341,6 +343,7 @@ export {
341343
groupingFormatter1 ,
342344
groupingFormatter2 ,
343345
sigFormatter ,
346+
options ,
344347
formatter ,
345348
segments ,
346349
date ,

0 commit comments

Comments
 (0)