@decimalturn/toml-patch 3.2.0-dev → 3.2.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.
Files changed (82) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +200 -0
  3. package/dist/patch-lite.js +20 -0
  4. package/dist/toml-patch.js +84 -0
  5. package/package.json +104 -13
  6. package/dist/dev/comment-alignment.js +0 -372
  7. package/dist/dev/comment-alignment.js.map +0 -1
  8. package/dist/dev/comment-ownership.js +0 -660
  9. package/dist/dev/comment-ownership.js.map +0 -1
  10. package/dist/dev/cst-source.js +0 -118
  11. package/dist/dev/cst-source.js.map +0 -1
  12. package/dist/dev/cst.js +0 -68
  13. package/dist/dev/cst.js.map +0 -1
  14. package/dist/dev/cursor.js +0 -66
  15. package/dist/dev/cursor.js.map +0 -1
  16. package/dist/dev/date-format.js +0 -196
  17. package/dist/dev/date-format.js.map +0 -1
  18. package/dist/dev/decode-utf8.js +0 -27
  19. package/dist/dev/decode-utf8.js.map +0 -1
  20. package/dist/dev/diff-lite.js +0 -123
  21. package/dist/dev/diff-lite.js.map +0 -1
  22. package/dist/dev/diff.js +0 -265
  23. package/dist/dev/diff.js.map +0 -1
  24. package/dist/dev/encode-lite.js +0 -193
  25. package/dist/dev/encode-lite.js.map +0 -1
  26. package/dist/dev/escape-preference.js +0 -166
  27. package/dist/dev/escape-preference.js.map +0 -1
  28. package/dist/dev/find-by-path.js +0 -111
  29. package/dist/dev/find-by-path.js.map +0 -1
  30. package/dist/dev/formatter.js +0 -298
  31. package/dist/dev/formatter.js.map +0 -1
  32. package/dist/dev/generate.js +0 -465
  33. package/dist/dev/generate.js.map +0 -1
  34. package/dist/dev/inline-comma-space.js +0 -13
  35. package/dist/dev/inline-comma-space.js.map +0 -1
  36. package/dist/dev/inline-format.js +0 -106
  37. package/dist/dev/inline-format.js.map +0 -1
  38. package/dist/dev/inline-layout.js +0 -107
  39. package/dist/dev/inline-layout.js.map +0 -1
  40. package/dist/dev/line-ending-backslash.js +0 -320
  41. package/dist/dev/line-ending-backslash.js.map +0 -1
  42. package/dist/dev/literal-string.js +0 -46
  43. package/dist/dev/literal-string.js.map +0 -1
  44. package/dist/dev/location.js +0 -104
  45. package/dist/dev/location.js.map +0 -1
  46. package/dist/dev/parse-error.js +0 -27
  47. package/dist/dev/parse-error.js.map +0 -1
  48. package/dist/dev/parse-js.js +0 -150
  49. package/dist/dev/parse-js.js.map +0 -1
  50. package/dist/dev/parse-string.js +0 -122
  51. package/dist/dev/parse-string.js.map +0 -1
  52. package/dist/dev/parse-toml.js +0 -714
  53. package/dist/dev/parse-toml.js.map +0 -1
  54. package/dist/dev/patch-lite.js +0 -4
  55. package/dist/dev/patch-lite2.js +0 -96
  56. package/dist/dev/patch-lite2.js.map +0 -1
  57. package/dist/dev/patch.js +0 -2652
  58. package/dist/dev/patch.js.map +0 -1
  59. package/dist/dev/smol-toml-date.js +0 -61
  60. package/dist/dev/smol-toml-date.js.map +0 -1
  61. package/dist/dev/to-js.js +0 -303
  62. package/dist/dev/to-js.js.map +0 -1
  63. package/dist/dev/to-toml.js +0 -874
  64. package/dist/dev/to-toml.js.map +0 -1
  65. package/dist/dev/tokenizer.js +0 -225
  66. package/dist/dev/tokenizer.js.map +0 -1
  67. package/dist/dev/toml-document.js +0 -220
  68. package/dist/dev/toml-document.js.map +0 -1
  69. package/dist/dev/toml-format.js +0 -528
  70. package/dist/dev/toml-format.js.map +0 -1
  71. package/dist/dev/toml-patch.js +0 -94
  72. package/dist/dev/toml-patch.js.map +0 -1
  73. package/dist/dev/traverse.js +0 -61
  74. package/dist/dev/traverse.js.map +0 -1
  75. package/dist/dev/truncate.js +0 -64
  76. package/dist/dev/truncate.js.map +0 -1
  77. package/dist/dev/update-order.js +0 -235
  78. package/dist/dev/update-order.js.map +0 -1
  79. package/dist/dev/utils.js +0 -244
  80. package/dist/dev/utils.js.map +0 -1
  81. package/dist/dev/writer.js +0 -758
  82. package/dist/dev/writer.js.map +0 -1
package/dist/dev/diff.js DELETED
@@ -1,265 +0,0 @@
1
- //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { datesEqual, isNegativeNan, isObject, merge, sameValue, stableStringify } from "./utils.js";
3
-
4
- //#region src/diff.ts
5
- function isAdd(change) {
6
- return change.type === "Add";
7
- }
8
- function isEdit(change) {
9
- return change.type === "Edit";
10
- }
11
- function isRemove(change) {
12
- return change.type === "Remove";
13
- }
14
- function isMove(change) {
15
- return change.type === "Move";
16
- }
17
- function isRename(change) {
18
- return change.type === "Rename";
19
- }
20
- function diff(before, after, path = [], options = {}) {
21
- if (sameValue(before, after) || datesEqual(before, after)) return [];
22
- if (typeof before === "number" && typeof after === "number" && Number.isNaN(before) && Number.isNaN(after)) {
23
- if (isNegativeNan(before) === isNegativeNan(after)) return [];
24
- }
25
- if (Array.isArray(before) && Array.isArray(after)) return compareArrays(before, after, path, options);
26
- else if (isObject(before) && isObject(after)) return compareObjects(before, after, path, options);
27
- else return [{
28
- type: "Edit",
29
- path
30
- }];
31
- }
32
- function compareObjects(before, after, path = [], options = {}) {
33
- let changes = [];
34
- const before_keys = Object.keys(before);
35
- const before_stable = before_keys.map((key) => stableStringify(before[key]));
36
- const after_keys = Object.keys(after);
37
- const after_stable = after_keys.map((key) => stableStringify(after[key]));
38
- const after_stable_by_key = new Map(after_keys.map((key, index) => [key, after_stable[index]]));
39
- const before_key_set = new Set(before_keys);
40
- const after_key_set = new Set(after_keys);
41
- const groupByValue = (keys, stables, exclude) => {
42
- const groups = /* @__PURE__ */ new Map();
43
- keys.forEach((key, index) => {
44
- if (exclude.has(key)) return;
45
- const group = groups.get(stables[index]);
46
- if (group) group.push(key);
47
- else groups.set(stables[index], [key]);
48
- });
49
- return groups;
50
- };
51
- const disappeared = groupByValue(before_keys, before_stable, after_key_set);
52
- const appeared = groupByValue(after_keys, after_stable, before_key_set);
53
- const renamed = /* @__PURE__ */ new Map();
54
- const renameTargets = /* @__PURE__ */ new Set();
55
- const renameSourcesByTarget = /* @__PURE__ */ new Map();
56
- for (const [value, sources] of disappeared) {
57
- const targets = appeared.get(value);
58
- if (!targets) continue;
59
- const pairs = Math.min(sources.length, targets.length);
60
- for (let i = 0; i < pairs; i++) {
61
- renamed.set(sources[i], targets[i]);
62
- renameTargets.add(targets[i]);
63
- renameSourcesByTarget.set(targets[i], sources[i]);
64
- }
65
- }
66
- before_keys.forEach((key, index) => {
67
- const sub_path = path.concat(key);
68
- if (after_key_set.has(key)) {
69
- const beforeValue = before[key];
70
- const afterValue = after[key];
71
- const hasNonFiniteNumber = typeof beforeValue === "number" && !Number.isFinite(beforeValue) || typeof afterValue === "number" && !Number.isFinite(afterValue);
72
- if (options.updateOrder || hasNonFiniteNumber || before_stable[index] !== after_stable_by_key.get(key)) merge(changes, diff(before[key], after[key], sub_path, options));
73
- } else if (renamed.has(key)) changes.push({
74
- type: "Rename",
75
- path,
76
- from: key,
77
- to: renamed.get(key)
78
- });
79
- else changes.push({
80
- type: "Remove",
81
- path: sub_path
82
- });
83
- });
84
- after_keys.forEach((key) => {
85
- if (!before_key_set.has(key) && !renameTargets.has(key)) {
86
- const add = {
87
- type: "Add",
88
- path: path.concat(key)
89
- };
90
- if (options.orderSource !== void 0) {
91
- let orderObject = options.orderSource;
92
- for (const segment of path) orderObject = orderObject === null || orderObject === void 0 ? void 0 : orderObject[segment];
93
- if (isObject(orderObject)) {
94
- const requestedKeys = Object.keys(orderObject);
95
- const addedIndex = requestedKeys.indexOf(key);
96
- for (let i = addedIndex + 1; i < requestedKeys.length; i++) {
97
- const target = requestedKeys[i];
98
- const source = renameSourcesByTarget.get(target) ?? (before_key_set.has(target) ? target : void 0);
99
- if (source !== void 0) {
100
- add.before = source;
101
- break;
102
- }
103
- }
104
- }
105
- }
106
- changes.push(add);
107
- }
108
- });
109
- let requestedKeys = after_keys;
110
- if (options.orderSource !== void 0) {
111
- let orderObject = options.orderSource;
112
- for (const segment of path) orderObject = orderObject === null || orderObject === void 0 ? void 0 : orderObject[segment];
113
- if (isObject(orderObject)) {
114
- const afterKeySet = new Set(after_keys);
115
- requestedKeys = Object.keys(orderObject).filter((key) => afterKeySet.has(key));
116
- }
117
- }
118
- const directChanges = changes.filter((change) => isAdd(change) && change.path.length === path.length + 1 || isRename(change) && change.path.length === path.length);
119
- if (options.orderSource !== void 0 && directChanges.length > 1) {
120
- const orderedDirectChanges = [...directChanges].sort((a, b) => {
121
- const aKey = isAdd(a) ? a.path[a.path.length - 1] : isRename(a) ? a.to : "";
122
- const bKey = isAdd(b) ? b.path[b.path.length - 1] : isRename(b) ? b.to : "";
123
- return requestedKeys.indexOf(aKey) - requestedKeys.indexOf(bKey);
124
- });
125
- let directIndex = 0;
126
- changes = changes.map((change) => directChanges.includes(change) ? orderedDirectChanges[directIndex++] : change);
127
- }
128
- if (options.updateOrder) {
129
- const sim = [];
130
- for (const key of before_keys) if (after_key_set.has(key)) {
131
- if (!sim.includes(key)) sim.push(key);
132
- } else if (renamed.has(key)) {
133
- const to = renamed.get(key);
134
- if (!sim.includes(to)) sim.push(to);
135
- }
136
- for (const key of after_keys) if (!sim.includes(key)) sim.push(key);
137
- after_keys.forEach((key, targetIndex) => {
138
- if (sim[targetIndex] === key) return;
139
- const from = sim.indexOf(key);
140
- changes.push({
141
- type: "Move",
142
- path,
143
- from,
144
- to: targetIndex,
145
- key
146
- });
147
- sim.splice(from, 1);
148
- sim.splice(targetIndex, 0, key);
149
- });
150
- }
151
- return changes;
152
- }
153
- function hasMultilineValue(v) {
154
- if (typeof v === "string") return v.includes("\n");
155
- if (Array.isArray(v)) return v.length > 0;
156
- if (v !== null && typeof v === "object" && !(v instanceof Date)) {
157
- const vals = Object.values(v);
158
- return vals.some((x) => x !== null && typeof x === "object") || vals.some(hasMultilineValue);
159
- }
160
- return false;
161
- }
162
- function hasInlineObject(value) {
163
- return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
164
- }
165
- function hasMixedStringAndObject(values) {
166
- return values.length > 4 && values.some((value) => typeof value === "string") && values.some(hasInlineObject);
167
- }
168
- function compareArrays(before, after, path = [], options = {}) {
169
- let changes = [];
170
- const before_stable = before.map(stableStringify);
171
- const after_stable = after.map(stableStringify);
172
- const layoutSensitiveArray = before.some(hasMultilineValue) || after.some(hasMultilineValue) || hasMixedStringAndObject(before) || hasMixedStringAndObject(after);
173
- const before_sim = before.slice();
174
- let removedBefore = 0;
175
- let sameArrayAddEmitted = false;
176
- const removeChange = (index) => {
177
- const change = {
178
- type: "Remove",
179
- path: path.concat(index)
180
- };
181
- if (!sameArrayAddEmitted || removedBefore > 0) Object.defineProperty(change, "coordinate", { value: "source" });
182
- return change;
183
- };
184
- for (let index = 0; index < after_stable.length; index++) {
185
- const value = after_stable[index];
186
- const overflow = index >= before_stable.length;
187
- if (!overflow && before_stable[index] === value) continue;
188
- const from = overflow ? -1 : before_stable.indexOf(value, index + 1);
189
- if (from > -1) {
190
- const valueAt = before_stable[index];
191
- let beforeCount = 0;
192
- for (let i = index; i < before_stable.length; i++) if (before_stable[i] === valueAt) beforeCount++;
193
- let afterCount = 0;
194
- for (let i = index; i < after_stable.length; i++) if (after_stable[i] === valueAt) afterCount++;
195
- const surplusDuplicate = beforeCount > afterCount;
196
- if (layoutSensitiveArray && (after_stable.indexOf(before_stable[index]) === -1 || surplusDuplicate)) {
197
- changes.push(removeChange(index + removedBefore));
198
- before_stable.splice(index, 1);
199
- before_sim.splice(index, 1);
200
- removedBefore++;
201
- index--;
202
- continue;
203
- }
204
- if (removedBefore > 0 && surplusDuplicate) {
205
- changes.push(removeChange(index + removedBefore));
206
- before_stable.splice(index, 1);
207
- before_sim.splice(index, 1);
208
- removedBefore++;
209
- index--;
210
- continue;
211
- }
212
- if (layoutSensitiveArray && removedBefore > 0) {
213
- changes.push({
214
- type: "Add",
215
- path: path.concat(index)
216
- });
217
- sameArrayAddEmitted = true;
218
- before_stable.splice(index, 0, value);
219
- before_sim.splice(index, 0, after[index]);
220
- removedBefore--;
221
- continue;
222
- }
223
- changes.push({
224
- type: "Move",
225
- path,
226
- from,
227
- to: index
228
- });
229
- const move = before_stable.splice(from, 1);
230
- before_stable.splice(index, 0, ...move);
231
- const moveValues = before_sim.splice(from, 1);
232
- before_sim.splice(index, 0, ...moveValues);
233
- continue;
234
- }
235
- let surplus = false;
236
- if (!overflow) {
237
- const value = before_stable[index];
238
- let beforeCount = 0;
239
- for (let i = index; i < before_stable.length; i++) if (before_stable[i] === value) beforeCount++;
240
- let afterCount = 0;
241
- for (let i = index; i < after_stable.length; i++) if (after_stable[i] === value) afterCount++;
242
- surplus = beforeCount > afterCount;
243
- }
244
- if (!overflow && surplus) {
245
- merge(changes, diff(before_sim[index], after[index], path.concat(index), options));
246
- before_stable[index] = value;
247
- before_sim[index] = after[index];
248
- continue;
249
- }
250
- changes.push({
251
- type: "Add",
252
- path: path.concat(index)
253
- });
254
- sameArrayAddEmitted = true;
255
- before_stable.splice(index, 0, value);
256
- before_sim.splice(index, 0, after[index]);
257
- if (removedBefore > 0) removedBefore--;
258
- }
259
- for (let i = after_stable.length; i < before_stable.length; i++) changes.push(removeChange(i + removedBefore));
260
- return changes;
261
- }
262
-
263
- //#endregion
264
- export { diff as default, isAdd, isEdit, isMove, isRemove, isRename };
265
- //# sourceMappingURL=diff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diff.js","names":[],"sources":["../../src/diff.ts"],"sourcesContent":["import { isObject, datesEqual, stableStringify, merge, sameValue, isNegativeNan } from './utils';\nimport { Path } from './find-by-path';\n\nexport enum ChangeType {\n Add = 'Add',\n Edit = 'Edit',\n Remove = 'Remove',\n Move = 'Move',\n Rename = 'Rename'\n}\n\nexport interface Add {\n type: ChangeType.Add;\n path: Path;\n /** Existing sibling key that the new member must be inserted before. */\n before?: string;\n}\nexport function isAdd(change: Change): change is Add {\n return change.type === ChangeType.Add;\n}\n\nexport interface Edit {\n type: ChangeType.Edit;\n path: Path;\n}\nexport function isEdit(change: Change): change is Edit {\n return change.type === ChangeType.Edit;\n}\n\nexport interface Remove {\n type: ChangeType.Remove;\n path: Path;\n /** Internal marker for array removes whose index refers to the original array. */\n coordinate?: 'source';\n}\nexport function isRemove(change: Change): change is Remove {\n return change.type === ChangeType.Remove;\n}\n\nexport interface Move {\n type: ChangeType.Move;\n path: Path;\n from: number;\n to: number;\n /** Present only for object-key moves (updateOrder); identifies the child to place. */\n key?: string;\n}\nexport function isMove(change: Change): change is Move {\n return change.type === ChangeType.Move;\n}\n\nexport interface Rename {\n type: ChangeType.Rename;\n path: Path;\n from: string;\n to: string;\n}\nexport function isRename(change: Change): change is Rename {\n return change.type === ChangeType.Rename;\n}\n\nexport type Change = Add | Edit | Remove | Move | Rename;\n\nexport interface DiffOptions {\n /**\n * When true, `compareObjects` additionally emits Moves so that object keys end up in the\n * same order as `after`'s. Off by default: a no-options `diff()` call emits zero Moves for\n * a pure key-order permutation, which is the compatibility guarantee callers rely on. See\n * docs/PLAN-Update-Order.md.\n */\n updateOrder?: boolean;\n /** Object graph whose key order represents the caller's requested order. */\n orderSource?: any;\n}\n\nexport default function diff(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n if (sameValue(before, after) || datesEqual(before, after)) {\n return [];\n }\n\n // Both NaN — treat as equal only if they have the same sign bit.\n // -NaN and NaN are distinguishable via IEEE 754, so a sign change\n // from negative NaN to canonical NaN should trigger an edit.\n if (typeof before === 'number' && typeof after === 'number'\n && Number.isNaN(before) && Number.isNaN(after)) {\n if (isNegativeNan(before) === isNegativeNan(after)) return [];\n // Sign differs — fall through to produce an Edit\n }\n\n if (Array.isArray(before) && Array.isArray(after)) {\n return compareArrays(before, after, path, options);\n } else if (isObject(before) && isObject(after)) {\n return compareObjects(before, after, path, options);\n } else {\n return [\n {\n type: ChangeType.Edit,\n path\n }\n ];\n }\n}\n\nfunction compareObjects(before: any, after: any, path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Get keys and stable values\n const before_keys = Object.keys(before);\n const before_stable = before_keys.map(key => stableStringify(before[key]));\n const after_keys = Object.keys(after);\n const after_stable = after_keys.map(key => stableStringify(after[key]));\n const after_stable_by_key = new Map(\n after_keys.map((key, index) => [key, after_stable[index]])\n );\n\n // Membership is tested once per key in each pass below, so these are Sets rather than the\n // key arrays: `includes` inside those loops makes the whole function quadratic in the\n // number of keys, which is felt on wide tables — a 2000-key object spent ~28ms there.\n const before_key_set = new Set(before_keys);\n const after_key_set = new Set(after_keys);\n\n // A key that disappeared is inferred to have been renamed when a key appears holding the\n // same value, since a rename is never declared — value equality is the only signal.\n //\n // Several keys can share a value, so the candidates are grouped by value and paired off in\n // order, as many as both sides can supply. Preserving comments is the point of this\n // library, so a plausible pairing is worth more than declining to guess: a renamed node is\n // edited in place and keeps its comments and formatting, whereas a remove-plus-add loses\n // them. Where the pairing is genuinely ambiguous the choice is arbitrary but harmless in\n // kind — a comment lands on one interchangeable key rather than another. Patching in\n // smaller steps removes the ambiguity for callers who care which.\n //\n // Pairing by position is what keeps it one-to-one. Matching with `indexOf` always resolved\n // to the first candidate, so every equal-valued source claimed the same target:\n // `{a:1,b:1} -> {z:1}` emitted two renames onto `z`, and the second blanked its node's\n // key, giving ` = 1` — output that does not parse. Leftovers on either side fall through\n // to Remove or Add.\n //\n // Keys present on both sides are excluded from both groups: they were not renamed and are\n // not available as targets. That is what keeps a removal whose value happens to match an\n // untouched sibling from being read as a rename onto it (issue #262).\n //\n // Tracked as from -> to because step 4 (order emission) has to follow a rename through\n // rather than treating the old name as simply gone.\n const groupByValue = (keys: string[], stables: string[], exclude: Set<string>) => {\n const groups = new Map<string, string[]>();\n keys.forEach((key, index) => {\n if (exclude.has(key)) return;\n const group = groups.get(stables[index]);\n if (group) group.push(key);\n else groups.set(stables[index], [key]);\n });\n return groups;\n };\n\n const disappeared = groupByValue(before_keys, before_stable, after_key_set);\n const appeared = groupByValue(after_keys, after_stable, before_key_set);\n\n const renamed = new Map<string, string>();\n const renameTargets = new Set<string>();\n const renameSourcesByTarget = new Map<string, string>();\n\n for (const [value, sources] of disappeared) {\n const targets = appeared.get(value);\n if (!targets) continue;\n\n const pairs = Math.min(sources.length, targets.length);\n for (let i = 0; i < pairs; i++) {\n renamed.set(sources[i], targets[i]);\n renameTargets.add(targets[i]);\n renameSourcesByTarget.set(targets[i], sources[i]);\n }\n }\n\n // 2. Check for changes, rename, and removed\n before_keys.forEach((key, index) => {\n const sub_path = path.concat(key);\n if (after_key_set.has(key)) {\n const beforeValue = before[key];\n const afterValue = after[key];\n const hasNonFiniteNumber =\n (typeof beforeValue === 'number' && !Number.isFinite(beforeValue)) ||\n (typeof afterValue === 'number' && !Number.isFinite(afterValue));\n if (options.updateOrder || hasNonFiniteNumber ||\n before_stable[index] !== after_stable_by_key.get(key)) {\n merge(changes, diff(before[key], after[key], sub_path, options));\n }\n } else if (renamed.has(key)) {\n changes.push({\n type: ChangeType.Rename,\n path,\n from: key,\n to: renamed.get(key)!\n });\n } else {\n changes.push({\n type: ChangeType.Remove,\n path: sub_path\n });\n }\n });\n\n // 3. Check for additions\n after_keys.forEach(key => {\n if (!before_key_set.has(key) && !renameTargets.has(key)) {\n const add: Add = {\n type: ChangeType.Add,\n path: path.concat(key)\n };\n\n // Adds normally append. If the caller supplied the original object whose order\n // should be honoured, anchor this add before the next member that already has a\n // slot. A rename uses its old key as the anchor because the rename runs in place.\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const requestedKeys = Object.keys(orderObject);\n const addedIndex = requestedKeys.indexOf(key);\n for (let i = addedIndex + 1; i < requestedKeys.length; i++) {\n const target = requestedKeys[i];\n const source = renameSourcesByTarget.get(target)\n ?? (before_key_set.has(target) ? target : undefined);\n if (source !== undefined) {\n add.before = source;\n break;\n }\n }\n }\n }\n\n changes.push(add);\n }\n });\n\n let requestedKeys = after_keys;\n if (options.orderSource !== undefined) {\n let orderObject = options.orderSource;\n for (const segment of path) orderObject = orderObject?.[segment as any];\n if (isObject(orderObject)) {\n const afterKeySet = new Set(after_keys);\n requestedKeys = Object.keys(orderObject).filter(key => afterKeySet.has(key));\n }\n }\n\n // A renamed member keeps its existing CST slot, while an added member is appended\n // by the patcher. Emit direct Adds and Renames in the updated object order so an\n // added dotted member can land before a renamed sibling without patch.ts inspecting\n // the CST or the complete change list.\n const directChanges = changes.filter(change =>\n (isAdd(change) && change.path.length === path.length + 1) ||\n (isRename(change) && change.path.length === path.length)\n );\n if (options.orderSource !== undefined && directChanges.length > 1) {\n const orderedDirectChanges = [...directChanges].sort((a, b) => {\n const aKey = isAdd(a) ? a.path[a.path.length - 1] : isRename(a) ? a.to : '';\n const bKey = isAdd(b) ? b.path[b.path.length - 1] : isRename(b) ? b.to : '';\n return requestedKeys.indexOf(aKey as string) - requestedKeys.indexOf(bKey as string);\n });\n let directIndex = 0;\n changes = changes.map(change =>\n directChanges.includes(change) ? orderedDirectChanges[directIndex++] : change\n );\n }\n\n // 4. Order emission (updateOrder only). Predict the key order the document will have\n // once Add/Remove/Rename above are applied, then walk the target order emitting a Move\n // wherever the prediction and the target disagree, splicing the prediction to match as we\n // go — the same simulate-and-splice approach compareArrays already uses for Move.\n if (options.updateOrder) {\n const sim: string[] = [];\n for (const key of before_keys) {\n if (after_key_set.has(key)) {\n if (!sim.includes(key)) sim.push(key);\n } else if (renamed.has(key)) {\n // Guard against the pre-existing spurious-rename case ({a:1,b:1} -> {b:1,x:1} emits\n // Rename a->b even though b is unchanged) pushing a duplicate into sim.\n const to = renamed.get(key)!;\n if (!sim.includes(to)) sim.push(to);\n }\n // removed -> drop\n }\n for (const key of after_keys) {\n if (!sim.includes(key)) sim.push(key); // adds append\n }\n\n after_keys.forEach((key, targetIndex) => {\n if (sim[targetIndex] === key) return;\n\n const from = sim.indexOf(key);\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: targetIndex,\n key\n });\n\n sim.splice(from, 1);\n sim.splice(targetIndex, 0, key);\n });\n }\n\n return changes;\n}\n\n// Multiline-formatting proxies, hoisted so compareArrays doesn't rebuild them\n// per call. See the layoutSensitiveArray comment in compareArrays.\nfunction hasMultilineValue(v: any): boolean {\n if (typeof v === 'string') return v.includes('\\n');\n if (Array.isArray(v)) return v.length > 0;\n if (v !== null && typeof v === 'object' && !(v instanceof Date)) {\n const vals = Object.values(v);\n return vals.some(x => x !== null && typeof x === 'object') || vals.some(hasMultilineValue);\n }\n return false;\n}\n\nfunction hasInlineObject(value: any): boolean {\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date);\n}\n\nfunction hasMixedStringAndObject(values: any[]): boolean {\n return values.length > 4 && values.some(value => typeof value === 'string') && values.some(hasInlineObject);\n}\n\nfunction compareArrays(before: any[], after: any[], path: Path = [], options: DiffOptions = {}): Change[] {\n let changes: Change[] = [];\n\n // 1. Convert arrays to stable objects\n const before_stable = before.map(stableStringify);\n const after_stable = after.map(stableStringify);\n\n // The writer corrupts multiline inline content when elements are relocated\n // (moves of elements holding multiline strings drop content lines — fuzz\n // seed 4765). Only for such arrays, prefer resolving a true deletion in\n // place over drifting the element right through a chain of Moves.\n // Multiline DELIMITED strings whose content is single-line aren't visible\n // here (the diff sees only values), but nested arrays/objects are a strong\n // proxy: those are what carry such formatting, and moving them corrupts\n // their interior the same way (fuzz seed 8512). A nested array or object\n // is itself evidence of multiline formatting even when its ELEMENTS are all\n // plain scalars — the formatter freely wraps such a container across lines,\n // and the diff cannot tell from values alone (fuzz seed 40181: removing a\n // scalar above a multiline `[218561, \"…\"]` chain-moved the array and dropped\n // columns out of its tail).\n const multilineArray = before.some(hasMultilineValue) || after.some(hasMultilineValue);\n const layoutSensitiveArray = multilineArray || hasMixedStringAndObject(before) || hasMixedStringAndObject(after);\n\n // Simulation of the actual VALUES, mutated in lockstep with before_stable.\n // The \"removed -> edited in place\" branch below must diff the element the\n // move simulation left at this index, not the untouched original: after a\n // Move, `before[index]` can hold a DIFFERENT element than the one whose\n // stable form sits at `before_stable[index]`, and diffing the wrong one\n // silently drops the edit (fuzz seed 340: `['4', …, true, …]` →\n // `[true, …]` moved `true` from 4 to 0, then diffed the original\n // `before[4]` — which was `true` — against `true`, emitting nothing for\n // the leftover string).\n const before_sim = before.slice();\n\n // Elements spliced out of `before` while walking the loop (the deletion\n // branch below). Remove paths are source coordinates — indices in the\n // ORIGINAL array — because the patcher applies same-array removals in\n // descending index order (see reorder() in patch.ts), so each emitted\n // index must stay valid against the un-shifted array.\n let removedBefore = 0;\n let sameArrayAddEmitted = false;\n\n const removeChange = (index: number): Remove => {\n const change: Remove = { type: ChangeType.Remove, path: path.concat(index) };\n if (!sameArrayAddEmitted || removedBefore > 0) {\n // Non-enumerable so `coordinate` stays out of the diff output that\n // callers and tests compare: it's an internal marker for reorder().\n Object.defineProperty(change, 'coordinate', { value: 'source' });\n }\n return change;\n };\n\n // 2. Step through after array making changes to before array as-needed\n for (let index = 0; index < after_stable.length; index++) {\n const value = after_stable[index];\n const overflow = index >= before_stable.length;\n\n // Check if items are the same\n if (!overflow && before_stable[index] === value) {\n continue;\n }\n\n // Check if item has been moved -> shift into place\n const from = overflow ? -1 : before_stable.indexOf(value, index + 1);\n if (from > -1) {\n // Is `before_stable[index]` (the mismatched element at this slot) a\n // surplus duplicate — more copies surviving in `before`'s unmatched\n // suffix than `after` demands? When so, the extra copy is genuinely\n // gone from this position and a removal in place is the honest edit.\n const valueAt = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === valueAt) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === valueAt) afterCount++;\n }\n const surplusDuplicate = beforeCount > afterCount;\n\n // A true deletion in move shape: the element at this position is\n // absent from `after` entirely (or is a surplus duplicate of a value\n // that later slots still hold), while the after-value sits later in\n // `before`. Without this the element only gets resolved at the end,\n // after a chain of Moves that relocates multiline elements — and the\n // writer corrupts their content (fuzz seed 4765: removing one scalar\n // from a multiline inline array dropped a line of a multiline string;\n // fuzz seed 35943: removing one of several duplicate scalars above a\n // nested multiline array chain-moved the array and corrupted its tail).\n if (layoutSensitiveArray && (after_stable.indexOf(before_stable[index]) === -1 || surplusDuplicate)) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // A Move emitted after an in-place deletion splice: its from/to are\n // simulation coordinates, but the patcher applies ALL removes first\n // (in descending index order) — when a trailing remove follows, the\n // move's source can be pushed out of bounds (fuzz seed 8138). When\n // the displaced element is a surplus duplicate, resolve it as a\n // removal in place instead of a Move: the remaining occurrences stay\n // where they are, so nothing needs to move.\n //\n // (Redundant with the surplus-duplicate removal above when\n // `layoutSensitiveArray` is set, but kept for the non-multiline case\n // where a prior splice already shifted indices and the surplus is\n // unambiguous.)\n if (removedBefore > 0 && surplusDuplicate) {\n changes.push(removeChange(index + removedBefore));\n before_stable.splice(index, 1);\n before_sim.splice(index, 1);\n removedBefore++;\n index--;\n continue;\n }\n\n // After an in-place removal this array is one element short at this\n // slot, so the after-value found later in `before` is NOT being\n // relocated — a fresh copy is needed here. Relocating it via a Move\n // drags multiline elements through a chain that later ADDs a new copy\n // anyway, and the writer corrupts their content (fuzz seed 62263: a\n // nested array above a multiline inline table replaced by a duplicate\n // scalar emitted Remove + Move + Add and mangled the table).\n if (layoutSensitiveArray && removedBefore > 0) {\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // The fresh copy is spliced in BEFORE the original (at `from`), so it\n // shifts every later sim element — including the original we just\n // declined to move — one slot right. `removedBefore` models the\n // LEFT-shift of a prior remove, so a later Remove's source index\n // (`index + removedBefore`) is off by one and removes the wrong\n // element (fuzz seed 179377: `[false, '''…''', …]` edited and trimmed\n // removed its neighbour instead of the surplus scalar). Cancelling\n // one unit of the remove shift keeps the sim↔source mapping aligned.\n removedBefore--;\n continue;\n }\n\n changes.push({\n type: ChangeType.Move,\n path,\n from,\n to: index\n });\n\n const move = before_stable.splice(from, 1);\n before_stable.splice(index, 0, ...move);\n const moveValues = before_sim.splice(from, 1);\n before_sim.splice(index, 0, ...moveValues);\n\n continue;\n }\n\n // Check if item is removed -> assume it's been edited and replace.\n //\n // `after.includes(value)` alone is not enough: when the value also\n // occurs later in the array, the element is read as \"kept\", so the\n // mismatch becomes an Add plus a chain of Moves that re-finds the\n // duplicate — a pathological diff for a plain in-place edit (fuzz seed\n // 1406: `true` → `'4'` with another `true` later emitted Add(1) + six\n // Moves + Remove(10), and the writer corrupted a multiline string).\n // A duplicate further along in `before` can serve the later `after`\n // slot, so this occurrence is surplus whenever `before`'s unmatched\n // suffix holds more copies of the value than `after`'s does — then the\n // element is genuinely gone from its position and edited in place.\n let surplus = false;\n if (!overflow) {\n const value = before_stable[index];\n let beforeCount = 0;\n for (let i = index; i < before_stable.length; i++) {\n if (before_stable[i] === value) beforeCount++;\n }\n let afterCount = 0;\n for (let i = index; i < after_stable.length; i++) {\n if (after_stable[i] === value) afterCount++;\n }\n surplus = beforeCount > afterCount;\n }\n const removed = !overflow && surplus;\n if (removed) {\n merge(changes, diff(before_sim[index], after[index], path.concat(index), options));\n before_stable[index] = value;\n before_sim[index] = after[index];\n\n continue;\n }\n\n // Add as new item and shift existing\n changes.push({\n type: ChangeType.Add,\n path: path.concat(index)\n });\n sameArrayAddEmitted = true;\n before_stable.splice(index, 0, value);\n before_sim.splice(index, 0, after[index]);\n // Same source-index bookkeeping as the refused-move Add above: splicing a\n // new element in front of the surviving suffix shifts later sim indices\n // right by one, so a later Remove's source index (`index + removedBefore`)\n // is one too far right and targets the wrong element when a prior remove\n // is still pending. Cancel one unit of the remove shift (fuzz seed\n // 208822: editing a duplicate scalar and trimming a multiline array\n // removed the multiline string instead of the plain scalar).\n if (removedBefore > 0) removedBefore--;\n }\n\n // 3. Remove any remaining overflow items\n for (let i = after_stable.length; i < before_stable.length; i++) {\n changes.push(removeCh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AAI,UAAU;EACd,IAAI,CAAC,UAAU;GACb,MAAM,QAAQ,cAAc;GAC5B,IAAI,cAAc;GAClB,KAAK,IAAI,IAAI,OAAO,IAAI,cAAc,QAAQ,KAC5C,IAAI,cAAc,OAAO,OAAO;GAElC,IAAI,aAAa;GACjB,KAAK,IAAI,IAAI,OAAO,IAAI,aAAa,QAAQ,KAC3C,IAAI,aAAa,OAAO,OAAO;GAEjC,UAAU,cAAc;EAC1B;EAEA,IADgB,CAAC,YAAY,SAChB;GACX,MAAM,SAAS,KAAK,WAAW,QAAQ,MAAM,QAAQ,KAAK,OAAO,KAAK,GAAG,OAAO,CAAC;GACjF,cAAc,SAAS;GACvB,WAAW,SAAS,MAAM;GAE1B;EACF;EAGA,QAAQ,KAAK;GACX;GACA,MAAM,KAAK,OAAO,KAAK;EACzB,CAAC;EACD,sBAAsB;EACtB,cAAc,OAAO,OAAO,GAAG,KAAK;EACpC,WAAW,OAAO,OAAO,GAAG,MAAM,MAAM;EAQxC,IAAI,gBAAgB,GAAG;CACzB;CAGA,KAAK,IAAI,IAAI,aAAa,QAAQ,IAAI,cAAc,QAAQ,KAC1D,QAAQ,KAAK,aAAa,IAAI,aAAa,CAAC;CAG9C,OAAO;AACT"}
@@ -1,193 +0,0 @@
1
- //! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- import { isFloat } from "./cst.js";
3
- import { DateFormatHelper, LocalDate, LocalDateTime, LocalTime, OffsetDateTime } from "./date-format.js";
4
- import { isNegativeNan } from "./utils.js";
5
- import { canUseLiteralString, canUseMultilineLiteral } from "./literal-string.js";
6
- import { PatchLiteError, formatPath } from "./diff-lite.js";
7
-
8
- //#region src/encode-lite.ts
9
- /**
10
- * Encodes a JavaScript leaf value as valid TOML, independent of the full
11
- * formatting pipeline. Only the value span is produced; the surrounding key,
12
- * equals sign, whitespace and comments are never regenerated.
13
- */
14
- function encodeValue(value, existingValue, path) {
15
- const type = typeof value;
16
- if (type === "string") return encodeString(value, existingValue === null || existingValue === void 0 ? void 0 : existingValue.raw);
17
- if (type === "boolean") return value ? "true" : "false";
18
- if (type === "bigint") return value.toString();
19
- if (type === "number") {
20
- if (!Number.isFinite(value)) return encodeNonFinite(value);
21
- if (Number.isSafeInteger(value) && !Object.is(value, -0) && !isFloat(existingValue)) return encodeInteger(value, existingValue === null || existingValue === void 0 ? void 0 : existingValue.raw);
22
- return encodeFloat(value, isFloat(existingValue) ? existingValue.raw : void 0);
23
- }
24
- if (value instanceof Date) return encodeDate(value, existingValue);
25
- throw new PatchLiteError("UnsupportedValue", path, `Unsupported value type ${Object.prototype.toString.call(value)} at ${formatPath(path)}`);
26
- }
27
- /**
28
- * Encodes a Date as TOML while keeping the source value's formatting: date vs
29
- * time vs datetime kind, fractional-digit count, space separator and offset
30
- * style are all taken from the existing value's raw text, exactly as the full
31
- * patch() does.
32
- */
33
- function encodeDate(value, existingValue) {
34
- const raw = existingValue === null || existingValue === void 0 ? void 0 : existingValue.raw;
35
- const native = toTomlPatchDate(value);
36
- if (typeof raw !== "string") return native.toISOString();
37
- return DateFormatHelper.createDateWithOriginalFormat(native, raw).toISOString();
38
- }
39
- /**
40
- * Converts a smol-toml `TomlDate` to the matching toml-patch class. Duck-typed
41
- * (the two packages have distinct class objects) and kept local so the lite
42
- * bundle does not import the vendored smol-toml date module. The `.000` suffix
43
- * smol-toml always writes for a zero fraction is dropped, so it does not leak
44
- * into the output and the result matches the full patch() byte for byte.
45
- */
46
- function toTomlPatchDate(value) {
47
- const v = value;
48
- if (!(typeof v.isDate === "function" && typeof v.isTime === "function")) return value;
49
- const canonical = value.toISOString().replace(/\.000(?=([Zz]|[+-]\d{2}:\d{2})$|$)/, "");
50
- if (v.isDate()) return new LocalDate(canonical);
51
- if (v.isTime()) return new LocalTime(canonical, canonical);
52
- if (v.isLocal()) return new LocalDateTime(canonical, false);
53
- return new OffsetDateTime(canonical, false);
54
- }
55
- /** Detects the radix and prefix of a prefixed integer literal (`0x`/`0o`/`0b`). */
56
- function integerRadixOf(raw) {
57
- if (raw.startsWith("0x")) return {
58
- radix: 16,
59
- prefix: "0x"
60
- };
61
- if (raw.startsWith("0o")) return {
62
- radix: 8,
63
- prefix: "0o"
64
- };
65
- if (raw.startsWith("0b")) return {
66
- radix: 2,
67
- prefix: "0b"
68
- };
69
- }
70
- function encodeInteger(value, existingRaw) {
71
- if (existingRaw) {
72
- const radixInfo = integerRadixOf(existingRaw);
73
- if (radixInfo && value >= 0) {
74
- const uppercaseHex = radixInfo.radix === 16 && /[A-F]/.test(existingRaw);
75
- let digits = value.toString(radixInfo.radix);
76
- if (uppercaseHex) digits = digits.toUpperCase();
77
- return radixInfo.prefix + digits;
78
- }
79
- }
80
- return String(value);
81
- }
82
- function encodeFloat(value, existingRaw) {
83
- if (Object.is(value, -0)) return "-0.0";
84
- if (existingRaw && /[eE]/.test(existingRaw)) return encodeExponentFloat(value, existingRaw);
85
- const raw = String(value);
86
- return /[.eE]/.test(raw) ? raw : `${raw}.0`;
87
- }
88
- /**
89
- * Renders a value in exponent notation, matching an existing float's style:
90
- * a TOML exponent (no leading `+`) and the mantissa's decimal-place count, but
91
- * dropping a non-zero fraction once the new value becomes a whole number.
92
- */
93
- function encodeExponentFloat(value, existingRaw) {
94
- const mantissaRaw = existingRaw.slice(0, existingRaw.search(/[eE]/));
95
- const dotIndex = mantissaRaw.indexOf(".");
96
- const fraction = dotIndex === -1 ? "" : mantissaRaw.slice(dotIndex + 1);
97
- const isRound = !/[1-9]/.test(fraction);
98
- const minDecimals = Number.isInteger(value) && !Object.is(value, -0) ? isRound ? fraction.length : 0 : 0;
99
- const [mantissa, exponent] = value.toExponential().split(/[eE]/);
100
- const mantissaDecimals = mantissa.includes(".") ? mantissa.length - mantissa.indexOf(".") - 1 : 0;
101
- const decimals = Math.max(minDecimals, mantissaDecimals);
102
- return `${decimals > 0 ? Number(mantissa).toFixed(decimals) : String(Number(mantissa))}${existingRaw.includes("E") ? "E" : "e"}${exponent.replace(/^\+/, "")}`;
103
- }
104
- function encodeNonFinite(value) {
105
- if (Number.isNaN(value)) return isNegativeNan(value) ? "-nan" : "nan";
106
- return value > 0 ? "inf" : "-inf";
107
- }
108
- /**
109
- * Encodes a string while preserving the source's literal style. A multiline
110
- * literal (`'''`) keeps its delimiters and leading newline, and a single-line
111
- * literal (`'`) stays single-quoted. Backslashes are left untouched because
112
- * literal strings do not escape, matching the full patch(). A value that can no
113
- * longer be written literally grows to a multiline literal where possible and
114
- * falls back to a basic string otherwise.
115
- */
116
- /**
117
- * The newline to write directly after a multiline delimiter.
118
- *
119
- * TOML drops a newline that immediately follows the opening delimiter, so a
120
- * value that starts with one needs an extra, disposable newline in front of it
121
- * to survive the round trip.
122
- */
123
- function multilineLeadingNewLine(existingRaw, delimiter, content) {
124
- if (existingRaw.startsWith(delimiter + "\r\n")) return "\r\n";
125
- if (existingRaw.startsWith(delimiter + "\n")) return "\n";
126
- if (content.startsWith("\r\n")) return "\r\n";
127
- return content.startsWith("\n") ? "\n" : "";
128
- }
129
- function encodeString(value, existingRaw) {
130
- if (existingRaw) {
131
- if (existingRaw.startsWith("'''")) {
132
- if (!canUseMultilineLiteral(value)) return encodeBasicString(value);
133
- return "'''" + multilineLeadingNewLine(existingRaw, "'''", value) + value + "'''";
134
- }
135
- if (existingRaw.startsWith("\"\"\"")) return encodeMultilineBasicString(value, existingRaw);
136
- if (existingRaw.startsWith("'")) {
137
- if (canUseLiteralString(value)) return "'" + value + "'";
138
- if (canUseMultilineLiteral(value)) return "'''" + multilineLeadingNewLine(existingRaw, "'''", value) + value + "'''";
139
- }
140
- }
141
- return encodeBasicString(value);
142
- }
143
- /**
144
- * Encodes a value as a multiline basic string (`"""`), preserving the leading
145
- * newline style of the source and escaping backslashes, control characters and
146
- * embedded triple quotes, matching the full patch().
147
- */
148
- function encodeMultilineBasicString(value, existingRaw) {
149
- const content = escapeMultilineBasicContent(value);
150
- return "\"\"\"" + multilineLeadingNewLine(existingRaw, "\"\"\"", content) + content + "\"\"\"";
151
- }
152
- /**
153
- * Escapes the content of a multiline basic string: backslashes are doubled,
154
- * control characters are escaped, newlines stay literal (CR only as part of
155
- * CRLF), and embedded `"""` is protected as `""\"`.
156
- */
157
- function escapeMultilineBasicContent(value) {
158
- let out = "";
159
- for (let i = 0; i < value.length; i++) {
160
- const ch = value[i];
161
- const code = value.charCodeAt(i);
162
- if (ch === "\\") out += "\\\\";
163
- else if (ch === "\b") out += "\\b";
164
- else if (ch === " ") out += "\\t";
165
- else if (ch === "\n") out += "\n";
166
- else if (ch === "\f") out += "\\f";
167
- else if (ch === "\r") out += value.charCodeAt(i + 1) === 10 ? "\r" : "\\r";
168
- else if (code >= 0 && code <= 7 || code === 11 || code >= 14 && code <= 31 || code === 127) out += "\\u" + code.toString(16).padStart(4, "0").toUpperCase();
169
- else out += ch;
170
- }
171
- return out.replace(/"""/g, "\"\"\\\"");
172
- }
173
- function encodeBasicString(value) {
174
- let out = "\"";
175
- for (const ch of value) {
176
- const code = ch.codePointAt(0);
177
- if (ch === "\"") out += "\\\"";
178
- else if (ch === "\\") out += "\\\\";
179
- else if (ch === "\b") out += "\\b";
180
- else if (ch === " ") out += "\\t";
181
- else if (ch === "\n") out += "\\n";
182
- else if (ch === "\f") out += "\\f";
183
- else if (ch === "\r") out += "\\r";
184
- else if (code < 32 || code === 127) out += "\\u" + code.toString(16).padStart(4, "0").toUpperCase();
185
- else out += ch;
186
- }
187
- out += "\"";
188
- return out;
189
- }
190
-
191
- //#endregion
192
- export { encodeValue };
193
- //# sourceMappingURL=encode-lite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode-lite.js","names":["isFloatNode"],"sources":["../../src/encode-lite.ts"],"sourcesContent":["import { isFloat as isFloatNode } from './cst';\nimport { DateFormatHelper, LocalDate, LocalTime, LocalDateTime, OffsetDateTime } from './date-format';\nimport { PatchLiteError, formatPath, Path } from './diff-lite';\nimport { canUseLiteralString, canUseMultilineLiteral } from './literal-string';\nimport { isNegativeNan } from './utils';\n\n/**\n * Encodes a JavaScript leaf value as valid TOML, independent of the full\n * formatting pipeline. Only the value span is produced; the surrounding key,\n * equals sign, whitespace and comments are never regenerated.\n */\nexport function encodeValue(value: any, existingValue: any, path: Path): string {\n const type = typeof value;\n\n if (type === 'string') return encodeString(value, existingValue?.raw);\n if (type === 'boolean') return value ? 'true' : 'false';\n if (type === 'bigint') return value.toString();\n\n if (type === 'number') {\n if (!Number.isFinite(value)) return encodeNonFinite(value);\n if (Number.isSafeInteger(value) && !Object.is(value, -0) && !isFloatNode(existingValue)) {\n return encodeInteger(value, existingValue?.raw);\n }\n return encodeFloat(value, isFloatNode(existingValue) ? existingValue.raw : undefined);\n }\n\n if (value instanceof Date) {\n return encodeDate(value, existingValue);\n }\n\n throw new PatchLiteError(\n 'UnsupportedValue',\n path,\n `Unsupported value type ${Object.prototype.toString.call(value)} at ${formatPath(path)}`\n );\n}\n\n/**\n * Encodes a Date as TOML while keeping the source value's formatting: date vs\n * time vs datetime kind, fractional-digit count, space separator and offset\n * style are all taken from the existing value's raw text, exactly as the full\n * patch() does.\n */\nfunction encodeDate(value: Date, existingValue: any): string {\n const raw = existingValue?.raw;\n const native = toTomlPatchDate(value);\n if (typeof raw !== 'string') return native.toISOString();\n return DateFormatHelper.createDateWithOriginalFormat(native, raw).toISOString();\n}\n\n/**\n * Converts a smol-toml `TomlDate` to the matching toml-patch class. Duck-typed\n * (the two packages have distinct class objects) and kept local so the lite\n * bundle does not import the vendored smol-toml date module. The `.000` suffix\n * smol-toml always writes for a zero fraction is dropped, so it does not leak\n * into the output and the result matches the full patch() byte for byte.\n */\nfunction toTomlPatchDate(value: Date): Date {\n const v = value as any;\n const isSmolTomlDate = typeof v.isDate === 'function' && typeof v.isTime === 'function';\n if (!isSmolTomlDate) return value;\n\n const canonical = value.toISOString().replace(/\\.000(?=([Zz]|[+-]\\d{2}:\\d{2})$|$)/, '');\n if (v.isDate()) return new LocalDate(canonical);\n if (v.isTime()) return new LocalTime(canonical, canonical);\n if (v.isLocal()) return new LocalDateTime(canonical, false);\n return new OffsetDateTime(canonical, false);\n}\n\n/** Detects the radix and prefix of a prefixed integer literal (`0x`/`0o`/`0b`). */\nfunction integerRadixOf(raw: string): { radix: number; prefix: string } | undefined {\n if (raw.startsWith('0x')) return { radix: 16, prefix: '0x' };\n if (raw.startsWith('0o')) return { radix: 8, prefix: '0o' };\n if (raw.startsWith('0b')) return { radix: 2, prefix: '0b' };\n return undefined;\n}\n\nfunction encodeInteger(value: number, existingRaw?: string): string {\n if (existingRaw) {\n const radixInfo = integerRadixOf(existingRaw);\n // TOML prefixed integers cannot carry a sign, so negative values fall\n // back to plain decimal.\n if (radixInfo && value >= 0) {\n const uppercaseHex = radixInfo.radix === 16 && /[A-F]/.test(existingRaw);\n let digits = value.toString(radixInfo.radix);\n if (uppercaseHex) digits = digits.toUpperCase();\n return radixInfo.prefix + digits;\n }\n }\n return String(value);\n}\n\nfunction encodeFloat(value: number, existingRaw?: string): string {\n if (Object.is(value, -0)) return '-0.0';\n\n // Preserve exponent notation when the source used it (e.g. `1.0e10` ->\n // `1.0e11`) rather than expanding into a long plain float.\n if (existingRaw && /[eE]/.test(existingRaw)) {\n return encodeExponentFloat(value, existingRaw);\n }\n\n const raw = String(value);\n return /[.eE]/.test(raw) ? raw : `${raw}.0`;\n}\n\n/**\n * Renders a value in exponent notation, matching an existing float's style:\n * a TOML exponent (no leading `+`) and the mantissa's decimal-place count, but\n * dropping a non-zero fraction once the new value becomes a whole number.\n */\nfunction encodeExponentFloat(value: number, existingRaw: string): string {\n const mantissaRaw = existingRaw.slice(0, existingRaw.search(/[eE]/));\n const dotIndex = mantissaRaw.indexOf('.');\n const fraction = dotIndex === -1 ? '' : mantissaRaw.slice(dotIndex + 1);\n const isRound = !/[1-9]/.test(fraction);\n const valueIsIntegral = Number.isInteger(value) && !Object.is(value, -0);\n\n // Keep the original's decimal count only for an explicit \"round\" float; a\n // non-zero fraction is insignificant once the new value becomes a whole number.\n const minDecimals = valueIsIntegral ? (isRound ? fraction.length : 0) : 0;\n\n const [mantissa, exponent] = value.toExponential().split(/[eE]/);\n const mantissaDecimals = mantissa.includes('.') ? mantissa.length - mantissa.indexOf('.') - 1 : 0;\n const decimals = Math.max(minDecimals, mantissaDecimals);\n const renderedMantissa = decimals > 0\n ? Number(mantissa).toFixed(decimals)\n : String(Number(mantissa));\n const uppercaseExponent = existingRaw.includes('E');\n return `${renderedMantissa}${uppercaseExponent ? 'E' : 'e'}${exponent.replace(/^\\+/, '')}`;\n}\n\nfunction encodeNonFinite(value: number): string {\n // `-nan` is a distinct TOML spelling that round-trips, so the sign has to be\n // written out; emitting a plain `nan` would make the value look changed again\n // on the next call.\n if (Number.isNaN(value)) return isNegativeNan(value) ? '-nan' : 'nan';\n return value > 0 ? 'inf' : '-inf';\n}\n\n/**\n * Encodes a string while preserving the source's literal style. A multiline\n * literal (`'''`) keeps its delimiters and leading newline, and a single-line\n * literal (`'`) stays single-quoted. Backslashes are left untouched because\n * literal strings do not escape, matching the full patch(). A value that can no\n * longer be written literally grows to a multiline literal where possible and\n * falls back to a basic string otherwise.\n */\n/**\n * The newline to write directly after a multiline delimiter.\n *\n * TOML drops a newline that immediately follows the opening delimiter, so a\n * value that starts with one needs an extra, disposable newline in front of it\n * to survive the round trip.\n */\nfunction multilineLeadingNewLine(existingRaw: string, delimiter: string, content: string): string {\n if (existingRaw.startsWith(delimiter + '\\r\\n')) return '\\r\\n';\n if (existingRaw.startsWith(delimiter + '\\n')) return '\\n';\n if (content.startsWith('\\r\\n')) return '\\r\\n';\n return content.startsWith('\\n') ? '\\n' : '';\n}\n\nfunction encodeString(value: string, existingRaw?: string): string {\n if (existingRaw) {\n if (existingRaw.startsWith(\"'''\")) {\n if (!canUseMultilineLiteral(value)) return encodeBasicString(value);\n return \"'''\" + multilineLeadingNewLine(existingRaw, \"'''\", value) + value + \"'''\";\n }\n if (existingRaw.startsWith('\"\"\"')) {\n return encodeMultilineBasicString(value, existingRaw);\n }\n if (existingRaw.startsWith(\"'\")) {\n if (canUseLiteralString(value)) return \"'\" + value + \"'\";\n // Single quotes are non-negotiable but one of them is: a value holding an\n // apostrophe or a newline moves up to a multiline literal.\n if (canUseMultilineLiteral(value)) {\n return \"'''\" + multilineLeadingNewLine(existingRaw, \"'''\", value) + value + \"'''\";\n }\n }\n }\n return encodeBasicString(value);\n}\n\n/**\n * Encodes a value as a multiline basic string (`\"\"\"`), preserving the leading\n * newline style of the source and escaping backslashes, control characters and\n * embedded triple quotes, matching the full patch().\n */\nfunction encodeMultilineBasicString(value: string, existingRaw: string): string {\n const content = escapeMultilineBasicContent(value);\n return '\"\"\"' + multilineLeadingNewLine(existingRaw, '\"\"\"', content) + content + '\"\"\"';\n}\n\n/**\n * Escapes the content of a multiline basic string: backslashes are doubled,\n * control characters are escaped, newlines stay literal (CR only as part of\n * CRLF), and embedded `\"\"\"` is protected as `\"\"\\\"`.\n */\nfunction escapeMultilineBasicContent(value: string): string {\n let out = '';\n for (let i = 0; i < value.length; i++) {\n const ch = value[i];\n const code = value.charCodeAt(i);\n if (ch === '\\\\') out += '\\\\\\\\';\n else if (ch === '\\b') out += '\\\\b';\n else if (ch === '\\t') out += '\\\\t';\n else if (ch === '\\n') out += '\\n';\n else if (ch === '\\f') out += '\\\\f';\n else if (ch === '\\r') {\n // A carriage return is only valid when part of CRLF; escape it otherwise.\n out += value.charCodeAt(i + 1) === 0x0a ? '\\r' : '\\\\r';\n } else if (\n (code >= 0x00 && code <= 0x07) ||\n code === 0x0b ||\n (code >= 0x0e && code <= 0x1f) ||\n code === 0x7f\n ) {\n out += '\\\\u' + code.toString(16).padStart(4, '0').toUpperCase();\n } else {\n out += ch;\n }\n }\n return out.replace(/\"\"\"/g, '\"\"\\\\\"');\n}\n\nfunction encodeBasicString(value: string): string {\n let out = '\"';\n\n for (const ch of value) {\n const code = ch.codePointAt(0)!;\n\n if (ch === '\"') out += '\\\\\"';\n else if (ch === '\\\\') out += '\\\\\\\\';\n else if (ch === '\\b') out += '\\\\b';\n else if (ch === '\\t') out += '\\\\t';\n else if (ch === '\\n') out += '\\\\n';\n else if (ch === '\\f') out += '\\\\f';\n else if (ch === '\\r') out += '\\\\r';\n else if (code < 0x20 || code === 0x7f) out += '\\\\u' + code.toString(16).padStart(4, '0').toUpperCase();\n else out += ch;\n }\n\n out += '\"';\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,YAAY,OAAY,eAAoB,MAAoB;CAC9E,MAAM,OAAO,OAAO;CAEpB,IAAI,SAAS,UAAU,OAAO,aAAa,qEAAO,cAAe,GAAG;CACpE,IAAI,SAAS,WAAW,OAAO,QAAQ,SAAS;CAChD,IAAI,SAAS,UAAU,OAAO,MAAM,SAAS;CAE7C,IAAI,SAAS,UAAU;EACrB,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO,gBAAgB,KAAK;EACzD,IAAI,OAAO,cAAc,KAAK,KAAK,CAAC,OAAO,GAAG,OAAO,EAAE,KAAK,CAACA,QAAY,aAAa,GACpF,OAAO,cAAc,qEAAO,cAAe,GAAG;EAEhD,OAAO,YAAY,OAAOA,QAAY,aAAa,IAAI,cAAc,MAAM,MAAS;CACtF;CAEA,IAAI,iBAAiB,MACnB,OAAO,WAAW,OAAO,aAAa;CAGxC,MAAM,IAAI,eACR,oBACA,MACA,0BAA0B,OAAO,UAAU,SAAS,KAAK,KAAK,EAAE,MAAM,WAAW,IAAI,GACvF;AACF;;;;;;;AAQA,SAAS,WAAW,OAAa,eAA4B;CAC3D,MAAM,oEAAM,cAAe;CAC3B,MAAM,SAAS,gBAAgB,KAAK;CACpC,IAAI,OAAO,QAAQ,UAAU,OAAO,OAAO,YAAY;CACvD,OAAO,iBAAiB,6BAA6B,QAAQ,GAAG,CAAC,CAAC,YAAY;AAChF;;;;;;;;AASA,SAAS,gBAAgB,OAAmB;CAC1C,MAAM,IAAI;CAEV,IAAI,EADmB,OAAO,EAAE,WAAW,cAAc,OAAO,EAAE,WAAW,aACxD,OAAO;CAE5B,MAA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