@discord/intl-ast 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -7
- package/dist/index.js +13 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,20 +9,16 @@ export declare enum FormatJsNodeType {
|
|
|
9
9
|
Pound = 7,
|
|
10
10
|
Tag = 8
|
|
11
11
|
}
|
|
12
|
-
export type LiteralNode = [
|
|
12
|
+
export type LiteralNode = [string];
|
|
13
13
|
export type ArgumentNode = [FormatJsNodeType.Argument, string];
|
|
14
14
|
export type NumberNode = [FormatJsNodeType.Number, string, string | undefined];
|
|
15
15
|
export type DateNode = [FormatJsNodeType.Date, string, string | undefined];
|
|
16
16
|
export type TimeNode = [FormatJsNodeType.Time, string, string | undefined];
|
|
17
|
-
export type SelectNode = [FormatJsNodeType.Select, string, Record<string,
|
|
18
|
-
value: AstNode[];
|
|
19
|
-
}>];
|
|
17
|
+
export type SelectNode = [FormatJsNodeType.Select, string, Record<string, AstNode[]>];
|
|
20
18
|
export type PluralNode = [
|
|
21
19
|
FormatJsNodeType.Plural,
|
|
22
20
|
string,
|
|
23
|
-
Record<string,
|
|
24
|
-
value: AstNode[];
|
|
25
|
-
}>,
|
|
21
|
+
Record<string, AstNode[]>,
|
|
26
22
|
number,
|
|
27
23
|
FormatJsPluralType
|
|
28
24
|
];
|
package/dist/index.js
CHANGED
|
@@ -51,19 +51,27 @@ function hydratePlural(keyless) {
|
|
|
51
51
|
for (const key in options) {
|
|
52
52
|
hydrateArray(options[key].value);
|
|
53
53
|
}
|
|
54
|
+
const valueOptions = options.map((option) => ({ value: option }));
|
|
54
55
|
// `pluralType` is technically only valid on `Plural` nodes, even
|
|
55
56
|
// though the structure is identical to `Select`.
|
|
56
57
|
if (type === FormatJsNodeType.Plural) {
|
|
57
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
type,
|
|
60
|
+
value,
|
|
61
|
+
options,
|
|
62
|
+
offset: valueOptions,
|
|
63
|
+
pluralType,
|
|
64
|
+
};
|
|
58
65
|
}
|
|
59
66
|
else {
|
|
60
|
-
return { type, value, options, offset };
|
|
67
|
+
return { type, value, options: valueOptions, offset };
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
function hydrateSingle(keyless) {
|
|
64
71
|
const [type] = keyless;
|
|
65
72
|
switch (type) {
|
|
66
73
|
case FormatJsNodeType.Literal:
|
|
74
|
+
return { type: 0, value: keyless[0] };
|
|
67
75
|
case FormatJsNodeType.Argument:
|
|
68
76
|
return { type, value: keyless[1] };
|
|
69
77
|
case FormatJsNodeType.Number:
|
|
@@ -102,9 +110,9 @@ function compressFormatJsToAst(node) {
|
|
|
102
110
|
if (Array.isArray(node)) {
|
|
103
111
|
return node.map((element) => compressFormatJsToAst(element));
|
|
104
112
|
}
|
|
105
|
-
console.log('compressing');
|
|
106
113
|
switch (node.type) {
|
|
107
114
|
case FormatJsNodeType.Literal:
|
|
115
|
+
return [node.value];
|
|
108
116
|
case FormatJsNodeType.Argument:
|
|
109
117
|
return [node.type, node.value];
|
|
110
118
|
case FormatJsNodeType.Number:
|
|
@@ -114,14 +122,14 @@ function compressFormatJsToAst(node) {
|
|
|
114
122
|
case FormatJsNodeType.Select: {
|
|
115
123
|
const reducedOptions = {};
|
|
116
124
|
for (const [name, option] of Object.entries(node.options)) {
|
|
117
|
-
reducedOptions[name] =
|
|
125
|
+
reducedOptions[name] = compressFormatJsToAst(option.value);
|
|
118
126
|
}
|
|
119
127
|
return [node.type, node.value, reducedOptions];
|
|
120
128
|
}
|
|
121
129
|
case FormatJsNodeType.Plural: {
|
|
122
130
|
const reducedOptions = {};
|
|
123
131
|
for (const [name, option] of Object.entries(node.options)) {
|
|
124
|
-
reducedOptions[name] =
|
|
132
|
+
reducedOptions[name] = compressFormatJsToAst(option.value);
|
|
125
133
|
}
|
|
126
134
|
return [node.type, node.value, reducedOptions, node.offset, node.pluralType];
|
|
127
135
|
}
|