@decimalturn/toml-patch 0.3.3 → 0.3.8
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/LICENSE +2 -1
- package/README.md +40 -2
- package/dist/toml-patch.cjs.min.js +2 -2
- package/dist/toml-patch.cjs.min.js.map +1 -1
- package/dist/toml-patch.d.ts +30 -1
- package/dist/toml-patch.es.js +196 -34
- package/dist/toml-patch.umd.min.js +2 -2
- package/dist/toml-patch.umd.min.js.map +1 -1
- package/package.json +21 -14
package/dist/toml-patch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v0.3.
|
|
1
|
+
//! @decimalturn/toml-patch v0.3.8 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
2
|
interface Format {
|
|
3
3
|
printWidth?: number;
|
|
4
4
|
tabWidth?: number;
|
|
@@ -7,9 +7,38 @@ interface Format {
|
|
|
7
7
|
bracketSpacing?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Applies modifications to a TOML document by comparing an existing TOML string with updated JavaScript data.
|
|
12
|
+
*
|
|
13
|
+
* This function preserves formatting and comments from the existing TOML document while
|
|
14
|
+
* applying changes from the updated data structure. It performs a diff between the existing
|
|
15
|
+
* and updated data, then strategically applies only the necessary changes to maintain the
|
|
16
|
+
* original document structure as much as possible.
|
|
17
|
+
*
|
|
18
|
+
* @param existing - The original TOML document as a string
|
|
19
|
+
* @param updated - The updated JavaScript object with desired changes
|
|
20
|
+
* @param format - Optional formatting options to apply to new or modified sections
|
|
21
|
+
* @returns A new TOML string with the changes applied
|
|
22
|
+
*/
|
|
10
23
|
declare function patch(existing: string, updated: any, format?: Format): string;
|
|
11
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Parses a TOML string into a JavaScript object.
|
|
27
|
+
* The function converts TOML syntax to its JavaScript equivalent.
|
|
28
|
+
* This proceeds in two steps: first, it parses the TOML string into an AST,
|
|
29
|
+
* and then it converts the AST into a JavaScript object.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The TOML string to parse
|
|
32
|
+
* @returns The parsed JavaScript object
|
|
33
|
+
*/
|
|
12
34
|
declare function parse(value: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* Converts a JavaScript object to a TOML string.
|
|
37
|
+
*
|
|
38
|
+
* @param value - The JavaScript object to stringify
|
|
39
|
+
* @param format - Optional formatting options for the resulting TOML
|
|
40
|
+
* @returns The stringified TOML representation
|
|
41
|
+
*/
|
|
13
42
|
declare function stringify(value: any, format?: Format): string;
|
|
14
43
|
|
|
15
44
|
export { parse, patch, stringify };
|
package/dist/toml-patch.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v0.3.
|
|
1
|
+
//! @decimalturn/toml-patch v0.3.8 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
2
|
var NodeType;
|
|
3
3
|
(function (NodeType) {
|
|
4
4
|
NodeType["Document"] = "Document";
|
|
@@ -161,11 +161,11 @@ function getLine$1(input, position) {
|
|
|
161
161
|
}
|
|
162
162
|
function findLines(input) {
|
|
163
163
|
// exec is stateful, so create new regexp each time
|
|
164
|
-
const BY_NEW_LINE =
|
|
164
|
+
const BY_NEW_LINE = /\r\n|\n/g;
|
|
165
165
|
const indexes = [];
|
|
166
166
|
let match;
|
|
167
167
|
while ((match = BY_NEW_LINE.exec(input)) != null) {
|
|
168
|
-
indexes.push(match.index);
|
|
168
|
+
indexes.push(match.index + match[0].length - 1);
|
|
169
169
|
}
|
|
170
170
|
indexes.push(input.length + 1);
|
|
171
171
|
return indexes;
|
|
@@ -176,6 +176,12 @@ function clonePosition(position) {
|
|
|
176
176
|
function cloneLocation(location) {
|
|
177
177
|
return { start: clonePosition(location.start), end: clonePosition(location.end) };
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Returns a Position at line 1, column 0.
|
|
181
|
+
* This means that lines are 1-indexed and columns are 0-indexed.
|
|
182
|
+
*
|
|
183
|
+
* @returns A Position at line 1, column 0
|
|
184
|
+
*/
|
|
179
185
|
function zero() {
|
|
180
186
|
return { line: 1, column: 0 };
|
|
181
187
|
}
|
|
@@ -420,10 +426,10 @@ function isString(value) {
|
|
|
420
426
|
return typeof value === 'string';
|
|
421
427
|
}
|
|
422
428
|
function isInteger(value) {
|
|
423
|
-
return typeof value === 'number' && value % 1 === 0;
|
|
429
|
+
return typeof value === 'number' && value % 1 === 0 && isFinite(value) && !Object.is(value, -0);
|
|
424
430
|
}
|
|
425
431
|
function isFloat(value) {
|
|
426
|
-
return typeof value === 'number' && !isInteger(value);
|
|
432
|
+
return typeof value === 'number' && (!isInteger(value) || !isFinite(value) || Object.is(value, -0));
|
|
427
433
|
}
|
|
428
434
|
function isBoolean(value) {
|
|
429
435
|
return typeof value === 'boolean';
|
|
@@ -1134,6 +1140,14 @@ function replace(root, parent, existing, replacement) {
|
|
|
1134
1140
|
};
|
|
1135
1141
|
addOffset(offset, getExitOffsets(root), replacement, existing);
|
|
1136
1142
|
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Inserts a child node into the AST.
|
|
1145
|
+
*
|
|
1146
|
+
* @param root - The root node of the AST
|
|
1147
|
+
* @param parent - The parent node to insert the child into
|
|
1148
|
+
* @param child - The child node to insert
|
|
1149
|
+
* @param index - The index at which to insert the child (optional)
|
|
1150
|
+
*/
|
|
1137
1151
|
function insert(root, parent, child, index) {
|
|
1138
1152
|
if (!hasItems(parent)) {
|
|
1139
1153
|
throw new Error(`Unsupported parent type "${parent.type}" for insert`);
|
|
@@ -1176,6 +1190,7 @@ function insertOnNewLine(parent, child, index) {
|
|
|
1176
1190
|
column: !isComment(previous) ? previous.loc.start.column : parent.loc.start.column
|
|
1177
1191
|
}
|
|
1178
1192
|
: clonePosition(parent.loc.start);
|
|
1193
|
+
//TODO: Check the definition for block to see if using isBlock is more appropriate
|
|
1179
1194
|
const is_block = isTable(child) || isTableArray(child);
|
|
1180
1195
|
let leading_lines = 0;
|
|
1181
1196
|
if (use_first_line) ;
|
|
@@ -1322,6 +1337,11 @@ function remove(root, parent, node) {
|
|
|
1322
1337
|
lines: -(removed_span.lines - (keep_line ? 1 : 0)),
|
|
1323
1338
|
columns: -removed_span.columns
|
|
1324
1339
|
};
|
|
1340
|
+
// If there is nothing left, don't perform any offsets
|
|
1341
|
+
if (previous === undefined && next === undefined) {
|
|
1342
|
+
offset.lines = 0;
|
|
1343
|
+
offset.columns = 0;
|
|
1344
|
+
}
|
|
1325
1345
|
// Offset for comma and remove comma that appear in front of the element (if-needed)
|
|
1326
1346
|
if (is_inline && previous_on_same_line) {
|
|
1327
1347
|
offset.columns -= 2;
|
|
@@ -1492,6 +1512,11 @@ function addOffset(offset, offsets, node, from) {
|
|
|
1492
1512
|
offsets.set(node, offset);
|
|
1493
1513
|
}
|
|
1494
1514
|
|
|
1515
|
+
/**
|
|
1516
|
+
* Generates a new TOML document node.
|
|
1517
|
+
*
|
|
1518
|
+
* @returns A new Document node.
|
|
1519
|
+
*/
|
|
1495
1520
|
function generateDocument() {
|
|
1496
1521
|
return {
|
|
1497
1522
|
type: NodeType.Document,
|
|
@@ -1571,7 +1596,7 @@ function generateKeyValue(key, value) {
|
|
|
1571
1596
|
value
|
|
1572
1597
|
};
|
|
1573
1598
|
}
|
|
1574
|
-
const IS_BARE_KEY =
|
|
1599
|
+
const IS_BARE_KEY = /^[\w-]+$/;
|
|
1575
1600
|
function keyValueToRaw(value) {
|
|
1576
1601
|
return value.map(part => (IS_BARE_KEY.test(part) ? part : JSON.stringify(part))).join('.');
|
|
1577
1602
|
}
|
|
@@ -1603,7 +1628,22 @@ function generateInteger(value) {
|
|
|
1603
1628
|
};
|
|
1604
1629
|
}
|
|
1605
1630
|
function generateFloat(value) {
|
|
1606
|
-
|
|
1631
|
+
let raw;
|
|
1632
|
+
if (value === Infinity) {
|
|
1633
|
+
raw = 'inf';
|
|
1634
|
+
}
|
|
1635
|
+
else if (value === -Infinity) {
|
|
1636
|
+
raw = '-inf';
|
|
1637
|
+
}
|
|
1638
|
+
else if (Number.isNaN(value)) {
|
|
1639
|
+
raw = 'nan';
|
|
1640
|
+
}
|
|
1641
|
+
else if (Object.is(value, -0)) {
|
|
1642
|
+
raw = '-0.0';
|
|
1643
|
+
}
|
|
1644
|
+
else {
|
|
1645
|
+
raw = value.toString();
|
|
1646
|
+
}
|
|
1607
1647
|
return {
|
|
1608
1648
|
type: NodeType.Float,
|
|
1609
1649
|
loc: { start: zero(), end: { line: 1, column: raw.length } },
|
|
@@ -1744,18 +1784,29 @@ This function makes sure that properties that are simple values (not objects or
|
|
|
1744
1784
|
and that objects and arrays are ordered last. This makes parseJS more reliable and easier to test.
|
|
1745
1785
|
*/
|
|
1746
1786
|
function reorderElements(value) {
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
result[key] = value[key];
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
// Then add all objects and arrays
|
|
1787
|
+
// Pre-sort keys to avoid multiple iterations
|
|
1788
|
+
const simpleKeys = [];
|
|
1789
|
+
const complexKeys = [];
|
|
1790
|
+
// Separate keys in a single pass
|
|
1755
1791
|
for (const key in value) {
|
|
1756
1792
|
if (isObject(value[key]) || Array.isArray(value[key])) {
|
|
1757
|
-
|
|
1793
|
+
complexKeys.push(key);
|
|
1758
1794
|
}
|
|
1795
|
+
else {
|
|
1796
|
+
simpleKeys.push(key);
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
// Create result with the correct order
|
|
1800
|
+
const result = {};
|
|
1801
|
+
// Add simple values first
|
|
1802
|
+
for (let i = 0; i < simpleKeys.length; i++) {
|
|
1803
|
+
const key = simpleKeys[i];
|
|
1804
|
+
result[key] = value[key];
|
|
1805
|
+
}
|
|
1806
|
+
// Then add complex values
|
|
1807
|
+
for (let i = 0; i < complexKeys.length; i++) {
|
|
1808
|
+
const key = complexKeys[i];
|
|
1809
|
+
result[key] = value[key];
|
|
1759
1810
|
}
|
|
1760
1811
|
return result;
|
|
1761
1812
|
}
|
|
@@ -1841,7 +1892,27 @@ function toJSON(value) {
|
|
|
1841
1892
|
}
|
|
1842
1893
|
|
|
1843
1894
|
const BY_NEW_LINE = /(\r\n|\n)/g;
|
|
1844
|
-
|
|
1895
|
+
/**
|
|
1896
|
+
* Converts an Abstract Syntax Tree (AST) back to TOML format string.
|
|
1897
|
+
*
|
|
1898
|
+
* This function traverses the AST and reconstructs the original TOML document
|
|
1899
|
+
* by writing each node's raw content to the appropriate location coordinates.
|
|
1900
|
+
* It preserves the original formatting, spacing, and structure of the TOML file.
|
|
1901
|
+
*
|
|
1902
|
+
* @param ast - The Abstract Syntax Tree representing the parsed TOML document
|
|
1903
|
+
* @param newline - The newline character(s) to use (\n by default)
|
|
1904
|
+
* @param options - Optional configuration object
|
|
1905
|
+
* @param options.trailingNewline - Number of trailing newlines to add (1 by default)
|
|
1906
|
+
* @returns The reconstructed TOML document as a string
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```typescript
|
|
1910
|
+
* const tomlString = toTOML(ast, '\n', { trailingNewline: 1 });
|
|
1911
|
+
* ```
|
|
1912
|
+
*/
|
|
1913
|
+
function toTOML(ast, newline = '\n', options) {
|
|
1914
|
+
var _a;
|
|
1915
|
+
const trailingNewline = (_a = options === null || options === void 0 ? void 0 : options.trailingNewline) !== null && _a !== void 0 ? _a : 1;
|
|
1845
1916
|
const lines = [];
|
|
1846
1917
|
traverse(ast, {
|
|
1847
1918
|
[NodeType.TableKey](node) {
|
|
@@ -1896,8 +1967,34 @@ function toTOML(ast, newline = '\n') {
|
|
|
1896
1967
|
write(lines, node.loc, node.raw);
|
|
1897
1968
|
}
|
|
1898
1969
|
});
|
|
1899
|
-
return lines.join(newline) + newline;
|
|
1970
|
+
return lines.join(newline) + newline.repeat(trailingNewline);
|
|
1900
1971
|
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Writes raw string content to specific location coordinates within a lines array.
|
|
1974
|
+
*
|
|
1975
|
+
* This function is responsible for placing TOML content at precise positions within
|
|
1976
|
+
* the output lines, handling multi-line content and preserving existing content
|
|
1977
|
+
* around the target location.
|
|
1978
|
+
*
|
|
1979
|
+
* @param lines - Array of string lines representing the TOML document being built.
|
|
1980
|
+
* Lines are 1-indexed but stored in 0-indexed array.
|
|
1981
|
+
* @param loc - Location object specifying where to write the content, containing:
|
|
1982
|
+
* - start: { line: number, column: number } - Starting position (1-indexed line, 0-indexed column)
|
|
1983
|
+
* - end: { line: number, column: number } - Ending position (1-indexed line, 0-indexed column)
|
|
1984
|
+
* @param raw - The raw string content to write at the specified location.
|
|
1985
|
+
* Can contain multiple lines separated by \n or \r\n.
|
|
1986
|
+
*
|
|
1987
|
+
* @throws {Error} When there's a mismatch between location span and raw string line count
|
|
1988
|
+
* @throws {Error} When attempting to write to an uninitialized line
|
|
1989
|
+
*
|
|
1990
|
+
* @example
|
|
1991
|
+
* ```typescript
|
|
1992
|
+
* const lines = ['', ''];
|
|
1993
|
+
* const location = { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } };
|
|
1994
|
+
* write(lines, location, 'key');
|
|
1995
|
+
* // Result: lines[0] becomes 'key'
|
|
1996
|
+
* ```
|
|
1997
|
+
*/
|
|
1901
1998
|
function write(lines, loc, raw) {
|
|
1902
1999
|
const raw_lines = raw.split(BY_NEW_LINE).filter(line => line !== '\n' && line !== '\r\n');
|
|
1903
2000
|
const expected_lines = loc.end.line - loc.start.line + 1;
|
|
@@ -1906,6 +2003,10 @@ function write(lines, loc, raw) {
|
|
|
1906
2003
|
}
|
|
1907
2004
|
for (let i = loc.start.line; i <= loc.end.line; i++) {
|
|
1908
2005
|
const line = getLine(lines, i);
|
|
2006
|
+
//Throw if line is uninitialized
|
|
2007
|
+
if (line === undefined) {
|
|
2008
|
+
throw new Error(`Line ${i} is uninitialized when writing "${raw}" at ${loc.start.line}:${loc.start.column} to ${loc.end.line}:${loc.end.column}`);
|
|
2009
|
+
}
|
|
1909
2010
|
const is_start_line = i === loc.start.line;
|
|
1910
2011
|
const is_end_line = i === loc.end.line;
|
|
1911
2012
|
const before = is_start_line
|
|
@@ -1915,6 +2016,24 @@ function write(lines, loc, raw) {
|
|
|
1915
2016
|
lines[i - 1] = before + raw_lines[i - loc.start.line] + after;
|
|
1916
2017
|
}
|
|
1917
2018
|
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Safely retrieves a line from the lines array, initializing empty lines as needed.
|
|
2021
|
+
*
|
|
2022
|
+
* This helper function handles the conversion between 1-indexed line numbers (used in locations)
|
|
2023
|
+
* and 0-indexed array positions. It ensures that accessing a line that doesn't exist yet
|
|
2024
|
+
* will initialize all preceding lines with empty strings.
|
|
2025
|
+
*
|
|
2026
|
+
* @param lines - Array of string lines representing the document
|
|
2027
|
+
* @param index - 1-indexed line number to retrieve
|
|
2028
|
+
* @returns The line content as a string, or empty string for new lines
|
|
2029
|
+
*
|
|
2030
|
+
* @example
|
|
2031
|
+
* ```typescript
|
|
2032
|
+
* const lines = ['first line'];
|
|
2033
|
+
* const line = getLine(lines, 3); // Initializes lines[1] and lines[2] as empty strings
|
|
2034
|
+
* // lines becomes ['first line', '', '']
|
|
2035
|
+
* ```
|
|
2036
|
+
*/
|
|
1918
2037
|
function getLine(lines, index) {
|
|
1919
2038
|
if (!lines[index - 1]) {
|
|
1920
2039
|
for (let i = 0; i < index; i++) {
|
|
@@ -1931,8 +2050,7 @@ function toJS(ast, input = '') {
|
|
|
1931
2050
|
const table_arrays = new Set();
|
|
1932
2051
|
const defined = new Set();
|
|
1933
2052
|
let active = result;
|
|
1934
|
-
let
|
|
1935
|
-
let skip = false;
|
|
2053
|
+
let skip_depth = 0;
|
|
1936
2054
|
traverse(ast, {
|
|
1937
2055
|
[NodeType.Table](node) {
|
|
1938
2056
|
const key = node.key.item.value;
|
|
@@ -1964,7 +2082,7 @@ function toJS(ast, input = '') {
|
|
|
1964
2082
|
},
|
|
1965
2083
|
[NodeType.KeyValue]: {
|
|
1966
2084
|
enter(node) {
|
|
1967
|
-
if (
|
|
2085
|
+
if (skip_depth > 0)
|
|
1968
2086
|
return;
|
|
1969
2087
|
const key = node.key.value;
|
|
1970
2088
|
try {
|
|
@@ -1978,24 +2096,15 @@ function toJS(ast, input = '') {
|
|
|
1978
2096
|
const target = key.length > 1 ? ensureTable(active, key.slice(0, -1)) : active;
|
|
1979
2097
|
target[last(key)] = value;
|
|
1980
2098
|
defined.add(joinKey(key));
|
|
1981
|
-
if (isInlineTable(node.value)) {
|
|
1982
|
-
previous_active = active;
|
|
1983
|
-
active = value;
|
|
1984
|
-
}
|
|
1985
|
-
},
|
|
1986
|
-
exit(node) {
|
|
1987
|
-
if (isInlineTable(node.value)) {
|
|
1988
|
-
active = previous_active;
|
|
1989
|
-
}
|
|
1990
2099
|
}
|
|
1991
2100
|
},
|
|
1992
2101
|
[NodeType.InlineTable]: {
|
|
1993
2102
|
enter() {
|
|
1994
2103
|
// Handled by toValue
|
|
1995
|
-
|
|
2104
|
+
skip_depth++;
|
|
1996
2105
|
},
|
|
1997
2106
|
exit() {
|
|
1998
|
-
|
|
2107
|
+
skip_depth--;
|
|
1999
2108
|
}
|
|
2000
2109
|
}
|
|
2001
2110
|
});
|
|
@@ -2295,6 +2404,19 @@ function findParent(node, path) {
|
|
|
2295
2404
|
return parent;
|
|
2296
2405
|
}
|
|
2297
2406
|
|
|
2407
|
+
/**
|
|
2408
|
+
* Applies modifications to a TOML document by comparing an existing TOML string with updated JavaScript data.
|
|
2409
|
+
*
|
|
2410
|
+
* This function preserves formatting and comments from the existing TOML document while
|
|
2411
|
+
* applying changes from the updated data structure. It performs a diff between the existing
|
|
2412
|
+
* and updated data, then strategically applies only the necessary changes to maintain the
|
|
2413
|
+
* original document structure as much as possible.
|
|
2414
|
+
*
|
|
2415
|
+
* @param existing - The original TOML document as a string
|
|
2416
|
+
* @param updated - The updated JavaScript object with desired changes
|
|
2417
|
+
* @param format - Optional formatting options to apply to new or modified sections
|
|
2418
|
+
* @returns A new TOML string with the changes applied
|
|
2419
|
+
*/
|
|
2298
2420
|
function patch(existing, updated, format) {
|
|
2299
2421
|
const existing_ast = parseTOML(existing);
|
|
2300
2422
|
const items = [...existing_ast];
|
|
@@ -2309,7 +2431,30 @@ function patch(existing, updated, format) {
|
|
|
2309
2431
|
const patched_document = applyChanges(existing_document, updated_document, changes);
|
|
2310
2432
|
// Validate the patched_document
|
|
2311
2433
|
//validate(patched_document);
|
|
2312
|
-
|
|
2434
|
+
// Detect the line ending style from the original file
|
|
2435
|
+
let newline = '\n'; // Default to LF
|
|
2436
|
+
const lfIndex = existing.indexOf('\n');
|
|
2437
|
+
// Even if a LF is found, it could that there is a CR right before the LF
|
|
2438
|
+
if (lfIndex > 0 && existing.substring(lfIndex - 1, lfIndex) === '\r') {
|
|
2439
|
+
newline = '\r\n'; // File uses CRLF
|
|
2440
|
+
}
|
|
2441
|
+
// Count consecutive trailing newlines
|
|
2442
|
+
function countTrailingNewlines(str, newlineChar) {
|
|
2443
|
+
let count = 0;
|
|
2444
|
+
let pos = str.length;
|
|
2445
|
+
while (pos >= newlineChar.length) {
|
|
2446
|
+
if (str.substring(pos - newlineChar.length, pos) === newlineChar) {
|
|
2447
|
+
count++;
|
|
2448
|
+
pos -= newlineChar.length;
|
|
2449
|
+
}
|
|
2450
|
+
else {
|
|
2451
|
+
break;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return count;
|
|
2455
|
+
}
|
|
2456
|
+
const trailingNewlineCount = countTrailingNewlines(existing, newline);
|
|
2457
|
+
return toTOML(patched_document.items, newline, { trailingNewline: trailingNewlineCount });
|
|
2313
2458
|
}
|
|
2314
2459
|
function reorder(changes) {
|
|
2315
2460
|
for (let i = 0; i < changes.length; i++) {
|
|
@@ -2377,8 +2522,9 @@ function applyChanges(original, updated, changes) {
|
|
|
2377
2522
|
}
|
|
2378
2523
|
else {
|
|
2379
2524
|
parent = findParent(original, change.path);
|
|
2380
|
-
if (isKeyValue(parent))
|
|
2525
|
+
if (isKeyValue(parent)) {
|
|
2381
2526
|
parent = parent.value;
|
|
2527
|
+
}
|
|
2382
2528
|
}
|
|
2383
2529
|
if (isTableArray(parent) || isInlineArray(parent) || isDocument(parent)) {
|
|
2384
2530
|
insert(original, parent, child, index);
|
|
@@ -2440,9 +2586,25 @@ function applyChanges(original, updated, changes) {
|
|
|
2440
2586
|
return original;
|
|
2441
2587
|
}
|
|
2442
2588
|
|
|
2589
|
+
/**
|
|
2590
|
+
* Parses a TOML string into a JavaScript object.
|
|
2591
|
+
* The function converts TOML syntax to its JavaScript equivalent.
|
|
2592
|
+
* This proceeds in two steps: first, it parses the TOML string into an AST,
|
|
2593
|
+
* and then it converts the AST into a JavaScript object.
|
|
2594
|
+
*
|
|
2595
|
+
* @param value - The TOML string to parse
|
|
2596
|
+
* @returns The parsed JavaScript object
|
|
2597
|
+
*/
|
|
2443
2598
|
function parse(value) {
|
|
2444
2599
|
return toJS(parseTOML(value), value);
|
|
2445
2600
|
}
|
|
2601
|
+
/**
|
|
2602
|
+
* Converts a JavaScript object to a TOML string.
|
|
2603
|
+
*
|
|
2604
|
+
* @param value - The JavaScript object to stringify
|
|
2605
|
+
* @param format - Optional formatting options for the resulting TOML
|
|
2606
|
+
* @returns The stringified TOML representation
|
|
2607
|
+
*/
|
|
2446
2608
|
function stringify(value, format) {
|
|
2447
2609
|
const document = parseJS(value, format);
|
|
2448
2610
|
return toTOML(document.items);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v0.3.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TOML={})}(this,(function(e){"use strict";var t,n;function l(e){return e.type===t.Document}function o(e){return e.type===t.Table}function r(e){return e.type===t.TableArray}function a(e){return e.type===t.KeyValue}function i(e){return e.type===t.InlineArray}function c(e){return e.type===t.InlineItem}function u(e){return e.type===t.InlineTable}function s(e){return e.type===t.Comment}function f(e){return l(e)||o(e)||r(e)||u(e)||i(e)}function m(e){return function(e){return e.type===t.TableKey}(e)||function(e){return e.type===t.TableArrayKey}(e)||c(e)}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(t||(t={}));class d{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return y();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?y():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}function y(){return{value:void 0,done:!0}}function p(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function v(e,t){const n=Array.isArray(e)?e:h(e),l=n.findIndex((e=>e>=t))+1;return{line:l,column:t-(n[l-2]+1||0)}}function h(e){const t=/[\r\n|\n]/g,n=[];let l;for(;null!=(l=t.exec(e));)n.push(l.index);return n.push(e.length+1),n}function w(e){return{line:e.line,column:e.column}}function g(e){return{start:w(e.start),end:w(e.end)}}class b extends Error{constructor(e,t,n){let l=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=h(e),l=n[t.line-2]||0,o=n[t.line-1]||e.length;return e.substr(l,o-l)}(e,t),o=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(l+=`${n}\n${o}\n`)}l+=n,super(l),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(n||(n={}));const k=/\s/,x=/(\r\n|\n)/,T='"',I="'",A=/[\w,\d,\",\',\+,\-,\_]/;function*E(e){const t=new d(e[Symbol.iterator]());t.next();const l=function(e){const t=h(e);return(e,n)=>({start:v(t,e),end:v(t,n)})}(e);for(;!t.done;){if(k.test(t.value));else if("["===t.value||"]"===t.value)yield $(t,l,n.Bracket);else if("{"===t.value||"}"===t.value)yield $(t,l,n.Curly);else if("="===t.value)yield $(t,l,n.Equal);else if(","===t.value)yield $(t,l,n.Comma);else if("."===t.value)yield $(t,l,n.Dot);else if("#"===t.value)yield S(t,l);else{const n=O(e,t.index,I)||O(e,t.index,T);n?yield K(t,l,n,e):yield C(t,l,e)}t.next()}}function $(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function S(e,t){const l=e.index;let o=e.value;for(;!e.peek().done&&!x.test(e.peek().value);)e.next(),o+=e.value;return{type:n.Comment,raw:o,loc:t(l,e.index+1)}}function K(e,t,l,o){const r=e.index;let a=l+l+l,i=a;for(e.next(),e.next(),e.next();!e.done&&(!O(o,e.index,l)||D(o,e.index,l));)i+=e.value,e.next();if(e.done)throw new b(o,v(o,e.index),`Expected close of multiline string with ${a}, reached end of file`);return i+=a,e.next(),e.next(),{type:n.Literal,raw:i,loc:t(r,e.index+1)}}function C(e,t,l){if(!A.test(e.value))throw new b(l,v(l,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const o=e.index;let r=e.value,a=e.value===T,i=e.value===I;const c=e=>{if(e.peek().done)return!0;const t=e.peek().value;return!(a||i)&&(k.test(t)||","===t||"."===t||"]"===t||"}"===t||"="===t||"#"===t)};for(;!e.done&&!c(e)&&(e.next(),e.value===T&&(a=!a),e.value!==I||a||(i=!i),r+=e.value,!e.peek().done);){let t=e.peek().value;a&&"\\"===e.value&&(t===T?(r+=T,e.next()):"\\"===t&&(r+="\\",e.next()))}if(a||i)throw new b(l,v(l,o),`Expected close of string with ${a?T:I}`);return{type:n.Literal,raw:r,loc:t(o,e.index+1)}}function O(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;const l=e.slice(0,t).match(/\\+$/);if(!l)return n;return!(l[0].length%2!=0)&&n}function D(e,t,n){return!!n&&(e[t]===n&&e[t+1]===n&&e[t+2]===n&&e[t+3]===n)}function j(e){return e[e.length-1]}function B(){return Object.create(null)}function F(e){return"number"==typeof e&&e%1==0}function N(e){return"[object Date]"===Object.prototype.toString.call(e)}function _(e){return e&&"object"==typeof e&&!N(e)&&!Array.isArray(e)}function L(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function M(e,...t){return t.reduce(((e,t)=>t(e)),e)}function U(e){if(_(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${U(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(U).join(",")}]`:JSON.stringify(e)}function V(e,t){const n=e.length,l=t.length;e.length=n+l;for(let o=0;o<l;o++)e[n+o]=t[o]}const q=/\r\n/g,R=/\n/g,W=/^(\r\n|\n)/,J=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function z(e){return e.startsWith("'''")?M(G(e,3),Q):e.startsWith(I)?G(e,1):e.startsWith('"""')?M(G(e,3),Q,Y,X,P,H):e.startsWith(T)?M(G(e,1),H):e}function P(e){let t="",n=0;for(let l=0;l<e.length;l++){const o=e[l];t+='"'===o&&n%2==0?'\\"':o,"\\"===o?n++:n=0}return t}function H(e){const t=e.replace(/\\U[a-fA-F0-9]{8}/g,(e=>{const t=parseInt(e.replace("\\U",""),16),n=String.fromCodePoint(t);return G(JSON.stringify(n),1)})),n=t.replace(/\t/g,"\\t");return JSON.parse(`"${n}"`)}function G(e,t){return e.slice(t,e.length-t)}function Q(e){return e.replace(W,"")}function X(e){return e.replace(q,"\\r\\n").replace(R,"\\n")}function Y(e){return e.replace(J,((e,t)=>e.replace(t,"")))}const Z="true",ee=/e/i,te=/\_/g,ne=/inf/,le=/nan/,oe=/^0x/,re=/^0o/,ae=/^0b/,ie=/(\d{4})-(\d{2})-(\d{2})/,ce=/(\d{2}):(\d{2}):(\d{2})/;function*ue(e){const t=E(e),n=new d(t);for(;!n.next().done;)yield*se(n,e)}function*se(e,l){if(e.value.type===n.Comment)yield me(e);else if(e.value.type===n.Bracket)yield function(e,l){const o=e.peek().done||e.peek().value.type!==n.Bracket?t.Table:t.TableArray,r=o===t.Table;if(r&&"["!==e.value.raw)throw new b(l,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!r&&("["!==e.value.raw||"["!==e.peek().value.raw))throw new b(l,e.value.loc.start,`Expected array of tables opening "[[", found ${e.value.raw+e.peek().value.raw}`);const a=r?{type:t.TableKey,loc:e.value.loc}:{type:t.TableArrayKey,loc:e.value.loc};e.next(),o===t.TableArray&&e.next();if(e.done)throw new b(l,a.loc.start,"Expected table key, reached end of file");a.item={type:t.Key,loc:g(e.value.loc),raw:e.value.raw,value:[z(e.value.raw)]};for(;!e.peek().done&&e.peek().value.type===n.Dot;){e.next();const t=e.value;e.next();const n=" ".repeat(t.loc.start.column-a.item.loc.end.column),l=" ".repeat(e.value.loc.start.column-t.loc.end.column);a.item.loc.end=e.value.loc.end,a.item.raw+=`${n}.${l}${e.value.raw}`,a.item.value.push(z(e.value.raw))}if(e.next(),r&&(e.done||"]"!==e.value.raw))throw new b(l,e.done?a.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?"end of file":e.value.raw}`);if(!r&&(e.done||e.peek().done||"]"!==e.value.raw||"]"!==e.peek().value.raw))throw new b(l,e.done||e.peek().done?a.item.loc.end:e.value.loc.start,`Expected array of tables closing "]]", found ${e.done||e.peek().done?"end of file":e.value.raw+e.peek().value.raw}`);r||e.next();a.loc.end=e.value.loc.end;let i=[];for(;!e.peek().done&&e.peek().value.type!==n.Bracket;)e.next(),V(i,[...se(e,l)]);return{type:r?t.Table:t.TableArray,loc:{start:w(a.loc.start),end:i.length?w(i[i.length-1].loc.end):w(a.loc.end)},key:a,items:i}}(e,l);else{if(e.value.type!==n.Literal)throw new b(l,e.value.loc.start,`Unexpected token "${e.value.type}". Expected Comment, Bracket, or String`);yield*function(e,l){const o={type:t.Key,loc:g(e.value.loc),raw:e.value.raw,value:[z(e.value.raw)]};for(;!e.peek().done&&e.peek().value.type===n.Dot;)e.next(),e.next(),o.loc.end=e.value.loc.end,o.raw+=`.${e.value.raw}`,o.value.push(z(e.value.raw));if(e.next(),e.done||e.value.type!==n.Equal)throw new b(l,e.done?o.loc.end:e.value.loc.start,`Expected "=" for key-value, found ${e.done?"end of file":e.value.raw}`);const r=e.value.loc.start.column;if(e.next(),e.done)throw new b(l,o.loc.start,"Expected value for key-value, reached end of file");const[a,...i]=fe(e,l);return[{type:t.KeyValue,key:o,value:a,loc:{start:w(o.loc.start),end:w(a.loc.end)},equals:r},...i]}(e,l)}}function*fe(e,l){if(e.value.type===n.Literal)e.value.raw[0]===T||e.value.raw[0]===I?yield function(e){return{type:t.String,loc:e.value.loc,raw:e.value.raw,value:z(e.value.raw)}}(e):e.value.raw===Z||"false"===e.value.raw?yield function(e){return{type:t.Boolean,loc:e.value.loc,value:e.value.raw===Z}}(e):ie.test(e.value.raw)||ce.test(e.value.raw)?yield function(e,l){let o,r=e.value.loc,a=e.value.raw;if(!e.peek().done&&e.peek().value.type===n.Literal&&ie.test(a)&&ce.test(e.peek().value.raw)){const t=r.start;e.next(),r={start:t,end:e.value.loc.end},a+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===n.Dot){const t=r.start;if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new b(l,e.value.loc.end,"Expected fractional value for DateTime");e.next(),r={start:t,end:e.value.loc.end},a+=`.${e.value.raw}`}if(ie.test(a))o=new Date(a.replace(" ","T"));else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${a}`)}return{type:t.DateTime,loc:r,raw:a,value:o}}(e,l):!e.peek().done&&e.peek().value.type===n.Dot||ne.test(e.value.raw)||le.test(e.value.raw)||ee.test(e.value.raw)&&!oe.test(e.value.raw)?yield function(e,l){let o,r=e.value.loc,a=e.value.raw;if(ne.test(a))o="-inf"===a?-1/0:1/0;else if(le.test(a))o=NaN;else if(e.peek().done||e.peek().value.type!==n.Dot)o=Number(a.replace(te,""));else{const t=r.start;if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new b(l,e.value.loc.end,"Expected fraction value for Float");e.next(),a+=`.${e.value.raw}`,r={start:t,end:e.value.loc.end},o=Number(a.replace(te,""))}return{type:t.Float,loc:r,raw:a,value:o}}(e,l):yield function(e){if("-0"===e.value.raw||"+0"===e.value.raw)return{type:t.Integer,loc:e.value.loc,raw:e.value.raw,value:0};let n=10;oe.test(e.value.raw)?n=16:re.test(e.value.raw)?n=8:ae.test(e.value.raw)&&(n=2);const l=parseInt(e.value.raw.replace(te,"").replace(re,"").replace(ae,""),n);return{type:t.Integer,loc:e.value.loc,raw:e.value.raw,value:l}}(e);else if(e.value.type===n.Curly)yield function(e,l){if("{"!==e.value.raw)throw new b(l,e.value.loc.start,`Expected "{" for inline table, found ${e.value.raw}`);const o={type:t.InlineTable,loc:g(e.value.loc),items:[]};e.next();for(;!e.done&&(e.value.type!==n.Curly||"}"!==e.value.raw);){if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new b(l,e.value.loc.start,'Found "," without previous value in inline table');t.comma=!0,t.loc.end=e.value.loc.start,e.next();continue}const[r]=se(e,l);if(r.type!==t.KeyValue)throw new b(l,e.value.loc.start,`Only key-values are supported in inline tables, found ${r.type}`);const a={type:t.InlineItem,loc:g(r.loc),item:r,comma:!1};o.items.push(a),e.next()}if(e.done||e.value.type!==n.Curly||"}"!==e.value.raw)throw new b(l,e.done?o.loc.start:e.value.loc.start,`Expected "}", found ${e.done?"end of file":e.value.raw}`);return o.loc.end=e.value.loc.end,o}(e,l);else{if(e.value.type!==n.Bracket)throw new b(l,e.value.loc.start,`Unrecognized token type "${e.value.type}". Expected String, Curly, or Bracket`);{const[o,r]=function(e,l){if("["!==e.value.raw)throw new b(l,e.value.loc.start,`Expected "[" for inline array, found ${e.value.raw}`);const o={type:t.InlineArray,loc:g(e.value.loc),items:[]};let r=[];e.next();for(;!e.done&&(e.value.type!==n.Bracket||"]"!==e.value.raw);){if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new b(l,e.value.loc.start,'Found "," without previous value for inline array');t.comma=!0,t.loc.end=e.value.loc.start}else if(e.value.type===n.Comment)r.push(me(e));else{const[n,...a]=fe(e,l),i={type:t.InlineItem,loc:g(n.loc),item:n,comma:!1};o.items.push(i),V(r,a)}e.next()}if(e.done||e.value.type!==n.Bracket||"]"!==e.value.raw)throw new b(l,e.done?o.loc.start:e.value.loc.start,`Expected "]", found ${e.done?"end of file":e.value.raw}`);return o.loc.end=e.value.loc.end,[o,r]}(e,l);yield o,yield*r}}}function me(e){return{type:t.Comment,loc:e.value.loc,raw:e.value.raw}}function de(e,n){var l;function o(e,t){for(const n of e)r(n,t)}function r(e,l){const a=n[e.type];switch(a&&"function"==typeof a&&a(e,l),a&&a.enter&&a.enter(e,l),e.type){case t.Document:o(e.items,e);break;case t.Table:r(e.key,e),o(e.items,e);break;case t.TableKey:r(e.item,e);break;case t.TableArray:r(e.key,e),o(e.items,e);break;case t.TableArrayKey:r(e.item,e);break;case t.KeyValue:r(e.key,e),r(e.value,e);break;case t.InlineArray:o(e.items,e);break;case t.InlineItem:r(e.item,e);break;case t.InlineTable:o(e.items,e);break;case t.Key:case t.String:case t.Integer:case t.Float:case t.Boolean:case t.DateTime:case t.Comment:break;default:throw new Error(`Unrecognized node type "${e.type}"`)}a&&a.exit&&a.exit(e,l)}null!=(l=e)&&"function"==typeof l[Symbol.iterator]?o(e,null):r(e,null)}const ye=new WeakMap,pe=e=>(ye.has(e)||ye.set(e,new WeakMap),ye.get(e)),ve=new WeakMap,he=e=>(ve.has(e)||ve.set(e,new WeakMap),ve.get(e));function we(e,t,n,l){if(f(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,l)}else if(a(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,l)}else if(m(t))t.item=l;else{if(!a(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=l:t.value=l}Ie(l,{lines:n.loc.start.line-l.loc.start.line,columns:n.loc.start.column-l.loc.start.column});const o=p(n.loc),r=p(l.loc);Ae({lines:r.lines-o.lines,columns:r.columns-o.columns},he(e),l,n)}function ge(e,t,n,m){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let d,y;m=null!=m&&"number"==typeof m?m:t.items.length,i(t)||u(t)?({shift:d,offset:y}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const l=null!=n?e.items[n-1]:j(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const r=!!l,a=!o,u=o&&!0===t.comma;r&&(l.comma=!0);a&&(t.comma=!0);const f=i(e)&&function(e){if(!e.items.length)return!1;return p(e.loc).lines>e.items.length}(e),m=l?{line:l.loc.end.line,column:f?s(l)?e.loc.start.column:l.loc.start.column:l.loc.end.column}:w(e.loc.start);let d=0;if(f)d=1;else{const e=2,t=1;m.column+=r?e:t}m.line+=d;const y={lines:m.line-t.loc.start.line,columns:m.column-t.loc.start.column},v=p(t.loc),h={lines:v.lines+(d-1),columns:v.columns+(r||a?2:0)+(u?1:0)};return{shift:y,offset:h}}(t,n,m)):({shift:d,offset:y}=function(e,t,n){if(i=t,!(a(i)||o(i)||r(i)||s(i)))throw new Error(`Incompatible child type "${t.type}"`);var i;const c=e.items[n-1],u=l(e)&&!e.items.length;e.items.splice(n,0,t);const f=c?{line:c.loc.end.line,column:s(c)?e.loc.start.column:c.loc.start.column}:w(e.loc.start),m=o(t)||r(t);let d=0;u||(d=m?2:1);f.line+=d;const y={lines:f.line-t.loc.start.line,columns:f.column-t.loc.start.column},v=p(t.loc),h={lines:v.lines+(d-1),columns:v.columns};return{shift:y,offset:h}}(t,n,m)),Ie(n,d);const v=t.items[m-1],h=v&&he(e).get(v);h&&(y.lines+=h.lines,y.columns+=h.columns,he(e).delete(v));he(e).set(n,y)}function be(e,t,n){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let l=t.items.indexOf(n);if(l<0){if(l=t.items.findIndex((e=>m(e)&&e.item===n)),l<0)throw new Error("Could not find node in parent for removal");n=t.items[l]}const o=t.items[l-1];let r=t.items[l+1];t.items.splice(l,1);let a=p(n.loc);r&&s(r)&&r.loc.start.line===n.loc.end.line&&(a=p({start:n.loc.start,end:r.loc.end}),r=t.items[l+1],t.items.splice(l,1));const i=o&&c(o)||r&&c(r),u=o&&o.loc.end.line===n.loc.start.line,d=r&&r.loc.start.line===n.loc.end.line,y=i&&(u||d),v={lines:-(a.lines-(y?1:0)),columns:-a.columns};i&&u&&(v.columns-=2),i&&!o&&r&&(v.columns-=2),i&&o&&!r&&(o.comma=!1);const h=o||t,w=o?he(e):pe(e),g=he(e),b=w.get(h);b&&(v.lines+=b.lines,v.columns+=b.columns);const k=g.get(n);k&&(v.lines+=k.lines,v.columns+=k.columns),w.set(h,v)}function ke(e,t,n=!0){if(!n)return;if(!t.items.length)return;Ae({lines:0,columns:1},pe(e),t);const l=j(t.items);Ae({lines:0,columns:1},he(e),l)}function xe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const l=j(t.items);l.comma=!0,Ae({lines:0,columns:1},he(e),l)}function Te(e){const n=pe(e),l=he(e),o={lines:0,columns:{}};function r(e){const t=o.lines;e.loc.start.line+=t;const l=o.columns[e.loc.start.line]||0;e.loc.start.column+=l;const r=n.get(e);r&&(o.lines+=r.lines,o.columns[e.loc.start.line]=(o.columns[e.loc.start.line]||0)+r.columns)}function a(e){const t=o.lines;e.loc.end.line+=t;const n=o.columns[e.loc.end.line]||0;e.loc.end.column+=n;const r=l.get(e);r&&(o.lines+=r.lines,o.columns[e.loc.end.line]=(o.columns[e.loc.end.line]||0)+r.columns)}const i={enter:r,exit:a};de(e,{[t.Document]:i,[t.Table]:i,[t.TableArray]:i,[t.InlineTable]:i,[t.InlineArray]:i,[t.InlineItem]:i,[t.TableKey]:i,[t.TableArrayKey]:i,[t.KeyValue]:{enter(e){const t=e.loc.start.line+o.lines,n=l.get(e.key);e.equals+=(o.columns[t]||0)+(n?n.columns:0),r(e)},exit:a},[t.Key]:i,[t.String]:i,[t.Integer]:i,[t.Float]:i,[t.Boolean]:i,[t.DateTime]:i,[t.Comment]:i}),ye.delete(e),ve.delete(e)}function Ie(e,n,l={}){const{first_line_only:o=!1}=l,r=e.loc.start.line,{lines:a,columns:i}=n,c=e=>{o&&e.loc.start.line!==r||(e.loc.start.column+=i,e.loc.end.column+=i),e.loc.start.line+=a,e.loc.end.line+=a};return de(e,{[t.Table]:c,[t.TableKey]:c,[t.TableArray]:c,[t.TableArrayKey]:c,[t.KeyValue](e){c(e),e.equals+=i},[t.Key]:c,[t.String]:c,[t.Integer]:c,[t.Float]:c,[t.Boolean]:c,[t.DateTime]:c,[t.InlineArray]:c,[t.InlineItem]:c,[t.InlineTable]:c,[t.Comment]:c}),e}function Ae(e,t,n,l){const o=t.get(l||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function Ee(){return{type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function $e(e){const n=function(e){const n=Oe(e);return{type:t.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:t.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:e,raw:n}}}(e);return{type:t.Table,loc:g(n.loc),key:n,items:[]}}function Se(e){const n=function(e){const n=Oe(e);return{type:t.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:t.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:e,raw:n}}}(e);return{type:t.TableArray,loc:g(n.loc),key:n,items:[]}}function Ke(e,n){const l=function(e){const n=Oe(e);return{type:t.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e),{column:o}=l.loc.end,r=o+1;return Ie(n,{lines:0,columns:o+3-n.loc.start.column},{first_line_only:!0}),{type:t.KeyValue,loc:{start:w(l.loc.start),end:w(n.loc.end)},key:l,equals:r,value:n}}const Ce=/[\w,\d,\_,\-]+/;function Oe(e){return e.map((e=>Ce.test(e)?e:JSON.stringify(e))).join(".")}function De(e){return{type:t.InlineItem,loc:g(e.loc),item:e,comma:!1}}function je(e){return e.items.filter((e=>{if(!a(e))return!1;const t=u(e.value),n=i(e.value)&&e.value.items.length&&u(e.value.items[0].item);return t||n})).forEach((t=>{be(e,e,t),u(t.value)?ge(e,e,function(e){const t=$e(e.key.value);for(const n of e.value.items)ge(t,t,n.item);return Te(t),t}(t)):function(e){const t=Ee();for(const n of e.value.items){const l=Se(e.key.value);ge(t,t,l);for(const e of n.item.items)ge(t,l,e.item)}return Te(t),t.items}(t).forEach((t=>{ge(e,e,t)}))})),Te(e),e}function Be(e){let t=0,n=0;for(const l of e.items)0===n&&l.loc.start.line>1?t=1-l.loc.start.line:l.loc.start.line+t>n+2&&(t+=n+2-(l.loc.start.line+t)),Ie(l,{lines:t,columns:0}),n=l.loc.end.line;return e}const Fe={printWidth:80,trailingComma:!1,bracketSpacing:!0};function Ne(e,t={}){t=Object.assign({},Fe,t),e=function(e){let t={};for(const n in e)_(e[n])||Array.isArray(e[n])||(t[n]=e[n]);for(const n in e)(_(e[n])||Array.isArray(e[n]))&&(t[n]=e[n]);return t}(e=Me(e));const n=Ee();for(const l of _e(e,t))ge(n,n,l);Te(n);const l=M(n,je,(e=>function(e){return e}(e)),Be);return l}function*_e(e,t){for(const n of Object.keys(e))yield Ke([n],Le(e[n],t))}function Le(e,n){if(null==e)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(e)?function(e){const n=JSON.stringify(e);return{type:t.String,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):F(e)?function(e){const n=e.toString();return{type:t.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"number"==typeof e&&!F(e)}(e)?function(e){const n=e.toString();return{type:t.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"boolean"==typeof e}(e)?function(e){return{type:t.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:e?4:5}},value:e}}(e):N(e)?function(e){const n=e.toISOString();return{type:t.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):Array.isArray(e)?function(e,n){const l={type:t.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const t of e){ge(l,l,De(Le(t,n)))}return ke(l,l,n.bracketSpacing),xe(l,l,n.trailingComma),Te(l),l}(e,n):function(e,n){if(e=Me(e),!_(e))return Le(e,n);const l={type:t.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[..._e(e,n)];for(const e of o){ge(l,l,De(e))}return ke(l,l,n.bracketSpacing),xe(l,l,n.trailingComma),Te(l),l}(e,n)}function Me(e){return e?N(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const Ue=/(\r\n|\n)/g;function Ve(e,n="\n"){const l=[];return de(e,{[t.TableKey](e){const{start:t,end:n}=e.loc;qe(l,{start:t,end:{line:t.line,column:t.column+1}},"["),qe(l,{start:{line:n.line,column:n.column-1},end:n},"]")},[t.TableArrayKey](e){const{start:t,end:n}=e.loc;qe(l,{start:t,end:{line:t.line,column:t.column+2}},"[["),qe(l,{start:{line:n.line,column:n.column-2},end:n},"]]")},[t.KeyValue](e){const{start:{line:t}}=e.loc;qe(l,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=")},[t.Key](e){qe(l,e.loc,e.raw)},[t.String](e){qe(l,e.loc,e.raw)},[t.Integer](e){qe(l,e.loc,e.raw)},[t.Float](e){qe(l,e.loc,e.raw)},[t.Boolean](e){qe(l,e.loc,e.value.toString())},[t.DateTime](e){qe(l,e.loc,e.raw)},[t.InlineArray](e){const{start:t,end:n}=e.loc;qe(l,{start:t,end:{line:t.line,column:t.column+1}},"["),qe(l,{start:{line:n.line,column:n.column-1},end:n},"]")},[t.InlineTable](e){const{start:t,end:n}=e.loc;qe(l,{start:t,end:{line:t.line,column:t.column+1}},"{"),qe(l,{start:{line:n.line,column:n.column-1},end:n},"}")},[t.InlineItem](e){if(!e.comma)return;const t=e.loc.end;qe(l,{start:t,end:{line:t.line,column:t.column+1}},",")},[t.Comment](e){qe(l,e.loc,e.raw)}}),l.join(n)+n}function qe(e,t,n){const l=n.split(Ue).filter((e=>"\n"!==e&&"\r\n"!==e)),o=t.end.line-t.start.line+1;if(l.length!==o)throw new Error(`Mismatch between location and raw string, expected ${o} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){const o=Re(e,n),r=n===t.start.line,a=n===t.end.line,i=r?o.substr(0,t.start.column).padEnd(t.start.column," "):"",c=a?o.substr(t.end.column):"";e[n-1]=i+l[n-t.start.line]+c}}function Re(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function We(e,n=""){const l=B(),o=new Set,r=new Set,a=new Set;let i,c=l,s=!1;return de(e,{[t.Table](e){const t=e.key.item.value;try{ze(l,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const i=Ge(t);o.add(i),a.add(i),c=Pe(l,t)},[t.TableArray](e){const t=e.key.item.value;try{ze(l,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const i=Ge(t);r.add(i),a.add(i),c=function(e,t){const n=He(e,t.slice(0,-1)),l=j(t);n[l]||(n[l]=[]);const o=B();return n[j(t)].push(o),o}(l,t)},[t.KeyValue]:{enter(e){if(s)return;const t=e.key.value;try{ze(c,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const l=Je(e.value);(t.length>1?Pe(c,t.slice(0,-1)):c)[j(t)]=l,a.add(Ge(t)),u(e.value)&&(i=c,c=l)},exit(e){u(e.value)&&(c=i)}},[t.InlineTable]:{enter(){s=!0},exit(){s=!1}}}),l}function Je(e){switch(e.type){case t.InlineTable:const n=B();return e.items.forEach((({item:e})=>{const t=e.key.value,l=Je(e.value);(t.length>1?Pe(n,t.slice(0,-1)):n)[j(t)]=l})),n;case t.InlineArray:return e.items.map((e=>Je(e.item)));case t.String:case t.Integer:case t.Float:case t.Boolean:case t.DateTime:return e.value;default:throw new Error(`Unrecognized value type "${e.type}"`)}}function ze(e,n,l,o){let r=[],a=0;for(const t of n){if(r.push(t),!L(e,t))return;if("object"!=typeof(i=e[t])&&!N(i))throw new Error(`Invalid key, a value has already been defined for ${r.join(".")}`);const l=Ge(r);if(Array.isArray(e[t])&&!o.table_arrays.has(l))throw new Error(`Invalid key, cannot add to a static array at ${l}`);const c=a++<n.length-1;e=Array.isArray(e[t])&&c?j(e[t]):e[t]}var i;const c=Ge(n);if(e&&l===t.Table&&o.defined.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(e&&l===t.TableArray&&!o.table_arrays.has(c))throw new Error(`Invalid key, cannot add an array of tables to a table at ${c}`)}function Pe(e,t){const n=He(e,t.slice(0,-1)),l=j(t);return n[l]||(n[l]=B()),n[l]}function He(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=B()),Array.isArray(e[t])?j(e[t]):e[t])),e)}function Ge(e){return e.join(".")}var Qe;function Xe(e){return e.type===Qe.Remove}function Ye(e,t,n=[]){return e===t||(o=t,N(l=e)&&N(o)&&l.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let l=[];const o=e.map(U),r=t.map(U);r.forEach(((a,i)=>{const c=i>=o.length;if(!c&&o[i]===a)return;const u=o.indexOf(a,i+1);if(!c&&u>-1){l.push({type:Qe.Move,path:n,from:u,to:i});const e=o.splice(u,1);return void o.splice(i,0,...e)}const s=!r.includes(o[i]);if(!c&&s)return V(l,Ye(e[i],t[i],n.concat(i))),void(o[i]=a);l.push({type:Qe.Add,path:n.concat(i)}),o.splice(i,0,a)}));for(let e=r.length;e<o.length;e++)l.push({type:Qe.Remove,path:n.concat(e)});return l}(e,t,n):_(e)&&_(t)?function(e,t,n=[]){let l=[];const o=Object.keys(e),r=o.map((t=>U(e[t]))),a=Object.keys(t),i=a.map((e=>U(t[e]))),c=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[r.indexOf(e)];return!a.includes(n)};return o.forEach(((o,u)=>{const s=n.concat(o);if(a.includes(o))V(l,Ye(e[o],t[o],s));else if(c(r[u],i)){const e=a[i.indexOf(r[u])];l.push({type:Qe.Rename,path:n,from:o,to:e})}else l.push({type:Qe.Remove,path:s})})),a.forEach(((e,t)=>{o.includes(e)||c(i[t],r)||l.push({type:Qe.Add,path:n.concat(e)})})),l}(e,t,n):[{type:Qe.Edit,path:n}];var l,o}function Ze(e,t){if(!t.length)return e;if(a(e))return Ze(e.value,t);const n={};let l;if(f(e)&&e.items.some(((e,i)=>{try{let u=[];if(a(e))u=e.key.value;else if(o(e))u=e.key.item.value;else if(r(e)){u=e.key.item.value;const t=U(u);n[t]||(n[t]=0);const l=n[t]++;u=u.concat(l)}else c(e)&&a(e.item)?u=e.item.key.value:c(e)&&(u=[i]);return!(!u.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(u,t.slice(0,u.length)))&&(l=Ze(e,t.slice(u.length)),!0)}catch(e){return!1}})),!l)throw new Error(`Could not find node at path ${t.join(".")}`);return l}function et(e,t){try{return Ze(e,t)}catch(e){}}function tt(e,t){let n,l=t;for(;l.length&&!n;)l=l.slice(0,-1),n=et(e,l);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(Qe||(Qe={})),e.parse=function(e){return We(ue(e),e)},e.patch=function(e,n,u){const s=[...ue(e)],f=We(s);return Ve(function(e,t,n){return n.forEach((n=>{if(function(e){return e.type===Qe.Add}(n)){const c=Ze(t,n.path),u=n.path.slice(0,-1);let s,f=j(n.path),m=r(c);if(F(f)&&!u.some(F)){const t=et(e,u.concat(0));t&&r(t)&&(m=!0)}if(o(c))s=e;else if(m){s=e;const t=e,n=et(t,u.concat(f-1)),l=et(t,u.concat(f));f=l?t.items.indexOf(l):n?t.items.indexOf(n)+1:t.items.length}else s=tt(e,n.path),a(s)&&(s=s.value);r(s)||i(s)||l(s)?ge(e,s,c,f):ge(e,s,c)}else if(function(e){return e.type===Qe.Edit}(n)){let l,o=Ze(e,n.path),r=Ze(t,n.path);a(o)&&a(r)?(l=o,o=o.value,r=r.value):a(o)&&c(r)&&a(r.item)?(l=o,o=o.value,r=r.item.value):l=tt(e,n.path),we(e,l,o,r)}else if(Xe(n)){let t=tt(e,n.path);a(t)&&(t=t.value);const l=Ze(e,n.path);be(e,t,l)}else if(function(e){return e.type===Qe.Move}(n)){let t=Ze(e,n.path);m(t)&&(t=t.item),a(t)&&(t=t.value);const l=t.items[n.from];be(e,t,l),ge(e,t,l,n.to)}else if(function(e){return e.type===Qe.Rename}(n)){let l=Ze(e,n.path.concat(n.from)),o=Ze(t,n.path.concat(n.to));m(l)&&(l=l.item),m(o)&&(o=o.item),we(e,l,l.key,o.key)}})),Te(e),e}({type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:s},Ne(n,u),function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Xe(n)){let l=t+1;for(;l<e.length;){const o=e[l];if(Xe(o)&&o.path[0]===n.path[0]&&o.path[1]>n.path[1]){e.splice(l,1),e.splice(t,0,o),t=0;break}l++}}}return e}(Ye(f,n))).items)},e.stringify=function(e,t){return Ve(Ne(e,t).items)}}));
|
|
1
|
+
//! @decimalturn/toml-patch v0.3.8 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TOML={})}(this,(function(e){"use strict";var t,n;function l(e){return e.type===t.Document}function o(e){return e.type===t.Table}function r(e){return e.type===t.TableArray}function a(e){return e.type===t.KeyValue}function i(e){return e.type===t.InlineArray}function c(e){return e.type===t.InlineItem}function u(e){return e.type===t.InlineTable}function s(e){return e.type===t.Comment}function f(e){return l(e)||o(e)||r(e)||u(e)||i(e)}function m(e){return function(e){return e.type===t.TableKey}(e)||function(e){return e.type===t.TableArrayKey}(e)||c(e)}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(t||(t={}));class d{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return p();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?p():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}function p(){return{value:void 0,done:!0}}function y(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function v(e,t){const n=Array.isArray(e)?e:h(e),l=n.findIndex((e=>e>=t))+1;return{line:l,column:t-(n[l-2]+1||0)}}function h(e){const t=/\r\n|\n/g,n=[];let l;for(;null!=(l=t.exec(e));)n.push(l.index+l[0].length-1);return n.push(e.length+1),n}function w(e){return{line:e.line,column:e.column}}function g(e){return{start:w(e.start),end:w(e.end)}}class b extends Error{constructor(e,t,n){let l=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=h(e),l=n[t.line-2]||0,o=n[t.line-1]||e.length;return e.substr(l,o-l)}(e,t),o=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(l+=`${n}\n${o}\n`)}l+=n,super(l),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(n||(n={}));const k=/\s/,x=/(\r\n|\n)/,T='"',I="'",A=/[\w,\d,\",\',\+,\-,\_]/;function*$(e){const t=new d(e[Symbol.iterator]());t.next();const l=function(e){const t=h(e);return(e,n)=>({start:v(t,e),end:v(t,n)})}(e);for(;!t.done;){if(k.test(t.value));else if("["===t.value||"]"===t.value)yield E(t,l,n.Bracket);else if("{"===t.value||"}"===t.value)yield E(t,l,n.Curly);else if("="===t.value)yield E(t,l,n.Equal);else if(","===t.value)yield E(t,l,n.Comma);else if("."===t.value)yield E(t,l,n.Dot);else if("#"===t.value)yield S(t,l);else{const n=C(e,t.index,I)||C(e,t.index,T);n?yield K(t,l,n,e):yield O(t,l,e)}t.next()}}function E(e,t,n){return{type:n,raw:e.value,loc:t(e.index,e.index+1)}}function S(e,t){const l=e.index;let o=e.value;for(;!e.peek().done&&!x.test(e.peek().value);)e.next(),o+=e.value;return{type:n.Comment,raw:o,loc:t(l,e.index+1)}}function K(e,t,l,o){const r=e.index;let a=l+l+l,i=a;for(e.next(),e.next(),e.next();!e.done&&(!C(o,e.index,l)||D(o,e.index,l));)i+=e.value,e.next();if(e.done)throw new b(o,v(o,e.index),`Expected close of multiline string with ${a}, reached end of file`);return i+=a,e.next(),e.next(),{type:n.Literal,raw:i,loc:t(r,e.index+1)}}function O(e,t,l){if(!A.test(e.value))throw new b(l,v(l,e.index),`Unsupported character "${e.value}". Expected ALPHANUMERIC, ", ', +, -, or _`);const o=e.index;let r=e.value,a=e.value===T,i=e.value===I;const c=e=>{if(e.peek().done)return!0;const t=e.peek().value;return!(a||i)&&(k.test(t)||","===t||"."===t||"]"===t||"}"===t||"="===t||"#"===t)};for(;!e.done&&!c(e)&&(e.next(),e.value===T&&(a=!a),e.value!==I||a||(i=!i),r+=e.value,!e.peek().done);){let t=e.peek().value;a&&"\\"===e.value&&(t===T?(r+=T,e.next()):"\\"===t&&(r+="\\",e.next()))}if(a||i)throw new b(l,v(l,o),`Expected close of string with ${a?T:I}`);return{type:n.Literal,raw:r,loc:t(o,e.index+1)}}function C(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;const l=e.slice(0,t).match(/\\+$/);if(!l)return n;return!(l[0].length%2!=0)&&n}function D(e,t,n){return!!n&&(e[t]===n&&e[t+1]===n&&e[t+2]===n&&e[t+3]===n)}function j(e){return e[e.length-1]}function B(){return Object.create(null)}function N(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function F(e){return"[object Date]"===Object.prototype.toString.call(e)}function L(e){return e&&"object"==typeof e&&!F(e)&&!Array.isArray(e)}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function _(e,...t){return t.reduce(((e,t)=>t(e)),e)}function U(e){if(L(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${U(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(U).join(",")}]`:JSON.stringify(e)}function V(e,t){const n=e.length,l=t.length;e.length=n+l;for(let o=0;o<l;o++)e[n+o]=t[o]}const q=/\r\n/g,R=/\n/g,W=/^(\r\n|\n)/,J=/(?<!\\)(?:\\\\)*(\\\s*[\n\r\n]\s*)/g;function z(e){return e.startsWith("'''")?_(G(e,3),Q):e.startsWith(I)?G(e,1):e.startsWith('"""')?_(G(e,3),Q,Y,X,P,H):e.startsWith(T)?_(G(e,1),H):e}function P(e){let t="",n=0;for(let l=0;l<e.length;l++){const o=e[l];t+='"'===o&&n%2==0?'\\"':o,"\\"===o?n++:n=0}return t}function H(e){const t=e.replace(/\\U[a-fA-F0-9]{8}/g,(e=>{const t=parseInt(e.replace("\\U",""),16),n=String.fromCodePoint(t);return G(JSON.stringify(n),1)})),n=t.replace(/\t/g,"\\t");return JSON.parse(`"${n}"`)}function G(e,t){return e.slice(t,e.length-t)}function Q(e){return e.replace(W,"")}function X(e){return e.replace(q,"\\r\\n").replace(R,"\\n")}function Y(e){return e.replace(J,((e,t)=>e.replace(t,"")))}const Z="true",ee=/e/i,te=/\_/g,ne=/inf/,le=/nan/,oe=/^0x/,re=/^0o/,ae=/^0b/,ie=/(\d{4})-(\d{2})-(\d{2})/,ce=/(\d{2}):(\d{2}):(\d{2})/;function*ue(e){const t=$(e),n=new d(t);for(;!n.next().done;)yield*se(n,e)}function*se(e,l){if(e.value.type===n.Comment)yield me(e);else if(e.value.type===n.Bracket)yield function(e,l){const o=e.peek().done||e.peek().value.type!==n.Bracket?t.Table:t.TableArray,r=o===t.Table;if(r&&"["!==e.value.raw)throw new b(l,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!r&&("["!==e.value.raw||"["!==e.peek().value.raw))throw new b(l,e.value.loc.start,`Expected array of tables opening "[[", found ${e.value.raw+e.peek().value.raw}`);const a=r?{type:t.TableKey,loc:e.value.loc}:{type:t.TableArrayKey,loc:e.value.loc};e.next(),o===t.TableArray&&e.next();if(e.done)throw new b(l,a.loc.start,"Expected table key, reached end of file");a.item={type:t.Key,loc:g(e.value.loc),raw:e.value.raw,value:[z(e.value.raw)]};for(;!e.peek().done&&e.peek().value.type===n.Dot;){e.next();const t=e.value;e.next();const n=" ".repeat(t.loc.start.column-a.item.loc.end.column),l=" ".repeat(e.value.loc.start.column-t.loc.end.column);a.item.loc.end=e.value.loc.end,a.item.raw+=`${n}.${l}${e.value.raw}`,a.item.value.push(z(e.value.raw))}if(e.next(),r&&(e.done||"]"!==e.value.raw))throw new b(l,e.done?a.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?"end of file":e.value.raw}`);if(!r&&(e.done||e.peek().done||"]"!==e.value.raw||"]"!==e.peek().value.raw))throw new b(l,e.done||e.peek().done?a.item.loc.end:e.value.loc.start,`Expected array of tables closing "]]", found ${e.done||e.peek().done?"end of file":e.value.raw+e.peek().value.raw}`);r||e.next();a.loc.end=e.value.loc.end;let i=[];for(;!e.peek().done&&e.peek().value.type!==n.Bracket;)e.next(),V(i,[...se(e,l)]);return{type:r?t.Table:t.TableArray,loc:{start:w(a.loc.start),end:i.length?w(i[i.length-1].loc.end):w(a.loc.end)},key:a,items:i}}(e,l);else{if(e.value.type!==n.Literal)throw new b(l,e.value.loc.start,`Unexpected token "${e.value.type}". Expected Comment, Bracket, or String`);yield*function(e,l){const o={type:t.Key,loc:g(e.value.loc),raw:e.value.raw,value:[z(e.value.raw)]};for(;!e.peek().done&&e.peek().value.type===n.Dot;)e.next(),e.next(),o.loc.end=e.value.loc.end,o.raw+=`.${e.value.raw}`,o.value.push(z(e.value.raw));if(e.next(),e.done||e.value.type!==n.Equal)throw new b(l,e.done?o.loc.end:e.value.loc.start,`Expected "=" for key-value, found ${e.done?"end of file":e.value.raw}`);const r=e.value.loc.start.column;if(e.next(),e.done)throw new b(l,o.loc.start,"Expected value for key-value, reached end of file");const[a,...i]=fe(e,l);return[{type:t.KeyValue,key:o,value:a,loc:{start:w(o.loc.start),end:w(a.loc.end)},equals:r},...i]}(e,l)}}function*fe(e,l){if(e.value.type===n.Literal)e.value.raw[0]===T||e.value.raw[0]===I?yield function(e){return{type:t.String,loc:e.value.loc,raw:e.value.raw,value:z(e.value.raw)}}(e):e.value.raw===Z||"false"===e.value.raw?yield function(e){return{type:t.Boolean,loc:e.value.loc,value:e.value.raw===Z}}(e):ie.test(e.value.raw)||ce.test(e.value.raw)?yield function(e,l){let o,r=e.value.loc,a=e.value.raw;if(!e.peek().done&&e.peek().value.type===n.Literal&&ie.test(a)&&ce.test(e.peek().value.raw)){const t=r.start;e.next(),r={start:t,end:e.value.loc.end},a+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===n.Dot){const t=r.start;if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new b(l,e.value.loc.end,"Expected fractional value for DateTime");e.next(),r={start:t,end:e.value.loc.end},a+=`.${e.value.raw}`}if(ie.test(a))o=new Date(a.replace(" ","T"));else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${a}`)}return{type:t.DateTime,loc:r,raw:a,value:o}}(e,l):!e.peek().done&&e.peek().value.type===n.Dot||ne.test(e.value.raw)||le.test(e.value.raw)||ee.test(e.value.raw)&&!oe.test(e.value.raw)?yield function(e,l){let o,r=e.value.loc,a=e.value.raw;if(ne.test(a))o="-inf"===a?-1/0:1/0;else if(le.test(a))o=NaN;else if(e.peek().done||e.peek().value.type!==n.Dot)o=Number(a.replace(te,""));else{const t=r.start;if(e.next(),e.peek().done||e.peek().value.type!==n.Literal)throw new b(l,e.value.loc.end,"Expected fraction value for Float");e.next(),a+=`.${e.value.raw}`,r={start:t,end:e.value.loc.end},o=Number(a.replace(te,""))}return{type:t.Float,loc:r,raw:a,value:o}}(e,l):yield function(e){if("-0"===e.value.raw||"+0"===e.value.raw)return{type:t.Integer,loc:e.value.loc,raw:e.value.raw,value:0};let n=10;oe.test(e.value.raw)?n=16:re.test(e.value.raw)?n=8:ae.test(e.value.raw)&&(n=2);const l=parseInt(e.value.raw.replace(te,"").replace(re,"").replace(ae,""),n);return{type:t.Integer,loc:e.value.loc,raw:e.value.raw,value:l}}(e);else if(e.value.type===n.Curly)yield function(e,l){if("{"!==e.value.raw)throw new b(l,e.value.loc.start,`Expected "{" for inline table, found ${e.value.raw}`);const o={type:t.InlineTable,loc:g(e.value.loc),items:[]};e.next();for(;!e.done&&(e.value.type!==n.Curly||"}"!==e.value.raw);){if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new b(l,e.value.loc.start,'Found "," without previous value in inline table');t.comma=!0,t.loc.end=e.value.loc.start,e.next();continue}const[r]=se(e,l);if(r.type!==t.KeyValue)throw new b(l,e.value.loc.start,`Only key-values are supported in inline tables, found ${r.type}`);const a={type:t.InlineItem,loc:g(r.loc),item:r,comma:!1};o.items.push(a),e.next()}if(e.done||e.value.type!==n.Curly||"}"!==e.value.raw)throw new b(l,e.done?o.loc.start:e.value.loc.start,`Expected "}", found ${e.done?"end of file":e.value.raw}`);return o.loc.end=e.value.loc.end,o}(e,l);else{if(e.value.type!==n.Bracket)throw new b(l,e.value.loc.start,`Unrecognized token type "${e.value.type}". Expected String, Curly, or Bracket`);{const[o,r]=function(e,l){if("["!==e.value.raw)throw new b(l,e.value.loc.start,`Expected "[" for inline array, found ${e.value.raw}`);const o={type:t.InlineArray,loc:g(e.value.loc),items:[]};let r=[];e.next();for(;!e.done&&(e.value.type!==n.Bracket||"]"!==e.value.raw);){if(e.value.type===n.Comma){const t=o.items[o.items.length-1];if(!t)throw new b(l,e.value.loc.start,'Found "," without previous value for inline array');t.comma=!0,t.loc.end=e.value.loc.start}else if(e.value.type===n.Comment)r.push(me(e));else{const[n,...a]=fe(e,l),i={type:t.InlineItem,loc:g(n.loc),item:n,comma:!1};o.items.push(i),V(r,a)}e.next()}if(e.done||e.value.type!==n.Bracket||"]"!==e.value.raw)throw new b(l,e.done?o.loc.start:e.value.loc.start,`Expected "]", found ${e.done?"end of file":e.value.raw}`);return o.loc.end=e.value.loc.end,[o,r]}(e,l);yield o,yield*r}}}function me(e){return{type:t.Comment,loc:e.value.loc,raw:e.value.raw}}function de(e,n){var l;function o(e,t){for(const n of e)r(n,t)}function r(e,l){const a=n[e.type];switch(a&&"function"==typeof a&&a(e,l),a&&a.enter&&a.enter(e,l),e.type){case t.Document:o(e.items,e);break;case t.Table:r(e.key,e),o(e.items,e);break;case t.TableKey:r(e.item,e);break;case t.TableArray:r(e.key,e),o(e.items,e);break;case t.TableArrayKey:r(e.item,e);break;case t.KeyValue:r(e.key,e),r(e.value,e);break;case t.InlineArray:o(e.items,e);break;case t.InlineItem:r(e.item,e);break;case t.InlineTable:o(e.items,e);break;case t.Key:case t.String:case t.Integer:case t.Float:case t.Boolean:case t.DateTime:case t.Comment:break;default:throw new Error(`Unrecognized node type "${e.type}"`)}a&&a.exit&&a.exit(e,l)}null!=(l=e)&&"function"==typeof l[Symbol.iterator]?o(e,null):r(e,null)}const pe=new WeakMap,ye=e=>(pe.has(e)||pe.set(e,new WeakMap),pe.get(e)),ve=new WeakMap,he=e=>(ve.has(e)||ve.set(e,new WeakMap),ve.get(e));function we(e,t,n,l){if(f(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,l)}else if(a(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,l)}else if(m(t))t.item=l;else{if(!a(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=l:t.value=l}Ie(l,{lines:n.loc.start.line-l.loc.start.line,columns:n.loc.start.column-l.loc.start.column});const o=y(n.loc),r=y(l.loc);Ae({lines:r.lines-o.lines,columns:r.columns-o.columns},he(e),l,n)}function ge(e,t,n,m){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let d,p;m=null!=m&&"number"==typeof m?m:t.items.length,i(t)||u(t)?({shift:d,offset:p}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const l=null!=n?e.items[n-1]:j(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const r=!!l,a=!o,u=o&&!0===t.comma;r&&(l.comma=!0);a&&(t.comma=!0);const f=i(e)&&function(e){if(!e.items.length)return!1;return y(e.loc).lines>e.items.length}(e),m=l?{line:l.loc.end.line,column:f?s(l)?e.loc.start.column:l.loc.start.column:l.loc.end.column}:w(e.loc.start);let d=0;if(f)d=1;else{const e=2,t=1;m.column+=r?e:t}m.line+=d;const p={lines:m.line-t.loc.start.line,columns:m.column-t.loc.start.column},v=y(t.loc),h={lines:v.lines+(d-1),columns:v.columns+(r||a?2:0)+(u?1:0)};return{shift:p,offset:h}}(t,n,m)):({shift:d,offset:p}=function(e,t,n){if(i=t,!(a(i)||o(i)||r(i)||s(i)))throw new Error(`Incompatible child type "${t.type}"`);var i;const c=e.items[n-1],u=l(e)&&!e.items.length;e.items.splice(n,0,t);const f=c?{line:c.loc.end.line,column:s(c)?e.loc.start.column:c.loc.start.column}:w(e.loc.start),m=o(t)||r(t);let d=0;u||(d=m?2:1);f.line+=d;const p={lines:f.line-t.loc.start.line,columns:f.column-t.loc.start.column},v=y(t.loc),h={lines:v.lines+(d-1),columns:v.columns};return{shift:p,offset:h}}(t,n,m)),Ie(n,d);const v=t.items[m-1],h=v&&he(e).get(v);h&&(p.lines+=h.lines,p.columns+=h.columns,he(e).delete(v));he(e).set(n,p)}function be(e,t,n){if(!f(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let l=t.items.indexOf(n);if(l<0){if(l=t.items.findIndex((e=>m(e)&&e.item===n)),l<0)throw new Error("Could not find node in parent for removal");n=t.items[l]}const o=t.items[l-1];let r=t.items[l+1];t.items.splice(l,1);let a=y(n.loc);r&&s(r)&&r.loc.start.line===n.loc.end.line&&(a=y({start:n.loc.start,end:r.loc.end}),r=t.items[l+1],t.items.splice(l,1));const i=o&&c(o)||r&&c(r),u=o&&o.loc.end.line===n.loc.start.line,d=r&&r.loc.start.line===n.loc.end.line,p=i&&(u||d),v={lines:-(a.lines-(p?1:0)),columns:-a.columns};void 0===o&&void 0===r&&(v.lines=0,v.columns=0),i&&u&&(v.columns-=2),i&&!o&&r&&(v.columns-=2),i&&o&&!r&&(o.comma=!1);const h=o||t,w=o?he(e):ye(e),g=he(e),b=w.get(h);b&&(v.lines+=b.lines,v.columns+=b.columns);const k=g.get(n);k&&(v.lines+=k.lines,v.columns+=k.columns),w.set(h,v)}function ke(e,t,n=!0){if(!n)return;if(!t.items.length)return;Ae({lines:0,columns:1},ye(e),t);const l=j(t.items);Ae({lines:0,columns:1},he(e),l)}function xe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const l=j(t.items);l.comma=!0,Ae({lines:0,columns:1},he(e),l)}function Te(e){const n=ye(e),l=he(e),o={lines:0,columns:{}};function r(e){const t=o.lines;e.loc.start.line+=t;const l=o.columns[e.loc.start.line]||0;e.loc.start.column+=l;const r=n.get(e);r&&(o.lines+=r.lines,o.columns[e.loc.start.line]=(o.columns[e.loc.start.line]||0)+r.columns)}function a(e){const t=o.lines;e.loc.end.line+=t;const n=o.columns[e.loc.end.line]||0;e.loc.end.column+=n;const r=l.get(e);r&&(o.lines+=r.lines,o.columns[e.loc.end.line]=(o.columns[e.loc.end.line]||0)+r.columns)}const i={enter:r,exit:a};de(e,{[t.Document]:i,[t.Table]:i,[t.TableArray]:i,[t.InlineTable]:i,[t.InlineArray]:i,[t.InlineItem]:i,[t.TableKey]:i,[t.TableArrayKey]:i,[t.KeyValue]:{enter(e){const t=e.loc.start.line+o.lines,n=l.get(e.key);e.equals+=(o.columns[t]||0)+(n?n.columns:0),r(e)},exit:a},[t.Key]:i,[t.String]:i,[t.Integer]:i,[t.Float]:i,[t.Boolean]:i,[t.DateTime]:i,[t.Comment]:i}),pe.delete(e),ve.delete(e)}function Ie(e,n,l={}){const{first_line_only:o=!1}=l,r=e.loc.start.line,{lines:a,columns:i}=n,c=e=>{o&&e.loc.start.line!==r||(e.loc.start.column+=i,e.loc.end.column+=i),e.loc.start.line+=a,e.loc.end.line+=a};return de(e,{[t.Table]:c,[t.TableKey]:c,[t.TableArray]:c,[t.TableArrayKey]:c,[t.KeyValue](e){c(e),e.equals+=i},[t.Key]:c,[t.String]:c,[t.Integer]:c,[t.Float]:c,[t.Boolean]:c,[t.DateTime]:c,[t.InlineArray]:c,[t.InlineItem]:c,[t.InlineTable]:c,[t.Comment]:c}),e}function Ae(e,t,n,l){const o=t.get(l||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function $e(){return{type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Ee(e){const n=function(e){const n=Ce(e);return{type:t.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:t.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:e,raw:n}}}(e);return{type:t.Table,loc:g(n.loc),key:n,items:[]}}function Se(e){const n=function(e){const n=Ce(e);return{type:t.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:t.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:e,raw:n}}}(e);return{type:t.TableArray,loc:g(n.loc),key:n,items:[]}}function Ke(e,n){const l=function(e){const n=Ce(e);return{type:t.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e),{column:o}=l.loc.end,r=o+1;return Ie(n,{lines:0,columns:o+3-n.loc.start.column},{first_line_only:!0}),{type:t.KeyValue,loc:{start:w(l.loc.start),end:w(n.loc.end)},key:l,equals:r,value:n}}const Oe=/^[\w-]+$/;function Ce(e){return e.map((e=>Oe.test(e)?e:JSON.stringify(e))).join(".")}function De(e){return{type:t.InlineItem,loc:g(e.loc),item:e,comma:!1}}function je(e){return e.items.filter((e=>{if(!a(e))return!1;const t=u(e.value),n=i(e.value)&&e.value.items.length&&u(e.value.items[0].item);return t||n})).forEach((t=>{be(e,e,t),u(t.value)?ge(e,e,function(e){const t=Ee(e.key.value);for(const n of e.value.items)ge(t,t,n.item);return Te(t),t}(t)):function(e){const t=$e();for(const n of e.value.items){const l=Se(e.key.value);ge(t,t,l);for(const e of n.item.items)ge(t,l,e.item)}return Te(t),t.items}(t).forEach((t=>{ge(e,e,t)}))})),Te(e),e}function Be(e){let t=0,n=0;for(const l of e.items)0===n&&l.loc.start.line>1?t=1-l.loc.start.line:l.loc.start.line+t>n+2&&(t+=n+2-(l.loc.start.line+t)),Ie(l,{lines:t,columns:0}),n=l.loc.end.line;return e}const Ne={printWidth:80,trailingComma:!1,bracketSpacing:!0};function Fe(e,t={}){t=Object.assign({},Ne,t),e=function(e){const t=[],n=[];for(const l in e)L(e[l])||Array.isArray(e[l])?n.push(l):t.push(l);const l={};for(let n=0;n<t.length;n++){const o=t[n];l[o]=e[o]}for(let t=0;t<n.length;t++){const o=n[t];l[o]=e[o]}return l}(e=_e(e));const n=$e();for(const l of Le(e,t))ge(n,n,l);Te(n);const l=_(n,je,(e=>function(e){return e}(e)),Be);return l}function*Le(e,t){for(const n of Object.keys(e))yield Ke([n],Me(e[n],t))}function Me(e,n){if(null==e)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(e)?function(e){const n=JSON.stringify(e);return{type:t.String,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):N(e)?function(e){const n=e.toString();return{type:t.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"number"==typeof e&&(!N(e)||!isFinite(e)||Object.is(e,-0))}(e)?function(e){let n;return n=e===1/0?"inf":e===-1/0?"-inf":Number.isNaN(e)?"nan":Object.is(e,-0)?"-0.0":e.toString(),{type:t.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):function(e){return"boolean"==typeof e}(e)?function(e){return{type:t.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:e?4:5}},value:e}}(e):F(e)?function(e){const n=e.toISOString();return{type:t.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:e}}(e):Array.isArray(e)?function(e,n){const l={type:t.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const t of e){ge(l,l,De(Me(t,n)))}return ke(l,l,n.bracketSpacing),xe(l,l,n.trailingComma),Te(l),l}(e,n):function(e,n){if(e=_e(e),!L(e))return Me(e,n);const l={type:t.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[...Le(e,n)];for(const e of o){ge(l,l,De(e))}return ke(l,l,n.bracketSpacing),xe(l,l,n.trailingComma),Te(l),l}(e,n)}function _e(e){return e?F(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const Ue=/(\r\n|\n)/g;function Ve(e,n="\n",l){var o;const r=null!==(o=null==l?void 0:l.trailingNewline)&&void 0!==o?o:1,a=[];return de(e,{[t.TableKey](e){const{start:t,end:n}=e.loc;qe(a,{start:t,end:{line:t.line,column:t.column+1}},"["),qe(a,{start:{line:n.line,column:n.column-1},end:n},"]")},[t.TableArrayKey](e){const{start:t,end:n}=e.loc;qe(a,{start:t,end:{line:t.line,column:t.column+2}},"[["),qe(a,{start:{line:n.line,column:n.column-2},end:n},"]]")},[t.KeyValue](e){const{start:{line:t}}=e.loc;qe(a,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=")},[t.Key](e){qe(a,e.loc,e.raw)},[t.String](e){qe(a,e.loc,e.raw)},[t.Integer](e){qe(a,e.loc,e.raw)},[t.Float](e){qe(a,e.loc,e.raw)},[t.Boolean](e){qe(a,e.loc,e.value.toString())},[t.DateTime](e){qe(a,e.loc,e.raw)},[t.InlineArray](e){const{start:t,end:n}=e.loc;qe(a,{start:t,end:{line:t.line,column:t.column+1}},"["),qe(a,{start:{line:n.line,column:n.column-1},end:n},"]")},[t.InlineTable](e){const{start:t,end:n}=e.loc;qe(a,{start:t,end:{line:t.line,column:t.column+1}},"{"),qe(a,{start:{line:n.line,column:n.column-1},end:n},"}")},[t.InlineItem](e){if(!e.comma)return;const t=e.loc.end;qe(a,{start:t,end:{line:t.line,column:t.column+1}},",")},[t.Comment](e){qe(a,e.loc,e.raw)}}),a.join(n)+n.repeat(r)}function qe(e,t,n){const l=n.split(Ue).filter((e=>"\n"!==e&&"\r\n"!==e)),o=t.end.line-t.start.line+1;if(l.length!==o)throw new Error(`Mismatch between location and raw string, expected ${o} lines for "${n}"`);for(let o=t.start.line;o<=t.end.line;o++){const r=Re(e,o);if(void 0===r)throw new Error(`Line ${o} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const a=o===t.start.line,i=o===t.end.line,c=a?r.substr(0,t.start.column).padEnd(t.start.column," "):"",u=i?r.substr(t.end.column):"";e[o-1]=c+l[o-t.start.line]+u}}function Re(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function We(e,n=""){const l=B(),o=new Set,r=new Set,a=new Set;let i=l,c=0;return de(e,{[t.Table](e){const t=e.key.item.value;try{ze(l,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const c=Ge(t);o.add(c),a.add(c),i=Pe(l,t)},[t.TableArray](e){const t=e.key.item.value;try{ze(l,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const c=Ge(t);r.add(c),a.add(c),i=function(e,t){const n=He(e,t.slice(0,-1)),l=j(t);n[l]||(n[l]=[]);const o=B();return n[j(t)].push(o),o}(l,t)},[t.KeyValue]:{enter(e){if(c>0)return;const t=e.key.value;try{ze(i,t,e.type,{tables:o,table_arrays:r,defined:a})}catch(t){const l=t;throw new b(n,e.key.loc.start,l.message)}const l=Je(e.value);(t.length>1?Pe(i,t.slice(0,-1)):i)[j(t)]=l,a.add(Ge(t))}},[t.InlineTable]:{enter(){c++},exit(){c--}}}),l}function Je(e){switch(e.type){case t.InlineTable:const n=B();return e.items.forEach((({item:e})=>{const t=e.key.value,l=Je(e.value);(t.length>1?Pe(n,t.slice(0,-1)):n)[j(t)]=l})),n;case t.InlineArray:return e.items.map((e=>Je(e.item)));case t.String:case t.Integer:case t.Float:case t.Boolean:case t.DateTime:return e.value;default:throw new Error(`Unrecognized value type "${e.type}"`)}}function ze(e,n,l,o){let r=[],a=0;for(const t of n){if(r.push(t),!M(e,t))return;if("object"!=typeof(i=e[t])&&!F(i))throw new Error(`Invalid key, a value has already been defined for ${r.join(".")}`);const l=Ge(r);if(Array.isArray(e[t])&&!o.table_arrays.has(l))throw new Error(`Invalid key, cannot add to a static array at ${l}`);const c=a++<n.length-1;e=Array.isArray(e[t])&&c?j(e[t]):e[t]}var i;const c=Ge(n);if(e&&l===t.Table&&o.defined.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(e&&l===t.TableArray&&!o.table_arrays.has(c))throw new Error(`Invalid key, cannot add an array of tables to a table at ${c}`)}function Pe(e,t){const n=He(e,t.slice(0,-1)),l=j(t);return n[l]||(n[l]=B()),n[l]}function He(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=B()),Array.isArray(e[t])?j(e[t]):e[t])),e)}function Ge(e){return e.join(".")}var Qe;function Xe(e){return e.type===Qe.Remove}function Ye(e,t,n=[]){return e===t||(o=t,F(l=e)&&F(o)&&l.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let l=[];const o=e.map(U),r=t.map(U);r.forEach(((a,i)=>{const c=i>=o.length;if(!c&&o[i]===a)return;const u=o.indexOf(a,i+1);if(!c&&u>-1){l.push({type:Qe.Move,path:n,from:u,to:i});const e=o.splice(u,1);return void o.splice(i,0,...e)}const s=!r.includes(o[i]);if(!c&&s)return V(l,Ye(e[i],t[i],n.concat(i))),void(o[i]=a);l.push({type:Qe.Add,path:n.concat(i)}),o.splice(i,0,a)}));for(let e=r.length;e<o.length;e++)l.push({type:Qe.Remove,path:n.concat(e)});return l}(e,t,n):L(e)&&L(t)?function(e,t,n=[]){let l=[];const o=Object.keys(e),r=o.map((t=>U(e[t]))),a=Object.keys(t),i=a.map((e=>U(t[e]))),c=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[r.indexOf(e)];return!a.includes(n)};return o.forEach(((o,u)=>{const s=n.concat(o);if(a.includes(o))V(l,Ye(e[o],t[o],s));else if(c(r[u],i)){const e=a[i.indexOf(r[u])];l.push({type:Qe.Rename,path:n,from:o,to:e})}else l.push({type:Qe.Remove,path:s})})),a.forEach(((e,t)=>{o.includes(e)||c(i[t],r)||l.push({type:Qe.Add,path:n.concat(e)})})),l}(e,t,n):[{type:Qe.Edit,path:n}];var l,o}function Ze(e,t){if(!t.length)return e;if(a(e))return Ze(e.value,t);const n={};let l;if(f(e)&&e.items.some(((e,i)=>{try{let u=[];if(a(e))u=e.key.value;else if(o(e))u=e.key.item.value;else if(r(e)){u=e.key.item.value;const t=U(u);n[t]||(n[t]=0);const l=n[t]++;u=u.concat(l)}else c(e)&&a(e.item)?u=e.item.key.value:c(e)&&(u=[i]);return!(!u.length||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(u,t.slice(0,u.length)))&&(l=Ze(e,t.slice(u.length)),!0)}catch(e){return!1}})),!l)throw new Error(`Could not find node at path ${t.join(".")}`);return l}function et(e,t){try{return Ze(e,t)}catch(e){}}function tt(e,t){let n,l=t;for(;l.length&&!n;)l=l.slice(0,-1),n=et(e,l);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(Qe||(Qe={})),e.parse=function(e){return We(ue(e),e)},e.patch=function(e,n,u){const s=[...ue(e)],f=We(s),d=function(e,t,n){return n.forEach((n=>{if(function(e){return e.type===Qe.Add}(n)){const c=Ze(t,n.path),u=n.path.slice(0,-1);let s,f=j(n.path),m=r(c);if(N(f)&&!u.some(N)){const t=et(e,u.concat(0));t&&r(t)&&(m=!0)}if(o(c))s=e;else if(m){s=e;const t=e,n=et(t,u.concat(f-1)),l=et(t,u.concat(f));f=l?t.items.indexOf(l):n?t.items.indexOf(n)+1:t.items.length}else s=tt(e,n.path),a(s)&&(s=s.value);r(s)||i(s)||l(s)?ge(e,s,c,f):ge(e,s,c)}else if(function(e){return e.type===Qe.Edit}(n)){let l,o=Ze(e,n.path),r=Ze(t,n.path);a(o)&&a(r)?(l=o,o=o.value,r=r.value):a(o)&&c(r)&&a(r.item)?(l=o,o=o.value,r=r.item.value):l=tt(e,n.path),we(e,l,o,r)}else if(Xe(n)){let t=tt(e,n.path);a(t)&&(t=t.value);const l=Ze(e,n.path);be(e,t,l)}else if(function(e){return e.type===Qe.Move}(n)){let t=Ze(e,n.path);m(t)&&(t=t.item),a(t)&&(t=t.value);const l=t.items[n.from];be(e,t,l),ge(e,t,l,n.to)}else if(function(e){return e.type===Qe.Rename}(n)){let l=Ze(e,n.path.concat(n.from)),o=Ze(t,n.path.concat(n.to));m(l)&&(l=l.item),m(o)&&(o=o.item),we(e,l,l.key,o.key)}})),Te(e),e}({type:t.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:s},Fe(n,u),function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Xe(n)){let l=t+1;for(;l<e.length;){const o=e[l];if(Xe(o)&&o.path[0]===n.path[0]&&o.path[1]>n.path[1]){e.splice(l,1),e.splice(t,0,o),t=0;break}l++}}}return e}(Ye(f,n)));let p="\n";const y=e.indexOf("\n");y>0&&"\r"===e.substring(y-1,y)&&(p="\r\n");const v=function(e,t){let n=0,l=e.length;for(;l>=t.length&&e.substring(l-t.length,l)===t;)n++,l-=t.length;return n}(e,p);return Ve(d.items,p,{trailingNewline:v})},e.stringify=function(e,t){return Ve(Fe(e,t).items)}}));
|
|
3
3
|
//# sourceMappingURL=toml-patch.umd.min.js.map
|