@x18n/builtins 0.0.14 → 0.1.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/checks.d.mts +1 -0
- package/dist/checks.mjs +26 -1
- package/dist/formats/ecmascript.mjs +72 -51
- package/dist/formats/ftl.mjs +1 -1
- package/dist/formats/ini.mjs +1 -1
- package/dist/formats/json.mjs +1 -1
- package/dist/formats/json5.mjs +126 -13
- package/dist/formats/jsonc.mjs +1 -1
- package/dist/formats/php.mjs +28 -30
- package/dist/formats/po.mjs +1 -1
- package/dist/formats/properties.mjs +1 -1
- package/dist/formats/resx.mjs +1 -1
- package/dist/formats/yaml.mjs +28 -1
- package/dist/index.mjs +2 -0
- package/dist/json-CGNSGS97.mjs +109 -0
- package/dist/literal-gIdB1VGy.mjs +125 -0
- package/dist/presets/ruby-i18n-js.d.mts +5 -0
- package/dist/presets/{i18n-js.mjs → ruby-i18n-js.mjs} +5 -5
- package/dist/presets.mjs +49 -49
- package/dist/reviews.d.mts +6 -0
- package/dist/reviews.mjs +35 -0
- package/dist/{shared-BWaXUmwA.mjs → shared-C7ceptwi.mjs} +5 -20
- package/package.json +4 -3
- package/dist/json-Db-8qSbE.mjs +0 -73
- package/dist/presets/i18n-js.d.mts +0 -5
package/dist/json-Db-8qSbE.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { n as detectEol, r as detectIndent } from "./shared-BWaXUmwA.mjs";
|
|
2
|
-
import { diffText, errors, pathId } from "@x18n/core";
|
|
3
|
-
import { applyEdits, modify, parseTree, printParseErrorCode } from "jsonc-parser";
|
|
4
|
-
//#region src/formats/shared/json.ts
|
|
5
|
-
function readTree(node, path, ranges) {
|
|
6
|
-
const out = {};
|
|
7
|
-
for (const property of node.children ?? []) {
|
|
8
|
-
const [keyNode, valueNode] = property.children ?? [];
|
|
9
|
-
if (!keyNode || !valueNode || typeof keyNode.value !== "string") continue;
|
|
10
|
-
const key = keyNode.value;
|
|
11
|
-
const childPath = [...path, key];
|
|
12
|
-
ranges.set(pathId(childPath), {
|
|
13
|
-
key: {
|
|
14
|
-
start: keyNode.offset + 1,
|
|
15
|
-
end: keyNode.offset + keyNode.length - 1
|
|
16
|
-
},
|
|
17
|
-
value: {
|
|
18
|
-
start: valueNode.offset,
|
|
19
|
-
end: valueNode.offset + valueNode.length
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (valueNode.type === "object") out[key] = readTree(valueNode, childPath, ranges);
|
|
23
|
-
else if (valueNode.type === "string" || valueNode.type === "number" || valueNode.type === "boolean" || valueNode.type === "null") out[key] = valueNode.value;
|
|
24
|
-
}
|
|
25
|
-
return out;
|
|
26
|
-
}
|
|
27
|
-
function createJsonFormat(id, extensions, allowComments, defaultIndent) {
|
|
28
|
-
return {
|
|
29
|
-
id,
|
|
30
|
-
extensions,
|
|
31
|
-
parse(text, ctx) {
|
|
32
|
-
const problems = [];
|
|
33
|
-
const root = parseTree(text, problems, {
|
|
34
|
-
allowTrailingComma: true,
|
|
35
|
-
disallowComments: !allowComments
|
|
36
|
-
});
|
|
37
|
-
if (problems.length > 0) {
|
|
38
|
-
const first = problems[0];
|
|
39
|
-
throw errors.X18N2002({
|
|
40
|
-
path: ctx.path,
|
|
41
|
-
reason: `${printParseErrorCode(first.error)} at offset ${first.offset}`
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (!root || root.type !== "object") {
|
|
45
|
-
if (text.trim() === "") return {
|
|
46
|
-
tree: {},
|
|
47
|
-
ranges: /* @__PURE__ */ new Map()
|
|
48
|
-
};
|
|
49
|
-
throw errors.X18N2003({ path: ctx.path });
|
|
50
|
-
}
|
|
51
|
-
const ranges = /* @__PURE__ */ new Map();
|
|
52
|
-
return {
|
|
53
|
-
tree: readTree(root, [], ranges),
|
|
54
|
-
ranges
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
edit(text, ops, ctx) {
|
|
58
|
-
const formattingOptions = {
|
|
59
|
-
...detectIndent(text, ctx.indent ?? defaultIndent),
|
|
60
|
-
eol: detectEol(text)
|
|
61
|
-
};
|
|
62
|
-
let next = text.trim() === "" ? "{}\n" : text;
|
|
63
|
-
for (const op of ops) next = applyEdits(next, modify(next, [...op.path], op.type === "set" ? op.value : void 0, { formattingOptions }));
|
|
64
|
-
return diffText(text, next);
|
|
65
|
-
},
|
|
66
|
-
serialize(tree, ctx) {
|
|
67
|
-
const indent = ctx.indent ?? defaultIndent ?? 2;
|
|
68
|
-
return `${JSON.stringify(tree, null, indent === "tab" ? " " : indent)}\n`;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
|
-
export { createJsonFormat as t };
|