@decimalturn/toml-patch 0.3.2 → 0.3.7
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/README.md +10 -1
- 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 +28 -1
- package/dist/toml-patch.es.js +36 -2
- package/dist/toml-patch.umd.min.js +2 -2
- package/dist/toml-patch.umd.min.js.map +1 -1
- package/package.json +10 -10
package/dist/toml-patch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! @decimalturn/toml-patch v0.3.
|
|
1
|
+
//! @decimalturn/toml-patch v0.3.7 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
2
|
interface Format {
|
|
3
3
|
printWidth?: number;
|
|
4
4
|
tabWidth?: number;
|
|
@@ -7,9 +7,36 @@ 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
|
+
*
|
|
29
|
+
* @param value - The TOML string to parse
|
|
30
|
+
* @returns The parsed JavaScript object
|
|
31
|
+
*/
|
|
12
32
|
declare function parse(value: string): any;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a JavaScript object to a TOML string.
|
|
35
|
+
*
|
|
36
|
+
* @param value - The JavaScript object to stringify
|
|
37
|
+
* @param format - Optional formatting options for the resulting TOML
|
|
38
|
+
* @returns The stringified TOML representation
|
|
39
|
+
*/
|
|
13
40
|
declare function stringify(value: any, format?: Format): string;
|
|
14
41
|
|
|
15
42
|
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.7 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
2
|
var NodeType;
|
|
3
3
|
(function (NodeType) {
|
|
4
4
|
NodeType["Document"] = "Document";
|
|
@@ -1096,7 +1096,7 @@ function replace(root, parent, existing, replacement) {
|
|
|
1096
1096
|
parent.items.splice(index, 1, replacement);
|
|
1097
1097
|
// This next case is a special case for Inline-Table item
|
|
1098
1098
|
// however due to the fact that both replacement of the whole Inline-Table and Inline-Table element will have the same parent,
|
|
1099
|
-
// we need to make sure
|
|
1099
|
+
// we need to make sure it's not an Inline-Table
|
|
1100
1100
|
}
|
|
1101
1101
|
else if (isKeyValue(parent) && isInlineTable(parent.value) && !isInlineTable(existing)) {
|
|
1102
1102
|
const index = parent.value.items.indexOf(existing);
|
|
@@ -2295,6 +2295,19 @@ function findParent(node, path) {
|
|
|
2295
2295
|
return parent;
|
|
2296
2296
|
}
|
|
2297
2297
|
|
|
2298
|
+
/**
|
|
2299
|
+
* Applies modifications to a TOML document by comparing an existing TOML string with updated JavaScript data.
|
|
2300
|
+
*
|
|
2301
|
+
* This function preserves formatting and comments from the existing TOML document while
|
|
2302
|
+
* applying changes from the updated data structure. It performs a diff between the existing
|
|
2303
|
+
* and updated data, then strategically applies only the necessary changes to maintain the
|
|
2304
|
+
* original document structure as much as possible.
|
|
2305
|
+
*
|
|
2306
|
+
* @param existing - The original TOML document as a string
|
|
2307
|
+
* @param updated - The updated JavaScript object with desired changes
|
|
2308
|
+
* @param format - Optional formatting options to apply to new or modified sections
|
|
2309
|
+
* @returns A new TOML string with the changes applied
|
|
2310
|
+
*/
|
|
2298
2311
|
function patch(existing, updated, format) {
|
|
2299
2312
|
const existing_ast = parseTOML(existing);
|
|
2300
2313
|
const items = [...existing_ast];
|
|
@@ -2397,6 +2410,13 @@ function applyChanges(original, updated, changes) {
|
|
|
2397
2410
|
existing = existing.value;
|
|
2398
2411
|
replacement = replacement.value;
|
|
2399
2412
|
}
|
|
2413
|
+
else if (isKeyValue(existing) && isInlineItem(replacement) && isKeyValue(replacement.item)) {
|
|
2414
|
+
// Sometimes, the replacement looks like it could be an inline item, but the original is a key-value
|
|
2415
|
+
// In this case, we convert the replacement to a key-value to match the original
|
|
2416
|
+
parent = existing;
|
|
2417
|
+
existing = existing.value;
|
|
2418
|
+
replacement = replacement.item.value;
|
|
2419
|
+
}
|
|
2400
2420
|
else {
|
|
2401
2421
|
parent = findParent(original, change.path);
|
|
2402
2422
|
}
|
|
@@ -2433,9 +2453,23 @@ function applyChanges(original, updated, changes) {
|
|
|
2433
2453
|
return original;
|
|
2434
2454
|
}
|
|
2435
2455
|
|
|
2456
|
+
/**
|
|
2457
|
+
* Parses a TOML string into a JavaScript object.
|
|
2458
|
+
* The function converts TOML syntax to its JavaScript equivalent.
|
|
2459
|
+
*
|
|
2460
|
+
* @param value - The TOML string to parse
|
|
2461
|
+
* @returns The parsed JavaScript object
|
|
2462
|
+
*/
|
|
2436
2463
|
function parse(value) {
|
|
2437
2464
|
return toJS(parseTOML(value), value);
|
|
2438
2465
|
}
|
|
2466
|
+
/**
|
|
2467
|
+
* Converts a JavaScript object to a TOML string.
|
|
2468
|
+
*
|
|
2469
|
+
* @param value - The JavaScript object to stringify
|
|
2470
|
+
* @param format - Optional formatting options for the resulting TOML
|
|
2471
|
+
* @returns The stringified TOML representation
|
|
2472
|
+
*/
|
|
2439
2473
|
function stringify(value, format) {
|
|
2440
2474
|
const document = parseJS(value, format);
|
|
2441
2475
|
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,c){const u=[...ue(e)],s=We(u);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):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:u},Ne(n,c),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(s,n))).items)},e.stringify=function(e,t){return Ve(Ne(e,t).items)}}));
|
|
1
|
+
//! @decimalturn/toml-patch v0.3.7 - 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 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)}}));
|
|
3
3
|
//# sourceMappingURL=toml-patch.umd.min.js.map
|