-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toml-test-decode-util.js
57 lines (54 loc) · 1.39 KB
/
toml-test-decode-util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"use strict";
/* eslint n/no-missing-require: off -- ignore */
const { generateConvertTOMLValue } = require("./lib/utils.js");
/** Converter for toml-test (https://github.com/toml-lang/toml-test). */
const convertTomlTestValue = generateConvertTOMLValue((node) => {
if (node.kind === "boolean") {
return { type: "bool", value: String(node.value) };
}
if (node.kind === "local-date") {
return {
type: "date-local",
value: node.value.toISOString().slice(0, 10),
};
}
if (node.kind === "local-date-time") {
return {
type: "datetime-local",
value: node.value.toISOString().slice(0, -1),
};
}
if (node.kind === "offset-date-time") {
return {
type: "datetime",
value: node.value.toISOString(),
};
}
if (node.kind === "local-time") {
return {
type: "time-local",
value: node.value.toISOString().slice(11, -1),
};
}
if (node.kind === "float") {
return {
type: node.kind,
value:
node.value === Infinity
? "+inf"
: node.value === -Infinity
? "-inf"
: Number.isNaN(node.value)
? "nan"
: String(node.value),
};
}
if (node.kind === "integer") {
return {
type: node.kind,
value: String(node.bigint),
};
}
return { type: node.kind, value: node.value };
});
module.exports = { convertTomlTestValue };