@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.
@@ -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 };
@@ -1,5 +0,0 @@
1
- import { Preset } from "@x18n/core";
2
- //#region src/presets/i18n-js/index.d.ts
3
- export declare function i18nJs(): Preset;
4
- //#endregion
5
- export { i18nJs as default };