@decimalturn/toml-patch 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,11 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.0] - 2026-04-15
11
+
12
+ ### Added
13
+ - Patching: Preserve preferred escape sequence representation in basic strings ([#131])
14
+ - Parsing: Add support for raw UTF-8 bytes (`Uint8Array`/`Buffer`) as input for `parse()` and `TomlDocument` ([#153]).
15
+ - Parsing: Add parsing options for `integersAsBigInt` modes (`'asNeeded'`, `true`, `false`) with `'asNeeded'` as default ([#153]).
16
+ - Formatting: Add `minimumDecimals` option to `TomlFormat` to control float decimal padding during serialization ([#153]).
17
+ - Parsing: Add support for rejection of invalid UTF-8 encoding as specified in `toml-test` ([#153]).
18
+
19
+ ### Fixed
20
+ - Patching: Editing a multiline basic string that uses a line ending backslash now preserves the original line-break structure and indentation. When the new value cannot be faithfully represented with a line ending backslash (e.g., values with leading or trailing whitespace), the format falls back to a regular multiline basic string to preserve content integrity ([#131]).
21
+ - Parsing: Preserve full integer precision by returning `BigInt` for values outside the JS safe integer range. Fallback to `Number` when integer cannot be parsed as a `BigInt` ([#153] & [#158]).
22
+ - Patching: Fixed mixed line endings bugs ([#131]).
23
+ - Date formatting: Ensure UTC year output is zero-padded to 4 digits for RFC3339 compliance ([#153]).
24
+ - Encoding: Fix encoding issue with DEL control character ([#153] & [#131]).
25
+
26
+ ## [1.0.7] - 2026-04-08
27
+
28
+ ### Fixed
29
+ - Stringifying: `undefined` values in objects are now silently ignored, matching `JSON.stringify` behavior ([#148]).
30
+ - Patching: Setting a key to `undefined` now correctly removes it, including in nested tables and inline tables ([#148]).
31
+ - Patching: Deleting a key from an inline table nested inside an inline array (e.g. `items = [{ name = "x", color = "y" }]`) now works correctly ([#148]).
32
+
10
33
  ## [1.0.6] - 2026-04-06
11
34
 
12
35
  ### Fixed
13
- - Patching: Support patching multiline inline tables.
14
- - Respect `inlineTableStart` inside Table Arrays (ie. Array of Tables)
36
+ - Patching: Support patching multiline inline tables ([#127]).
37
+ - Styling: Respect `inlineTableStart` inside Table Arrays (ie. Array of Tables) ([#144]).
15
38
 
16
39
  ## [1.0.5] - 2026-03-17
17
40
 
@@ -19,32 +42,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
42
  - Patching: Adding keys to nested inline tables (e.g. `config = { server = { host = "localhost" } }`) now works correctly
20
43
 
21
44
  ### Changed
22
- - Remove circular dependency between `toml-format` and `generate` modules ([#118](https://github.com/DecimalTurn/toml-patch/pull/118))
23
- - Reduce bundle size by deduplicating internal parsing and date-formatting helpers, implementing schema-based validation and shortening error messages ([#122](https://github.com/DecimalTurn/toml-patch/pull/122))
24
- - Improve internal representation handling for faster write performance (~3–4% speedup in benchmarks) by fixing inconsistencies in how positions are tracked internally ([#125](https://github.com/DecimalTurn/toml-patch/pull/125))
45
+ - Remove circular dependency between `toml-format` and `generate` modules ([#118])
46
+ - Reduce bundle size by deduplicating internal parsing and date-formatting helpers, implementing schema-based validation and shortening error messages ([#122])
47
+ - Improve internal representation handling for faster write performance (~3–4% speedup in benchmarks) by fixing inconsistencies in how positions are tracked internally ([#125])
25
48
 
26
49
  ## [1.0.2] - 2026-02-14
27
50
 
28
51
  ### Changed
29
- - Improve stringification performance ([#106](https://github.com/DecimalTurn/toml-patch/pull/106))
52
+ - Improve stringification performance ([#106])
30
53
 
31
54
  ## [1.0.1] - 2026-02-14
32
55
 
33
56
  ### Changed
34
- - Improve parsing and conversion performance ([#105](https://github.com/DecimalTurn/toml-patch/pull/105))
35
- - Better benchmarking ([#104](https://github.com/DecimalTurn/toml-patch/pull/104))
57
+ - Improve parsing and conversion performance ([#105])
58
+ - Better benchmarking ([#104])
36
59
  - Migrate benchmarks from CommonJS to ESM modules
37
60
  - Improve benchmark output with colored tables and formatted results
38
61
  - Support benchmarking multiple package versions with automatic caching (`--versions`)
39
62
  - Add CLI filters for benchmarks (`--package`, `--file`, `--example`)
40
63
 
41
64
  ### Added
42
- - Profiling support via `npm run profile` ([#105](https://github.com/DecimalTurn/toml-patch/pull/105))
65
+ - Profiling support via `npm run profile` ([#105])
43
66
 
44
67
  ## [1.0.0] - 2026-02-12
45
68
 
46
69
  ### Changed
47
- - **BREAKING**: Migrate to ESM-only distribution, removing CommonJS and UMD builds ([#100](https://github.com/DecimalTurn/toml-patch/pull/100))
70
+ - **BREAKING**: Migrate to ESM-only distribution, removing CommonJS and UMD builds ([#100])
48
71
  - Package.json now declares `"type": "module"` and uses a modern `exports` field
49
72
  - Single ESM build: `dist/toml-patch.js`
50
73
  - Removed: `dist/toml-patch.cjs.min.js`, `dist/toml-patch.umd.min.js`, and all source maps
@@ -56,7 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
56
79
  ## [0.7.0] - 2026-02-08
57
80
 
58
81
  ### Fixed
59
- - Per official [toml-test](https://github.com/toml-lang/toml-test), return error for invalid TOML inputs (keys, strings, inline tables, tables, date/time, control characters, and newline handling) except for encoding issues ([#94](https://github.com/DecimalTurn/toml-patch/pull/95)).
82
+ - Per official [toml-test](https://github.com/toml-lang/toml-test), return error for invalid TOML inputs (keys, strings, inline tables, tables, date/time, control characters, and newline handling) except for encoding issues ([#94]).
60
83
 
61
84
  ## [0.6.0] - 2026-02-01
62
85
 
@@ -66,7 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
89
  ## [0.5.2] - 2026-01-19
67
90
 
68
91
  ### Fixed
69
- - Remove circular reference warning ([#90](https://github.com/DecimalTurn/toml-patch/pull/90))
92
+ - Remove circular reference warning ([#90])
70
93
 
71
94
  ## [0.5.1] - 2026-01-18
72
95
 
@@ -74,13 +97,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
74
97
  - Add CHANGELOG.md
75
98
 
76
99
  ### Fixed
77
- - Fix multiline string handling when patching ([#87](https://github.com/DecimalTurn/toml-patch/pull/87))
100
+ - Fix multiline string handling when patching ([#87])
78
101
  - Fix LocalTime timezone parsing issue (2dea07ffd8377ad2aa30678e7025dcbe6753a8e9)
79
102
 
80
103
  ## [0.5.0] - 2025-12-26
81
104
 
82
105
  ### Added
83
- - Add `truncateZeroTimeInDates` formatting option for date serialization ([#86](https://github.com/DecimalTurn/toml-patch/pull/86))
106
+ - Add `truncateZeroTimeInDates` formatting option for date serialization ([#86])
84
107
 
85
108
  ### Changed
86
109
  - Update dependency dedent to v1.7.1
@@ -88,10 +111,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
111
  ## [0.4.1] - 2025-12-25
89
112
 
90
113
  ### Added
91
- - Introduce `TomlDocument` class ([#66](https://github.com/DecimalTurn/toml-patch/pull/66))
92
- - Add `TomlFormat` class ([#77](https://github.com/DecimalTurn/toml-patch/pull/77))
93
- - Better Inline vs Multiline Tables formatting ([#79](https://github.com/DecimalTurn/toml-patch/pull/79))
94
- - Handle TOML date formats when patching ([#82](https://github.com/DecimalTurn/toml-patch/pull/82))
114
+ - Introduce `TomlDocument` class ([#66])
115
+ - Add `TomlFormat` class ([#77])
116
+ - Better Inline vs Multiline Tables formatting ([#79])
117
+ - Handle TOML date formats when patching ([#82])
95
118
 
96
119
  ### Fixed
97
120
  - Dates will now preserve their formatting when patched
@@ -111,7 +134,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
111
134
  ## [0.3.8] - 2025-10-25
112
135
 
113
136
  ### Fixed
114
- - Add roundtrip tests and fix related issues ([#64](https://github.com/DecimalTurn/toml-patch/pull/64))
137
+ - Add roundtrip tests and fix related issues ([#64])
115
138
  - Ensure trailing end-of-line (EOL) preservation at the end-of-file (ie. if the original TOML doesn't have any EOL at EOF, don't add one and if there's more than one include them)
116
139
  - Fix issues with float values (`Infinity`, `-Infinity`, `NaN`, `-0`)
117
140
  - Fix the regular expression for bare TOML keys ensuring correct quoted keys interpretation (`"tater.man"` != `tater.man`)
@@ -120,7 +143,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
120
143
  - Fix regex for newline matching
121
144
 
122
145
  ### Security
123
- - Add Socket Free Firewall ([#53](https://github.com/DecimalTurn/toml-patch/pull/53))
146
+ - Add Socket Free Firewall ([#53])
124
147
 
125
148
  ### Changed
126
149
  - Updated submodules/toml-test digest to 1d35870
@@ -136,7 +159,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
136
159
  - Updated socketdev/action to v1.2.0
137
160
 
138
161
  ### Other
139
- - Expand benchmarks ([#61](https://github.com/DecimalTurn/toml-patch/pull/61))
162
+ - Expand benchmarks ([#61])
140
163
 
141
164
  ## [0.3.7] - 2025-08-20
142
165
 
@@ -149,18 +172,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
149
172
  ## [0.3.3] - 2025-05-10
150
173
 
151
174
  ### Fixed
152
- - Handle key-value vs inline-item mixup ([#4](https://github.com/DecimalTurn/toml-patch/pull/4))
175
+ - Handle key-value vs inline-item mixup ([#4])
153
176
 
154
177
  ## [0.3.2] - 2025-04-13
155
178
 
156
179
  ### Fixed
157
- - Fix replacement from Inline-Table to String Value ([#3](https://github.com/DecimalTurn/toml-patch/pull/3))
180
+ - Fix replacement from Inline-Table to String Value ([#3])
158
181
 
159
182
  ## [0.3.1] - 2025-04-12
160
183
 
161
184
  ### Fixed
162
- - Fix inline-table element deletion ([#1](https://github.com/DecimalTurn/toml-patch/pull/1))
163
- - Fix inline-table edition ([#2](https://github.com/DecimalTurn/toml-patch/pull/2))
185
+ - Fix inline-table element deletion ([#1])
186
+ - Fix inline-table edition ([#2])
164
187
 
165
188
  ## [0.3.0] - 2025-04-12
166
189
 
@@ -177,3 +200,33 @@ This first forked version from [timhall/toml-patch](https://github.com/timhall/t
177
200
  ### Changed
178
201
  - Updates dependencies
179
202
  - Ensures all latest spec tests from https://github.com/iarna/toml-spec-tests are passing (1880b1a)
203
+
204
+
205
+ [#1]: https://github.com/DecimalTurn/toml-patch/pull/1
206
+ [#2]: https://github.com/DecimalTurn/toml-patch/pull/2
207
+ [#3]: https://github.com/DecimalTurn/toml-patch/pull/3
208
+ [#4]: https://github.com/DecimalTurn/toml-patch/pull/4
209
+ [#53]: https://github.com/DecimalTurn/toml-patch/pull/53
210
+ [#61]: https://github.com/DecimalTurn/toml-patch/pull/61
211
+ [#64]: https://github.com/DecimalTurn/toml-patch/pull/64
212
+ [#66]: https://github.com/DecimalTurn/toml-patch/pull/66
213
+ [#77]: https://github.com/DecimalTurn/toml-patch/pull/77
214
+ [#79]: https://github.com/DecimalTurn/toml-patch/pull/79
215
+ [#82]: https://github.com/DecimalTurn/toml-patch/pull/82
216
+ [#86]: https://github.com/DecimalTurn/toml-patch/pull/86
217
+ [#87]: https://github.com/DecimalTurn/toml-patch/pull/87
218
+ [#90]: https://github.com/DecimalTurn/toml-patch/pull/90
219
+ [#94]: https://github.com/DecimalTurn/toml-patch/pull/94
220
+ [#100]: https://github.com/DecimalTurn/toml-patch/pull/100
221
+ [#104]: https://github.com/DecimalTurn/toml-patch/pull/104
222
+ [#105]: https://github.com/DecimalTurn/toml-patch/pull/105
223
+ [#106]: https://github.com/DecimalTurn/toml-patch/pull/106
224
+ [#118]: https://github.com/DecimalTurn/toml-patch/pull/118
225
+ [#122]: https://github.com/DecimalTurn/toml-patch/pull/122
226
+ [#125]: https://github.com/DecimalTurn/toml-patch/pull/125
227
+ [#127]: https://github.com/DecimalTurn/toml-patch/pull/127
228
+ [#131]: https://github.com/DecimalTurn/toml-patch/pull/131
229
+ [#144]: https://github.com/DecimalTurn/toml-patch/pull/144
230
+ [#148]: https://github.com/DecimalTurn/toml-patch/pull/148
231
+ [#153]: https://github.com/DecimalTurn/toml-patch/pull/153
232
+ [#158]: https://github.com/DecimalTurn/toml-patch/pull/158
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Patch, parse, and stringify [TOML](https://toml.io/en/) (v1.1.0) while preserving comments and formatting.
8
8
 
9
- This project started as a fork of the [original toml-patch](https://github.com/timhall/toml-patch) but has since evolved into a standalone project with significant improvements in reliability and features. We've added TOML v1.1 support, introduced new APIs like `TomlDocument` and `TomlFormat` classes, fixed numerous bugs through comprehensive testing with toml-test, and continue to actively maintain and improve the package.
9
+ This project started as a fork of the [original toml-patch](https://github.com/timhall/toml-patch) but has since evolved into a standalone project with significant improvements in reliability and features. We've added TOML v1.1 support, introduced new APIs like `TomlDocument` and `TomlFormat` classes, fixed numerous bugs through increase in testing namely with [toml-test](https://github.com/toml-lang/toml-test).
10
10
 
11
11
  We hope that these improvements can be incorporated upstream one day if the original author returns, but until then, this project is the actively maintained version.
12
12
 
@@ -29,7 +29,6 @@ We hope that these improvements can be incorporated upstream one day if the orig
29
29
  - [Methods](#methods)
30
30
  - [patch() Example](#patch-example)
31
31
  - [update() Example](#update-example)
32
- - [When to Use](#when-to-use-tomldocument-vs-functional-api)
33
32
  - [Formatting](#formatting)
34
33
  - [TomlFormat Class](#tomlformat-class)
35
34
  - [Basic Usage](#basic-usage)
@@ -65,7 +64,7 @@ toml-patch provides both a [functional API]((#functional-api)) for one-time oper
65
64
 
66
65
  For simple one-time operations, you can use the functional API:
67
66
 
68
- #### patch(*existing*, *updated*, *format?*)
67
+ #### <a id="patch"></a>patch(*existing*, *updated*, *format?*)
69
68
 
70
69
  ```typescript
71
70
  function patch(
@@ -145,19 +144,26 @@ owner.name = "Tim"
145
144
  );
146
145
  ```
147
146
 
148
- #### parse(*value*)
147
+ #### <a id="parse"></a>parse(*value*, *options?*)
149
148
 
150
149
  ```typescript
151
- function parse(value: string): any
150
+ function parse(value: string | Uint8Array, options?: ParseOptions): any
152
151
  ```
153
152
 
154
- Parses a TOML string into a JavaScript object. The function converts TOML syntax to its JavaScript equivalent. This proceeds in two steps: first, it parses the TOML string into an abstract syntax tree (AST), and then it converts the AST into a JavaScript object.
153
+ Parses a TOML string (or raw UTF-8 bytes) into a JavaScript object.
155
154
 
156
155
  **Parameters:**
157
- - `value: string` - The TOML string to parse
156
+ - `value: string | Uint8Array` - The TOML source to parse
157
+ - `options?: ParseOptions` - Optional parse options
158
+ - `integersAsBigInt?: 'asNeeded' | true | false` — Controls how TOML integers are represented in JS:
159
+ - `'asNeeded'` *(default)* — integers within the JS safe-integer range are `number`; larger values are `bigint` to preserve precision
160
+ - `true` — all integers are returned as `bigint`
161
+ - `false` — all integers are returned as `number` (large values lose precision)
158
162
 
159
163
  **Returns:** `any` - The parsed JavaScript object
160
164
 
165
+ > **Note:** The default `'asNeeded'` mode is a behavioral change from v1.0.7 and earlier. If your code serializes the result to JSON or mixes `number`/`bigint` arithmetic, set `integersAsBigInt: false` to restore the previous behavior.
166
+
161
167
  ##### Example
162
168
  ```js
163
169
  import * as TOML from '@decimalturn/toml-patch';
@@ -179,7 +185,7 @@ assert.deepStrictEqual(parsed, {
179
185
  });
180
186
  ```
181
187
 
182
- #### stringify(*value*, *format?*)
188
+ #### <a id="stringify"></a>stringify(*value*, *format?*)
183
189
 
184
190
  ```typescript
185
191
  function stringify(
@@ -229,13 +235,18 @@ The `TomlDocument` class provides a stateful interface for working with TOML doc
229
235
  #### Constructor
230
236
 
231
237
  ```typescript
232
- new TomlDocument(tomlString: string)
238
+ new TomlDocument(tomlSource: string | Uint8Array, options?: ParseOptions)
233
239
  ```
234
240
 
235
- Initializes the TomlDocument with a TOML string, parsing it into an internal representation (AST).
241
+ Initializes the TomlDocument with TOML source, parsing it into an internal representation (AST). When bytes are provided they are decoded as UTF-8 in fatal mode, rejecting invalid sequences before parsing.
236
242
 
237
243
  **Parameters:**
238
- - `tomlString: string` - The TOML string to parse
244
+ - `tomlSource: string | Uint8Array` - The TOML source to parse
245
+ - `options?: ParseOptions` - Optional parse options
246
+ - `integersAsBigInt?: 'asNeeded' | true | false` — Controls how TOML integers are represented in `toJsObject`:
247
+ - `'asNeeded'` *(default)* — integers within the JS safe-integer range are `number`; larger values are `bigint` to preserve precision
248
+ - `true` — all integers are returned as `bigint`
249
+ - `false` — all integers are returned as `number` (large values lose precision)
239
250
 
240
251
  ##### Basic Usage Example
241
252
 
@@ -264,7 +275,7 @@ get toTomlString(): string
264
275
  ```
265
276
 
266
277
  - `toJsObject: any` - Returns the JavaScript object representation of the TOML document
267
- - `toTomlString: string` - Returns the TOML string representation (cached for performance)
278
+ - `toTomlString: string` - Returns the current TOML string representation
268
279
 
269
280
  #### Methods
270
281
 
@@ -361,19 +372,9 @@ doc.update(updatedToml);
361
372
  console.log(doc.toJsObject.server.port); // 3000
362
373
  ```
363
374
 
364
- #### When to use TomlDocument vs Functional API
365
-
366
- | Use Case | TomlDocument | Functional API |
367
- |----------|-------------|----------------|
368
- | Multiple operations on same document | ✅ Preferred | ❌ Inefficient |
369
- | One-time parsing/patching | ⚠️ Overkill | ✅ Preferred |
370
- | Incremental text updates | ✅ `update()` method | ❌ Not supported |
371
- | Preserving document state | ✅ Built-in | ❌ Manual |
372
- | Working with large files | ✅ Better performance | ❌ Re-parses entirely |
373
-
374
375
  ## Formatting
375
376
 
376
- The `TomlFormat` class provides comprehensive control over how TOML documents are formatted during stringification and patching operations. This class encapsulates all formatting preferences, making it easy to maintain consistent styling across your TOML documents.
377
+ The `TomlFormat` class provides decent control over how TOML documents are formatted during stringification and patching operations. This class encapsulates all formatting preferences, making it easy to maintain consistent styling across your TOML documents.
377
378
 
378
379
  ### TomlFormat Class
379
380
 
@@ -385,7 +386,8 @@ class TomlFormat {
385
386
  bracketSpacing: boolean
386
387
  inlineTableStart?: number
387
388
  truncateZeroTimeInDates: boolean
388
-
389
+ minimumDecimals?: number
390
+
389
391
  static default(): TomlFormat
390
392
  static autoDetectFormat(tomlString: string): TomlFormat
391
393
  }
@@ -523,6 +525,18 @@ stringify(data, format);
523
525
  // endDate = 2024-12-31T23:59:59.999Z
524
526
  ```
525
527
 
528
+ **minimumDecimals**
529
+ - **Type:** `number` (optional)
530
+ - **Default:** `0`
531
+ - **Description:** The minimum number of decimal places to use when serializing JS numbers as TOML floats. When greater than `0`, plain JS integer values are serialized as TOML floats padded with zeros to reach the specified decimal count. `bigint` values are always serialized as TOML integers regardless of this setting.
532
+
533
+ ```js
534
+ const format = TomlFormat.default();
535
+ format.minimumDecimals = 0; // { x: 1, y: 1.5 } → { x = 1, y = 1.5 } (default)
536
+ format.minimumDecimals = 1; // { x: 1, y: 1.5 } → { x = 1.0, y = 1.5 }
537
+ format.minimumDecimals = 2; // { x: 1, y: 1.5 } → { x = 1.00, y = 1.50 }
538
+ ```
539
+
526
540
  ### Auto-Detection and Patching
527
541
 
528
542
  The `TomlFormat.autoDetectFormat()` method analyzes existing TOML strings to automatically detect and preserve their current formatting. If you don't supply the `format` argument when patching an existing document, this is what will be used to determine the formatting to use when inserting new elements.
@@ -1,4 +1,4 @@
1
- //! @decimalturn/toml-patch v1.0.6 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v1.1.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
2
  declare class TomlFormat {
3
3
  /**
4
4
  * The line ending character(s) to use in the output TOML.
@@ -68,7 +68,19 @@ declare class TomlFormat {
68
68
  *
69
69
  */
70
70
  useTabsForIndentation?: boolean;
71
- constructor(newLine?: string, trailingNewline?: number, trailingComma?: boolean, bracketSpacing?: boolean, inlineTableStart?: number, truncateZeroTimeInDates?: boolean, useTabsForIndentation?: boolean);
71
+ /**
72
+ * The minimum number of decimal places to use when serializing JS numbers as TOML floats.
73
+ * When greater than 0, plain JS integer values are serialized as TOML floats padded with
74
+ * zeros to reach the specified decimal count. BigInt values are always serialized as integers
75
+ * regardless of this setting.
76
+ *
77
+ * @example
78
+ * - 0: stringify({ x: 1, y: 1.5 }) → x = 1 / y = 1.5 (default)
79
+ * - 1: stringify({ x: 1, y: 1.5 }) → x = 1.0 / y = 1.5
80
+ * - 2: stringify({ x: 1, y: 1.5 }) → x = 1.00 / y = 1.50
81
+ */
82
+ minimumDecimals?: number;
83
+ constructor(newLine?: string, trailingNewline?: number, trailingComma?: boolean, bracketSpacing?: boolean, inlineTableStart?: number, truncateZeroTimeInDates?: boolean, useTabsForIndentation?: boolean, minimumDecimals?: number);
72
84
  /**
73
85
  * Creates a new TomlFormat instance with default formatting preferences.
74
86
  *
@@ -102,6 +114,11 @@ declare class TomlFormat {
102
114
  static autoDetectFormat(tomlString: string): TomlFormat;
103
115
  }
104
116
 
117
+ type IntegersAsBigInt = boolean | 'asNeeded';
118
+ interface ParseOptions {
119
+ integersAsBigInt?: IntegersAsBigInt;
120
+ }
121
+
105
122
  interface Location {
106
123
  start: Position;
107
124
  end: Position;
@@ -174,7 +191,7 @@ interface String extends TreeNode {
174
191
  interface Integer extends TreeNode {
175
192
  type: NodeType.Integer;
176
193
  raw: string;
177
- value: number;
194
+ value: number | bigint;
178
195
  }
179
196
  interface Float extends TreeNode {
180
197
  type: NodeType.Float;
@@ -281,6 +298,45 @@ interface TreeNode {
281
298
  */
282
299
  declare function patch(existing: string, updated: any, format?: Partial<TomlFormat> | TomlFormat): string;
283
300
 
301
+ /**
302
+ * Custom Date class for local dates (date-only).
303
+ * Format: 1979-05-27
304
+ */
305
+ declare class LocalDate extends Date {
306
+ constructor(value: string);
307
+ toISOString(): string;
308
+ }
309
+ /**
310
+ * Custom Date class for local times (time-only)
311
+ * Format: 07:32:00 or 07:32:00.999
312
+ */
313
+ declare class LocalTime extends Date {
314
+ originalFormat: string;
315
+ constructor(value: string, originalFormat: string);
316
+ toISOString(): string;
317
+ }
318
+ /**
319
+ * Custom Date class for local datetime (no timezone)
320
+ * Format: 1979-05-27T07:32:00 or 1979-05-27 07:32:00
321
+ */
322
+ declare class LocalDateTime extends Date {
323
+ useSpaceSeparator: boolean;
324
+ originalFormat: string;
325
+ constructor(value: string, useSpaceSeparator?: boolean, originalFormat?: string);
326
+ toISOString(): string;
327
+ }
328
+ /**
329
+ * Custom Date class for offset datetime that preserves space separator
330
+ * Format: 1979-05-27T07:32:00Z or 1979-05-27 07:32:00-07:00
331
+ */
332
+ declare class OffsetDateTime extends Date {
333
+ useSpaceSeparator: boolean;
334
+ originalOffset?: string;
335
+ originalFormat: string;
336
+ constructor(value: string, useSpaceSeparator?: boolean);
337
+ toISOString(): string;
338
+ }
339
+
284
340
  /**
285
341
  * TomlDocument encapsulates a TOML AST and provides methods to interact with it.
286
342
  */
@@ -288,11 +344,18 @@ declare class TomlDocument {
288
344
  private _ast;
289
345
  private _currentTomlString;
290
346
  private _format;
347
+ private _integersAsBigInt;
291
348
  /**
292
- * Initializes the TomlDocument with a TOML string, parsing it into an AST.
293
- * @param tomlString - The TOML string to parse
349
+ * Initializes the TomlDocument with TOML source, parsing it into an AST.
350
+ *
351
+ * When bytes are provided, they are decoded as UTF-8 in fatal mode.
352
+ * This rejects invalid UTF-8 sequences before parsing.
353
+ *
354
+ * @param tomlSource - The TOML source to parse (string or raw UTF-8 bytes)
355
+ * @param options - Optional parse options
356
+ * @param options.integersAsBigInt - Controls bigint vs number for TOML integers
294
357
  */
295
- constructor(tomlString: string);
358
+ constructor(tomlSource: string | Uint8Array, options?: ParseOptions);
296
359
  get toTomlString(): string;
297
360
  /**
298
361
  * Returns the JavaScript object representation of the TOML document.
@@ -325,15 +388,33 @@ declare class TomlDocument {
325
388
  }
326
389
 
327
390
  /**
328
- * Parses a TOML string into a JavaScript object.
329
- * The function converts TOML syntax to its JavaScript equivalent.
330
- * This proceeds in two steps: first, it parses the TOML string into an AST,
331
- * and then it converts the AST into a JavaScript object.
391
+ * Parses a TOML string or raw UTF-8 bytes into a JavaScript object.
392
+ *
393
+ * When raw bytes (Uint8Array / Buffer) are provided, they are decoded with
394
+ * the WHATWG TextDecoder in fatal mode, which rejects any invalid UTF-8
395
+ * byte sequences before parsing begins. This matches the TOML spec requirement
396
+ * that "A TOML file must be a valid UTF-8 encoded Unicode document."
397
+ *
398
+ * The string path has zero overhead — the bytes path incurs one TextDecoder
399
+ * decode (which also produces the string needed for parsing).
400
+ *
401
+ * By default (`options.integersAsBigInt` unset or `'asNeeded'`), integers that
402
+ * fit within the JavaScript safe-integer range are returned as `number`; integers
403
+ * outside that range are returned as `bigint` to preserve precision. Set
404
+ * `options.integersAsBigInt` to `true` to always return `bigint` for all integers,
405
+ * or `false` to always return `number` (large integers will lose precision).
406
+ *
407
+ * Note: the `'asNeeded'` default is a behavioral change from prior versions (<=1.0.7). If
408
+ * your code serializes the result to JSON or performs arithmetic mixing `number`
409
+ * and `bigint`, set `integersAsBigInt: false` to restore the previous behavior.
332
410
  *
333
- * @param value - The TOML string to parse
411
+ * @param value - TOML source as a string or raw UTF-8 bytes
412
+ * @param options - Optional parse options
413
+ * @param options.integersAsBigInt - Controls `bigint` vs `number` for integers.
414
+ * `'asNeeded'` (default) | `true` | `false`
334
415
  * @returns The parsed JavaScript object
335
416
  */
336
- declare function parse(value: string): any;
417
+ declare function parse(value: string | Uint8Array, options?: ParseOptions): any;
337
418
  /**
338
419
  * Converts a JavaScript object to a TOML string.
339
420
  *
@@ -343,4 +424,5 @@ declare function parse(value: string): any;
343
424
  */
344
425
  declare function stringify(value: any, format?: Partial<TomlFormat> | TomlFormat): string;
345
426
 
346
- export { TomlDocument, TomlFormat, parse, patch, stringify };
427
+ export { LocalDate, LocalDateTime, LocalTime, OffsetDateTime, TomlDocument, TomlFormat, parse, patch, stringify };
428
+ export type { IntegersAsBigInt, ParseOptions };
@@ -1,2 +1,2 @@
1
- //! @decimalturn/toml-patch v1.0.6 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- var e,t;function n(t){return t.type===e.Document}function o(t){return t.type===e.Table}function r(t){return t.type===e.TableArray}function l(t){return t.type===e.KeyValue}function i(t){return t.type===e.String}function a(t){return t.type===e.DateTime}function s(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function m(e){return n(e)||o(e)||r(e)||u(e)||s(e)}function d(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function h(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function p(e,t){const n=Array.isArray(e)?e:w(e);if(0===n.length)return{line:1,column:t};let o=0,r=n.length-1;for(;o<r;){const e=o+r>>>1;n[e]<t?o=e+1:r=e}n[o]<t&&o++;const l=o+1;return{line:l,column:t-(n[l-2]+1||0)}}function w(e){const t=[];for(let n=0;n<e.length;n++){const o=e.charCodeAt(n);10===o?t.push(n):13===o&&(10===e.charCodeAt(n+1)?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function y(e){return{line:e.line,column:e.column}}function g(e){return{start:y(e.start),end:y(e.end)}}!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"}(e||(e={}));class v extends Error{constructor(e,t,n){let o=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=w(e),o=void 0!==n[t.line-2]?n[t.line-2]+1:0,r=n[t.line-1]||e.length;return e.substring(o,r)}(e,t),r=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(o+=`${n}\n${r}\n`)}o+=n,super(o),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"}(t||(t={}));const b='"',T="'",$=" ",k=/[\w,\d,",',+,\-,_]/,S=10,I=13,E=127;function*A(e){const n=e.length;let o=0;const r=[],l=(e,t)=>({start:p(r,e),end:p(r,t)});for(;o<n;){const c=e.charCodeAt(o);if((c<=31||c===E)&&9!==c&&c!==I&&c!==S)throw new v(e,p(r,o),`Control char 0x${c.toString(16).toUpperCase().padStart(2,"0")} not allowed`);if(c===I&&(o+1>=n||e.charCodeAt(o+1)!==S))throw new v(e,p(r,o),"Standalone CR; must be CRLF or LF");if(32===c||9===c||c===I);else if(c===S)r.push(o);else if(91===c||93===c)yield{type:t.Bracket,raw:e[o],loc:l(o,o+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[o],loc:l(o,o+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:l(o,o+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:l(o,o+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:l(o,o+1)};else if(35===c)yield i();else{const t=C(e,o,T)||C(e,o,b);t?yield a(t):yield s()}o++}function i(){const i=o;for(;o+1<n;){const t=e.charCodeAt(o+1);if(t===S||t===I)break;o++;const n=e.charCodeAt(o);if((n<=31||n===E)&&9!==n)throw new v(e,p(r,o),`Control char 0x${n.toString(16).toUpperCase().padStart(2,"0")} not allowed`)}return{type:t.Comment,raw:e.slice(i,o+1),loc:l(i,o+1)}}function a(i){const a=o,s=i+i+i;for(o+=3;o<n;){if(C(e,o,i)){let t=3;for(;e[o+t]===i;)t++;if(t>=6)throw new v(e,p(r,o),`Invalid multiline string: ${t} consecutive ${i} characters`);if(3===t){o+=2;break}o+=t-3,o+=2;break}const t=e.charCodeAt(o);if(t===I&&(o+1>=n||e.charCodeAt(o+1)!==S))throw new v(e,p(r,o),"Standalone CR in multiline string; must be CRLF or LF");if((t<=31||t===E)&&9!==t&&t!==S&&t!==I){const n=i===b?"multiline basic strings":"multiline literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let a="";0===t?a="Null":t===E&&(a="DEL");const s=a?`${a} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),s)}t===S&&r.push(o),o++}if(o>=n){if(i===b){let t=0,l=n-1;for(;l>=0&&"\\"===e[l];)t++,l--;if(t>0&&t%2!=0)throw new v(e,p(r,o),`Unterminated multiline ${s} (possible escape issue)`)}throw new v(e,p(r,o),`Unterminated multiline ${s}`)}return{type:t.Literal,raw:e.slice(a,o+1),loc:l(a,o+1)}}function s(){const i=e[o];if(!k.test(i))throw new v(e,p(r,o),`Unexpected char "${i}"`);const a=o;let s=i===b,c=i===T;for(;o<n&&!(o+1>=n);){const t=e.charCodeAt(o+1);if(!(s||c||32!==t&&9!==t&&t!==S&&t!==I&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(o++,s||c){const t=e.charCodeAt(o);if((t<=31||t===E)&&9!==t){const n=s?"basic strings":"literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";t===S?i="Newline":t===I?i="Carriage return":0===t?i="Null":t===E&&(i="DEL");const a=i?`${i} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),a)}}const l=e[o];if(l===b&&(s=!s),l!==T||s||(c=!c),o+1>=n)break;if(s&&"\\"===l){const t=e[o+1];t!==b&&"\\"!==t||o++}}if(s||c)throw new v(e,p(r,a),`Expected close of string with ${s?b:T}`);return{type:t.Literal,raw:e.slice(a,o+1),loc:l(a,o+1)}}}function C(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===T)return n;let o=0,r=t-1;for(;r>=0&&"\\"===e[r];)o++,r--;if(0===o)return n;return!(o%2!=0)&&n}const x=new Int8Array(128);x.fill(-1);for(let e=0;e<10;e++)x[48+e]=e;for(let e=0;e<6;e++)x[65+e]=10+e,x[97+e]=10+e;function _(e){const t=e.charCodeAt(0);return t<128&&-1!==x[t]}function O(e,t){return x[e.charCodeAt(t)]<<12|x[e.charCodeAt(t+1)]<<8|x[e.charCodeAt(t+2)]<<4|x[e.charCodeAt(t+3)]}function D(e){return e.startsWith("'''")?L(e.slice(3,e.length-3)):e.startsWith(T)?e.slice(1,e.length-1):e.startsWith('"""')?F(L(e.slice(3,e.length-3)),!0):e.startsWith(b)?F(e.slice(1,e.length-1),!1):e}function F(e,t){const n=e.length;if(!t&&-1===e.indexOf("\\"))return e;const o=[];let r=0;for(let l=0;l<n;l++){if("\\"!==e[l])continue;if(l>r&&o.push(e.slice(r,l)),l++,l>=n)throw new Error("Trailing backslash");const i=e[l];switch(i){case"b":o.push("\b");break;case"t":o.push("\t");break;case"n":o.push("\n");break;case"f":o.push("\f");break;case"r":o.push("\r");break;case'"':o.push('"');break;case"\\":o.push("\\");break;case"e":o.push("");break;case"u":{if(l+4>n||!_(e[l+1])||!_(e[l+2])||!_(e[l+3])||!_(e[l+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(l+1,l+5)}`);const t=O(e,l+1);if(t>=55296&&t<=57343)throw new Error(`Invalid \\u${e.slice(l+1,l+5)}: surrogates not allowed`);o.push(String.fromCharCode(t)),l+=4;break}case"U":{if(l+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);for(let t=1;t<=8;t++)if(!_(e[l+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);const t=parseInt(e.slice(l+1,l+9),16);o.push(String.fromCodePoint(t)),l+=8;break}case"x":{if(l+2>n||!_(e[l+1])||!_(e[l+2]))throw new Error(`Invalid hex escape: \\x${e.slice(l+1,l+3)}`);const t=x[e.charCodeAt(l+1)]<<4|x[e.charCodeAt(l+2)];o.push(String.fromCharCode(t)),l+=2;break}default:if(t&&("\n"===i||"\r"===i||" "===i||"\t"===i)){let t="\n"===i||"\r"===i,o=l;for(;o<n&&(" "===e[o]||"\t"===e[o]||"\n"===e[o]||"\r"===e[o]);)"\n"!==e[o]&&"\r"!==e[o]||(t=!0),o++;if(!t)throw new Error(`Invalid escape sequence: \\${i}`);l=o-1;break}throw new Error(`Invalid escape sequence: \\${i}`)}r=l+1}return 0===r?e:(r<n&&o.push(e.slice(r)),o.join(""))}function L(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class K{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 M();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?M():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const U=Object.freeze({value:void 0,done:!0});function M(){return U}function N(e){return{year:String(e.getUTCFullYear()),month:String(e.getUTCMonth()+1).padStart(2,"0"),day:String(e.getUTCDate()).padStart(2,"0"),hours:String(e.getUTCHours()).padStart(2,"0"),minutes:String(e.getUTCMinutes()).padStart(2,"0"),seconds:String(e.getUTCSeconds()).padStart(2,"0"),ms:e.getUTCMilliseconds()}}function j(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(".")){const o=t.match(n),r=o?o[1].length:3;return"."+String(e).padStart(3,"0").slice(0,r)}return e>0?"."+String(e).padStart(3,"0").replace(/0+$/,""):""}function W(e){if("Z"===e)return 0;const t="+"===e[0]?1:-1,[n,o]=e.slice(1).split(":");return t*(60*parseInt(n)+parseInt(o))}class B{static createDateWithOriginalFormat(e,t){if(B.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof z)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new q(t,!1)}const t=e.toISOString().split("T")[0];return new Z(t)}if(B.IS_TIME_ONLY.test(t)){if(e instanceof V)return e;{const n=N(e),o=j(n.ms,t);return new V(`${n.hours}:${n.minutes}:${n.seconds}${o}`,t)}}if(B.IS_LOCAL_DATETIME_T.test(t)){const n=N(e),o=j(n.ms,t);return new q(`${n.year}-${n.month}-${n.day}T${n.hours}:${n.minutes}:${n.seconds}${o}`,!1,t)}if(B.IS_LOCAL_DATETIME_SPACE.test(t)){const n=N(e),o=j(n.ms,t);return new q(`${n.year}-${n.month}-${n.day} ${n.hours}:${n.minutes}:${n.seconds}${o}`,!0,t)}if(B.IS_OFFSET_DATETIME_T.test(t)||B.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),o=n?"z"===n[1]?"Z":n[1]:"Z",r=B.IS_OFFSET_DATETIME_SPACE.test(t),l=N(new Date(e.getTime()+6e4*W(o))),i=r?" ":"T",a=j(l.ms,t,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),s=`${l.year}-${l.month}-${l.day}${i}${l.hours}:${l.minutes}:${l.seconds}${a}${o}`;return new z(s,r)}return e}}B.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,B.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,B.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,B.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,B.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class Z extends Date{constructor(e){super(e)}toISOString(){const e=N(this);return`${e.year}-${e.month}-${e.day}`}}class V extends Date{constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+":00"),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){const e=N(this);return`${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}}class q extends Date{constructor(e,t=!1,n){let o=e;/\d{2}:\d{2}:\d{2}/.test(e)||(o=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(o.replace(" ","T")+"Z"),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=N(this),t=this.useSpaceSeparator?" ":"T";return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}}class z extends Date{constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(n.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const o=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);o&&(this.originalOffset="z"===o[1]?"Z":o[1])}toISOString(){if(this.originalOffset){const e=N(new Date(this.getTime()+6e4*W(this.originalOffset))),t=this.useSpaceSeparator?" ":"T",n=j(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const R=B,P="true",H=/e/i,J=/_/g,Y=/^[+-]?inf$/,G=/^[+-]?nan$/,Q=/^[+-]?0x/i;function X(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const ee=/^[+-]?0o/i,te=/^[+-]?0b/i;function ne(e,t,n){for(let o=0;o<e.length;o++)if(!X(e.charCodeAt(o)))throw new v(t,{line:n.line,column:n.column+o},`Invalid bare key char '${e[o]}'`)}function oe(e,t,n){if(e.startsWith('"""')||e.startsWith("'''"))throw new v(t,n,"Multiline strings cannot be keys")}function re(e,t,n){try{return D(e)}catch(e){throw new v(t,n,e.message)}}function le(e,t,n,o=!0){if(e.endsWith("_"))throw new v(t,n,"Underscore must be between digits");if(o?/^[+-]?_/.test(e):e.startsWith("_"))throw new v(t,n,"Underscore must be between digits");if(/__/.test(e))throw new v(t,n,"Consecutive underscores not allowed")}function ie(e,t,n,o){const r=e.replace(J,"");if(/^[+-]?0\d/.test(r)&&!Q.test(e)&&!ee.test(e)&&!te.test(e))throw new v(t,n,`Leading zeros are not allowed in ${o}`)}function ae(e,t,n,o){if(/_[eE]/.test(e))throw new v(n,o,"Underscore before exponent is not allowed");if(/[eE][+-]?_/.test(e))throw new v(n,o,"Underscore at start of exponent is not allowed");if(/[eE][+-]?$/.test(e))throw new v(n,o,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new v(n,o,`Invalid float "${t}": decimal point not allowed in exponent`)}function se(e,t,n,o,r,l){if(2!==e.length)throw new v(r,l,`"${o}": hour must be 2 digits`);if(2!==t.length)throw new v(r,l,`"${o}": minute must be 2 digits`);if(n&&2!==n.length)throw new v(r,l,`"${o}": second must be 2 digits`)}function ce(e,t,n,o,r,l){if(void 0!==e){const t=parseInt(e,10);if(t<0||t>23)throw new v(r,l,`"${o}": hour must be 00-23`)}if(void 0!==t){const e=parseInt(t,10);if(e<0||e>59)throw new v(r,l,`"${o}": minute must be 00-59`)}if(void 0!==n){const e=parseInt(n,10);if(e<0||e>60)throw new v(r,l,`"${o}": second must be 00-60`)}}function ue(e,t,n,o,r,l,i){const a=o[0]+o[1].toUpperCase();if(new RegExp("^[+\\-]?"+a.replace(/([[\]])/g,"\\$1")).test(e))throw new v(t,n,`${l} prefix must be lowercase "${o}"`);if(new RegExp("^[+\\-]?"+o+"_","i").test(e))throw new v(t,n,"Underscore must be between digits");const s=new RegExp("^[+\\-]?"+o,"i"),c=e.replace(s,"");if(!c||"_"===c||c.startsWith("_"))throw new v(t,n,`Incomplete ${l.toLowerCase()} number`);const u=c.replace(/_/g,"");if(!r.test(u))throw new v(t,n,null!=i?i:`Invalid ${l.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new v(t,n,`${l} numbers cannot have a sign prefix`)}function*fe(e){const t=new K(A(e));for(;!t.next().done;){const n=ve(t,e);for(const e of n)yield e}}function me(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function de(n,o){const r=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,l=r===e.Table;if(l&&"["!==n.value.raw)throw new v(o,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!l){const e=n.peek();if(e.done)throw new v(o,n.value.loc.start,'Expected "[[" for Array of Tables, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new v(o,n.value.loc.start,`Expected "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,r=e.value;if(t.loc.end.line!==r.loc.start.line||t.loc.end.column!==r.loc.start.column)throw new v(o,t.loc.start,'"[[" brackets must be adjacent (no whitespace)')}const i=l?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),r===e.TableArray&&n.next(),n.done)throw new v(o,i.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new v(o,n.value.loc.start,r===e.TableArray?"Array of Tables header [[]] requires a table name":"Table header [] requires a table name");const a=n.value.raw;oe(a,o,n.value.loc.start);let s;for(a.startsWith('"')||a.startsWith("'")||ne(a,o,n.value.loc.start),s=[re(n.value.raw,o,n.value.loc.start)],i.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:s};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;t.startsWith('"')||t.startsWith("'")||ne(t,o,n.value.loc.start);const r=" ".repeat(e.loc.start.column-i.item.loc.end.column),l=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${r}.${l}${n.value.raw}`;try{i.item.value.push(D(n.value.raw))}catch(e){const t=e;throw new v(o,n.value.loc.start,t.message)}}if(n.next(),!n.done){const e=i.loc.start.line;if(n.value.loc.start.line!==e)throw new v(o,n.value.loc.start,l?"Table header must be single-line":"Array of Tables header must be single-line")}if(l&&(n.done||"]"!==n.value.raw))throw new v(o,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!l&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(o,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected "]]" closing, found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);if(!l){const e=n.value,t=n.peek().value;if(e.loc.end.line!==t.loc.start.line||e.loc.end.column!==t.loc.start.column)throw new v(o,e.loc.start,'"]]" brackets must be adjacent (no whitespace)')}if(l||n.next(),i.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===i.loc.end.line&&e.type!==t.Comment)throw new v(o,e.loc.start,`Extra content after ${l?"table":"Array of Tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=ve(n,o);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:l?e.Table:e.TableArray,loc:{start:y(i.loc.start),end:c.length?y(c[c.length-1].loc.end):y(i.loc.end)},key:i,items:c}}function he(t,n){const o=re(t.value.raw,n,t.value.loc.start);return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:o}}function pe(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===P}}function we(n,o){let r,l=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&R.IS_FULL_DATE.test(i)&&R.IS_FULL_TIME.test(n.peek().value.raw)){const e=l.start;n.next(),l={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=l.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fractional value for DateTime");n.next(),l={start:e,end:n.value.loc.end},i+=`.${n.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new v(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new v(t,n,`"${e}": offset needs HH:MM`);const o=/\d{2}:\d{2}/.test(e),r=o?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){const e=r[0],o=r[2],l=r[3],i=r[4];if(":"!==l)throw new v(t,n,`Offset "${e}": missing colon separator`);if(2!==o.length)throw new v(t,n,`Offset "${e}": hour must be 2 digits`);if(!i||0===i.length)throw new v(t,n,`Offset "${e}": minute required`);if(2!==i.length)throw new v(t,n,`Offset "${e}": minute must be 2 digits`);const a=parseInt(o,10);if(a<0||a>23)throw new v(t,n,`Offset "${e}": hour must be 00-23`);const s=parseInt(i,10);if(s<0||s>59)throw new v(t,n,`Offset "${e}": minute must be 00-59`)}const l=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!l.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new v(t,n,`"${e}": 'T' requires time component`);if(/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e))throw new v(t,n,`Invalid date "${e}": unexpected character after date`);if(/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e))throw new v(t,n,`"${e}": missing 'T' or space separator`);throw new v(t,n,`Invalid datetime "${e}"`)}const i=e.match(/^(\d+)-/);if(i&&4!==i[1].length)throw new v(t,n,`"${e}": year must be 4 digits`);const a=/^(\d+)-(\d+)-(\d+)/,s=e.match(a);if(s){const[,,o,r]=s;if(2!==o.length)throw new v(t,n,`"${e}": month must be 2 digits`);if(2!==r.length)throw new v(t,n,`"${e}": day must be 2 digits`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,o,r,l]=u;se(o,r,l,e,t,n)}const f=/^(\d+):(\d+)(?::(\d+))?/,m=e.match(f);if(m&&!s){const[,o,r,l]=m;se(o,r,l,e,t,n)}const d=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(d){const[,o,r,l,i,a,s]=d,c=parseInt(r,10);if(c<1||c>12)throw new v(t,n,`"${e}": month must be 01-12`);const u=parseInt(l,10);if(u<1||u>31)throw new v(t,n,`"${e}": day must be 01-31`);const f=function(e,t){const n=[31,28,31,30,31,30,31,31,30,31,30,31];if(2===t){return e%4==0&&e%100!=0||e%400==0?29:28}return n[t-1]}(parseInt(o,10),c);if(u>f)throw new v(t,n,`"${e}": day ${l} invalid for ${o}-${r}`);ce(i,a,s,e,t,n)}else if(h){const[,o,r,l]=h;ce(o,r,l,e,t,n)}}(i,o,l.start),R.IS_FULL_DATE.test(i))r=R.IS_DATE_ONLY.test(i)?new Z(i):R.IS_LOCAL_DATETIME_T.test(i)?new q(i,!1):R.IS_LOCAL_DATETIME_SPACE.test(i)?new q(i,!0):R.IS_OFFSET_DATETIME_T.test(i)?new z(i,!1):R.IS_OFFSET_DATETIME_SPACE.test(i)?new z(i,!0):new Date(i.replace(" ","T"));else if(R.IS_TIME_ONLY.test(i))r=new V(i,i);else{const[e]=(new Date).toISOString().split("T");r=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:l,raw:i,value:r}}function ye(n,o){let r,l=n.value.loc,i=n.value.raw;if(Y.test(i))r=i.startsWith("-")?-1/0:1/0;else if(G.test(i))r=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(le(i,o,l.start),ae(i,i,o,l.start),!n.peek().done&&n.peek().value.type===t.Dot)throw new v(o,n.peek().value.loc.start,`Float "${i}.": dot after exponent`);ie(i,o,l.start,"the integer part of a float"),r=Number(i.replace(J,""))}else{const e=l.start;{if(H.test(i)&&!Q.test(i))throw new v(o,l.start,`Float "${i}": dot after exponent`);const e=i;ie(e,o,l.start,"the integer part of a float");const t=e.replace(/^[+-]/,"");if(""===t||"_"===t)throw new v(o,l.start,"Float: digit required before dot");le(e,o,l.start)}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,l={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new v(o,n.value.loc.start,`Float: fraction must start with digit, found "${e}"`);le(e,o,n.value.loc.start,!1),ae(e,i,o,n.value.loc.start)}r=Number(i.replace(J,""))}if(Number.isNaN(r)&&!G.test(i))throw new v(o,l.start,`Invalid float "${i}"`);return{type:e.Float,loc:l,raw:i,value:r}}function ge(t,n){const o=t.value.raw,r=t.value.loc;if(/^\d{1,}-\d{1,}/.test(o)||/^\d{1,}:\d{1,}/.test(o)||/^\d{6}-\d{2}$/.test(o))throw new v(n,r.start,`Invalid integer "${o}"`);if("-0"===o||"+0"===o)return{type:e.Integer,loc:r,raw:o,value:0};if(/^[+-]{2,}/.test(o))throw new v(n,r.start,"Double sign is not allowed in integers");ie(o,n,r.start,"decimal integers"),le(o,n,r.start);let l=10;Q.test(o)?(l=16,ue(o,n,r.start,"0x",/^[0-9a-fA-F]+$/,"Hexadecimal")):ee.test(o)?(l=8,ue(o,n,r.start,"0o",/^[0-7]+$/,"Octal","Invalid octal digits (must be 0-7)")):te.test(o)&&(l=2,ue(o,n,r.start,"0b",/^[01]+$/,"Binary","Invalid binary digits (must be 0 or 1)"));const i=parseInt(o.replace(J,"").replace(ee,"").replace(te,""),l);if(Number.isNaN(i))throw new v(n,r.start,`Invalid integer "${o}"`);return{type:e.Integer,loc:r,raw:o,value:i}}function ve(n,o){if(n.value.type===t.Comment)return[me(n)];if(n.value.type===t.Bracket)return[de(n,o)];if(n.value.type===t.Literal)return function(n,o){const r=n.value.raw;if(r.endsWith(":"))throw new v(o,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...r].length-1},"Use '=' to separate keys and values, not ':'");oe(r,o,n.value.loc.start);r.startsWith('"')||r.startsWith("'")||ne(r,o,n.value.loc.start);let l;l=[re(n.value.raw,o,n.value.loc.start)];const i={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:l};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;oe(e,o,n.value.loc.start);e.startsWith('"')||e.startsWith("'")||ne(e,o,n.value.loc.start),i.loc.end=n.value.loc.end,i.raw+=`.${n.value.raw}`,i.value.push(re(n.value.raw,o,n.value.loc.start))}if(n.next(),!n.done&&n.value.loc.start.line!==i.loc.end.line)throw new v(o,n.value.loc.start,'"=" must be on same line as key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new v(o,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new v(o,n.done?i.loc.end:n.value.loc.start,'Expected "=" for key-value')}const a=n.value.loc.start.column,s=n.value.loc.start.line;if(n.next(),n.done)throw new v(o,i.loc.start,"Expected value, reached EOF");if(n.value.loc.start.line!==s)throw new v(o,n.value.loc.start,"Value must be on same line as '='");if(n.done)throw new v(o,i.loc.start,"Expected value for key-value");const c=be(n,o),u=c[0];if(!n.peek().done){const r=n.peek().value;if(r.type===t.Dot&&r.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new v(o,r.loc.start,"Invalid number: multiple decimal points not allowed");if((r.type===t.Literal||r.type===t.Bracket)&&r.loc.start.line===u.loc.end.line)throw new v(o,r.loc.start,"Key/value pairs must be separated by a newline")}return c[0]={type:e.KeyValue,key:i,value:u,loc:{start:y(i.loc.start),end:y(u.loc.end)},equals:a},c}(n,o);throw n.value.type===t.Equal?new v(o,n.value.loc.start,"Missing key before '='"):new v(o,n.value.loc.start,`Unexpected token "${n.value.type}"`)}function be(n,o){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===b||e[0]===T?[he(n,o)]:e===P||"false"===e?[pe(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[we(n,o)]:!n.peek().done&&n.peek().value.type===t.Dot||Y.test(e)||G.test(e)||H.test(e)&&!Q.test(e)?[ye(n,o)]:[ge(n,o)]}if(n.value.type===t.Curly){const[r,l]=function(n,o){if("{"!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "{" for inline table');const r={type:e.InlineTable,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){l.push(me(n)),n.next();continue}if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in inline table");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in inline table");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const i=r.items[r.items.length-1];if(i&&!i.comma)throw new v(o,n.value.loc.start,"Missing comma between inline table items");const a=ve(n,o),s=a[0];if(s.type===e.KeyValue){r.items.push({type:e.InlineItem,loc:g(s.loc),item:s,comma:!1});for(let e=1;e<a.length;e++)l.push(a[e])}n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "}"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}if(n.value.type===t.Bracket){const[r,l]=function(n,o){if("["!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "[" for inline array');const r={type:e.InlineArray,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in array");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in array");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)l.push(me(n));else{const t=r.items[r.items.length-1];if(t&&!t.comma)throw new v(o,n.value.loc.start,"Missing comma between array elements");const i=be(n,o),a=i[0];r.items.push({type:e.InlineItem,loc:g(a.loc),item:a,comma:!1});for(let e=1;e<i.length;e++)l.push(i[e])}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "]"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}throw n.value.type===t.Dot?new v(o,n.value.loc.start,"Number cannot start with a dot"):new v(o,n.value.loc.start,"Unrecognized token type")}function Te(e){return e[e.length-1]}function $e(){return Object.create(null)}function ke(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function Se(e){return"[object Date]"===Object.prototype.toString.call(e)}function Ie(e){return e&&"object"==typeof e&&!Se(e)&&!Array.isArray(e)}function Ee(e){return null!=e&&"function"==typeof e[Symbol.iterator]}function Ae(e,t){return t in e}function Ce(e){if(Ie(e)){return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Ce(e[t])}`).join(",")}}`}return Array.isArray(e)?`[${e.map(Ce).join(",")}]`:JSON.stringify(e)}function xe(e,t){const n=e.length,o=t.length;e.length=n+o;for(let r=0;r<o;r++)e[n+r]=t[r]}function _e(e){return e.startsWith('"""')||e.startsWith("'''")}const Oe=new WeakSet,De=new WeakMap,Fe=e=>(De.has(e)||De.set(e,new WeakMap),De.get(e)),Le=new WeakMap,Ke=e=>(Le.has(e)||Le.set(e,new WeakMap),Le.get(e));function Ue(e,t,n,o){if(m(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.items.splice(e,1,o)}else if(l(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.value.items.splice(e,1,o)}else if(d(t))t.item=o;else{if(!l(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=o:t.value=o}Ve(o,{lines:n.loc.start.line-o.loc.start.line,columns:n.loc.start.column-o.loc.start.column});const r=h(n.loc),i=h(o.loc);ze({lines:i.lines-r.lines,columns:i.columns-r.columns},Ke(e),o,n),Oe.add(e)}function Me(e,t,i,a,d){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,w;a=null!=a&&"number"==typeof a?a:t.items.length,s(t)||u(t)?({shift:p,offset:w}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const o=null!=n?e.items[n-1]:Te(e.items),r=null==n||n===e.items.length;e.items.splice(n,0,t);const l=!!o,i=!r;l&&(o.comma=!0);i&&(t.comma=!0);const a=qe(e),s=r&&!0===t.comma;return Ne(e,t,n,{useNewLine:a,hasCommaHandling:!0,isLastElement:r,hasSeparatingCommaBefore:l,hasSeparatingCommaAfter:i,hasTrailingComma:s})}(t,i,a)):d&&n(t)?({shift:p,offset:w}=function(e,t,n){const o=Ne(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),o}(t,i,a)):({shift:p,offset:w}=function(e,t,i){if(a=t,!(l(a)||o(a)||r(a)||f(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:y(e.loc.start),m=o(t)||r(t);let d=0;c||(d=m?2:1);u.line+=d;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},w=h(t.loc),g={lines:w.lines+(d-1),columns:w.columns};return{shift:p,offset:g}}(t,i,a)),Ve(i,p);const g=t.items[a-1],v=g&&Ke(e).get(g);if(v&&(w.lines+=v.lines,w.columns+=v.columns,Ke(e).delete(g)),u(t)&&0!==w.lines&&m(e)&&e!==t){const t=i.loc.start.line,n=e.items;for(let e=0;e<n.length;e++){const o=n[e];if(!f(o))continue;o.loc.start.line<t&&(o.loc.start.line-=w.lines,o.loc.end.line-=w.lines)}}Ke(e).set(i,w),Oe.add(e)}function Ne(e,t,n,o={}){const{useNewLine:r=!1,skipCommaSpace:l=2,skipBracketSpace:i=1,hasCommaHandling:a=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:m=!1}=o,d=n>0?e.items[n-1]:void 0,p=d?{line:d.loc.end.line,column:r?f(d)?e.loc.start.column:d.loc.start.column:d.loc.end.column}:y(e.loc.start);let w=0;if(r)w=1;else{const e=c||!a&&!!d;e&&a?p.column+=l:(e||a&&!d)&&(p.column+=i)}p.line+=w;const g={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=h(t.loc);if(!a){return{shift:g,offset:{lines:v.lines+(w-1),columns:v.columns}}}let b=0;c&&m&&!u&&s&&(b=-1);return{shift:g,offset:{lines:v.lines+(w-1),columns:v.columns+(c||u?l:0)+(m?1+b:0)}}}function je(e,t,n){if(!m(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=>d(e)&&e.item===n),l<0)throw new Error("Node not found in parent for removal");n=t.items[l]}const i=t.items[l-1];let a=t.items[l+1];t.items.splice(l,1);let s=h(n.loc);a&&f(a)&&a.loc.start.line===n.loc.end.line&&(s=h({start:n.loc.start,end:a.loc.end}),a=t.items[l+1],t.items.splice(l,1));const p=i&&c(i)||a&&c(a),w=i&&i.loc.end.line===n.loc.start.line,y=a&&a.loc.start.line===n.loc.end.line,g=p&&(w||y),v={lines:-(s.lines-(g?1:0)),columns:g?-s.columns:0};if(void 0===i&&void 0===a&&(v.lines=0,v.columns=0),p&&w&&(v.columns-=2),p&&!i&&a&&(qe(t)||(v.columns-=2)),p&&i&&!a){const e=n.comma;i.comma=!!e}let b,T;i?(b=i,T=Ke(e)):(o(t)||r(t))&&"key"in t?(b=t.key,T=Ke(e)):(b=t,T=Fe(e));const $=Ke(e),k=T.get(b);k&&(v.lines+=k.lines,v.columns+=k.columns);const S=$.get(n);if(S&&(v.lines+=S.lines,v.columns+=S.columns),T.set(b,v),Oe.add(e),u(t)&&0!==v.lines&&m(e)&&e!==t){const t=n.loc.start.line,o=e.items,r=[];for(let e=0;e<o.length;e++){const n=o[e];if(!f(n))continue;const l=n.loc.start.line;l===t?r.push(e):l<t&&(n.loc.start.line-=v.lines,n.loc.end.line-=v.lines)}for(let e=r.length-1;e>=0;e--)o.splice(r[e],1)}}function We(e,t,n=!0){if(!n)return;if(!t.items.length)return;ze({lines:0,columns:1},Fe(e),t);const o=Te(t.items);ze({lines:0,columns:1},Ke(e),o),Oe.add(e)}function Be(e,t,n=!1){if(!n)return;if(!t.items.length)return;const o=Te(t.items);o.comma=!0,ze({lines:0,columns:1},Ke(e),o),Oe.add(e)}function Ze(t){if(!Oe.has(t))return;const n=Fe(t),o=Ke(t);let r=0;const l={};function i(e){let t=e.loc.start.line,n=e.loc.start.column;if("key"in e){const o=e.key.loc.end;(o.line>t||o.line===t&&o.column>n)&&(t=o.line,n=o.column)}for(let o=0;o<e.items.length;o++){const r=e.items[o].loc.end;(r.line>t||r.line===t&&r.column>n)&&(t=r.line,n=r.column)}e.loc.end={line:t,column:n}}function a(e){e.loc.start.line+=r;const t=l[e.loc.start.line]||0;e.loc.start.column+=t;const o=n.get(e);o&&(r+=o.lines,l[e.loc.start.line]=(l[e.loc.start.line]||0)+o.columns)}function s(e){e.loc.end.line+=r;const t=l[e.loc.end.line]||0;e.loc.end.column+=t;const n=o.get(e);n&&(r+=n.lines,l[e.loc.end.line]=(l[e.loc.end.line]||0)+n.columns)}!function t(n){switch(n.type){case e.Document:{const e=n;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.Table:{const e=n;a(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.TableArray:{const e=n;a(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.TableKey:{const e=n;a(e),t(e.item),s(e);break}case e.TableArrayKey:{const e=n;a(e),t(e.item),s(e);break}case e.KeyValue:{const e=n,i=e.loc.start.line+r,c=o.get(e.key);e.equals+=(l[i]||0)+(c?c.columns:0),a(e),t(e.key),t(e.value),s(e);break}case e.InlineArray:{const e=n;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e);break}case e.InlineTable:{const e=n;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e);break}case e.InlineItem:{const e=n;a(e),t(e.item),s(e);break}case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:a(n),s(n);break;default:throw new Error(`Unrecognized node type "${n.type}"`)}}(t),Oe.delete(t),De.delete(t),Le.delete(t)}function Ve(t,n,o={}){const{lines:r,columns:l}=n;if(0===r&&0===l)return t;const{first_line_only:i=!1}=o,a=t.loc.start.line,s=t.type;if(s===e.Key||s===e.String||s===e.Integer||s===e.Float||s===e.Boolean||s===e.DateTime||s===e.Comment)return i&&t.loc.start.line!==a||(t.loc.start.column+=l,t.loc.end.column+=l),t.loc.start.line+=r,t.loc.end.line+=r,t;if(s===e.KeyValue){const n=t,o=n.value.type;if(o===e.String||o===e.Integer||o===e.Float||o===e.Boolean||o===e.DateTime){i&&n.loc.start.line!==a||(n.loc.start.column+=l,n.loc.end.column+=l),n.loc.start.line+=r,n.loc.end.line+=r,n.equals+=l;const e=n.key;i&&e.loc.start.line!==a||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r;const o=n.value;return i&&o.loc.start.line!==a||(o.loc.start.column+=l,o.loc.end.column+=l),o.loc.start.line+=r,o.loc.end.line+=r,t}}const c=e=>{i&&e.loc.start.line!==a||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r};return function(t,n){function o(e,t){for(const n of e)r(n,t)}function r(t,l){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,l),i&&i.enter&&i.enter(t,l),t.type){case e.Document:o(t.items,t);break;case e.Table:r(t.key,t),o(t.items,t);break;case e.TableKey:r(t.item,t);break;case e.TableArray:r(t.key,t),o(t.items,t);break;case e.TableArrayKey:r(t.item,t);break;case e.KeyValue:r(t.key,t),r(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:r(t.item,t);break;case e.InlineTable:o(t.items,t);break;case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:break;default:throw new Error(`Unrecognized node type "${t.type}"`)}i&&i.exit&&i.exit(t,l)}Ee(t)?o(t,null):r(t,null)}(t,{[e.Table]:c,[e.TableKey]:c,[e.TableArray]:c,[e.TableArrayKey]:c,[e.KeyValue](e){c(e),e.equals+=l},[e.Key]:c,[e.String]:c,[e.Integer]:c,[e.Float]:c,[e.Boolean]:c,[e.DateTime]:c,[e.InlineArray]:c,[e.InlineItem]:c,[e.InlineTable]:c,[e.Comment]:c}),t}function qe(e){if(!e.items.length)return!1;return h(e.loc).lines>e.items.length}function ze(e,t,n,o){const r=t.get(o||n);r&&(e.lines+=r.lines,e.columns+=r.columns),t.set(n,e)}function Re(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Pe(t){const n=function(t){const n=Ge(t);return{type:e.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:e.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:t,raw:n}}}(t);return{type:e.Table,loc:g(n.loc),key:n,items:[]}}function He(t){const n=function(t){const n=Ge(t);return{type:e.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:e.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:t,raw:n}}}(t);return{type:e.TableArray,loc:g(n.loc),key:n,items:[]}}function Je(t,n){const o=function(t){const n=Ge(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:r}=o.loc.end,l=r+1;return Ve(n,{lines:0,columns:r+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:y(o.loc.start),end:y(n.loc.end)},key:o,equals:l,value:n}}const Ye=/^[\w-]+$/;function Ge(e){return e.map(e=>Ye.test(e)?e:JSON.stringify(e)).join(".")}function Qe(t,n){let o,r;if(n&&_e(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const r=e?"'''":'"""',l=n.includes("\r\n")?"\r\n":"\n",i=n.startsWith(`${r}${l}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let a;a=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()).replace(/"""/g,'""\\"'),o=i?`${r}${l}${a}${r}`:`${r}${a}${r}`}else o=JSON.stringify(t);if(o.includes("\r\n")||o.includes("\n")&&!o.includes("\r\n")){const e=o.includes("\r\n")?"\r\n":"\n",t=(o.match(new RegExp("\r\n"===e?"\\r\\n":"\\n","g"))||[]).length;r=t>0?{line:1+t,column:3}:{line:1,column:o.length}}else r={line:1,column:o.length};return{type:e.String,loc:{start:{line:1,column:0},end:r},raw:o,value:t}}function Xe(t){return{type:e.InlineItem,loc:g(t.loc),item:t,comma:!1}}const et=!1,tt=!0,nt=!1,ot=!1;function rt(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const o=t.split(/\r?\n/),r=e.start.line-1,l=e.end.line-1,i=e.start.column,a=e.end.column;let s="";if(r===l)s=(null===(n=o[r])||void 0===n?void 0:n.substring(i,a+1))||"";else{o[r]&&(s+=o[r].substring(i));for(let e=r+1;e<l;e++)s+="\n"+(o[e]||"");o[l]&&(s+="\n"+o[l].substring(0,a+1))}const c=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[1].length>0;return null}(e.loc,t);if(null!==n)return n}if(e.items&&Array.isArray(e.items))for(const n of e.items){const e=rt(n,t);if(null!==e)return e;if(n.item){const e=rt(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const o=rt(e[n],t);if(null!==o)return o}return null}function lt(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return it(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return it(e.items);if("KeyValue"===e.type&&e.value)return lt(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=lt(t);if(null!==e)return e}return null}function it(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function at(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function st(e,t){var n,o,r,l,i,a;if(e){if(e instanceof ct)return e;{const s=function(e){if(!e||"object"!=typeof e)return{};const t=e=>"boolean"==typeof e?null:"expected boolean, got "+typeof e,n={newLine:e=>"string"==typeof e?null:"expected string, got "+typeof e,trailingNewline:e=>"boolean"==typeof e||"number"==typeof e?null:"expected boolean or number, got "+typeof e,trailingComma:t,bracketSpacing:t,inlineTableStart:e=>null==e||"number"==typeof e&&Number.isInteger(e)&&e>=0?null:"expected non-negative integer or undefined, got "+typeof e,truncateZeroTimeInDates:t,useTabsForIndentation:t},o={},r=[],l=[];for(const t in e){const i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0;if(i){const n=e[t],r=i(n);r?l.push(`${t} (${r})`):o[t]=n}else Object.prototype.hasOwnProperty.call(e,t)&&r.push(t)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Object.keys(n).join(", ")}`),l.length>0)throw new TypeError(`Invalid types for format properties: ${l.join(", ")}`);return o}(e);return new ct(null!==(n=s.newLine)&&void 0!==n?n:t.newLine,null!==(o=s.trailingNewline)&&void 0!==o?o:t.trailingNewline,null!==(r=s.trailingComma)&&void 0!==r?r:t.trailingComma,null!==(l=s.bracketSpacing)&&void 0!==l?l:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(i=s.truncateZeroTimeInDates)&&void 0!==i?i:t.truncateZeroTimeInDates,null!==(a=s.useTabsForIndentation)&&void 0!==a?a:t.useTabsForIndentation)}}return t}class ct{constructor(e,t,n,o,r,l,i){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:et,this.bracketSpacing=null!=o?o:tt,this.inlineTableStart=null!=r?r:1,this.truncateZeroTimeInDates=null!=l?l:nt,this.useTabsForIndentation=null!=i?i:ot}static default(){return new ct("\n",1,et,tt,1,nt,ot)}static autoDetectFormat(e){const t=ct.default();t.newLine=at(e),t.trailingNewline=function(e,t){let n=0,o=e.length;for(;o>=t.length&&e.substring(o-t.length,o)===t;)n++,o-=t.length;return n}(e,t.newLine);try{const n=fe(e),o=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=lt(e);if(null!==t)return t}return et}(o),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=rt(t,e);if(null!==n)return n}return tt}(e,o)}catch(e){t.trailingComma=et,t.bracketSpacing=tt}return t.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,o=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&o++,n+o>=5))break;return n>o}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=nt,t}}function ut(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function ft(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function mt(e,t){if(0===t.inlineTableStart)return e;return e.items.filter(e=>{if(!l(e))return!1;const n=u(e.value),o=s(e.value)&&e.value.items.length>0&&e.value.items.every(e=>u(e.item));if(n||o){const n=pt(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1}).forEach(t=>{je(e,e,t),u(t.value)?Me(e,e,dt(t)):function(e){const t=Re();for(const n of e.value.items){const o=He(e.key.value);Me(t,t,o);for(const e of n.item.items)Me(t,o,e.item)}return Ze(t),t.items}(t).forEach(t=>{Me(e,e,t)})}),Ze(e),e}function dt(e){const t=Pe(e.key.value);for(const n of e.value.items)Me(t,t,n.item);return Ze(t),t}function ht(e){if(e.items.length>0){const t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function pt(e){return Math.max(0,e.length-1)}function wt(e,t,n){var o;for(let r=e.items.length-1;r>=0;r--){const i=e.items[r];if(l(i)&&u(i.value)){const r=[...e.key.item.value,...i.key.value];if(pt(r)<(null!==(o=n.inlineTableStart)&&void 0!==o?o:1)){const o=Pe(r);for(const e of i.value.items)Me(o,o,e.item);je(e,e,i),ht(e),t.push(o),wt(o,t,n)}}}}function yt(e,t=ct.default()){e=bt(e);const n=Re();for(const o of gt(e,t))Me(n,n,o);return Ze(n),mt(n,t),function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const o of e.items)if(l(o)&&u(o.value)){if(pt(o.key.value)<t.inlineTableStart){const r=dt(o);je(e,e,o),Me(e,e,r),wt(r,n,t)}}else("Table"===o.type||r(o))&&wt(o,n,t);for(const t of n)Me(e,e,t);Ze(e)}(n,t),function(e){let t=0,n=0;for(const o of e.items)0===n&&o.loc.start.line>1?t=1-o.loc.start.line:o.loc.start.line+t>n+2&&(t+=n+2-(o.loc.start.line+t)),Ve(o,{lines:t,columns:0}),n=o.loc.end.line;return e}(n)}function*gt(e,t){for(const n of Object.keys(e))yield Je([n],vt(e[n],t))}function vt(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?Qe(t):ke(t)?function(t){const n=t.toString();return{type:e.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"number"==typeof e&&(!ke(e)||!isFinite(e)||Object.is(e,-0))}(t)?function(t){let n;return n=t===1/0?"inf":t===-1/0?"-inf":Number.isNaN(t)?"nan":Object.is(t,-0)?"-0.0":t.toString(),{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):function(e){return"boolean"==typeof e}(t)?function(t){return{type:e.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:t?4:5}},value:t}}(t):Se(t)?function(t,n=!1){n&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new Z(t.toISOString().split("T")[0]));const o=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}(t,n.truncateZeroTimeInDates):Array.isArray(t)?function(t,n){const o={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){Me(o,o,Xe(vt(e,n)))}return We(o,o,n.bracketSpacing),Be(o,o,n.trailingComma),Ze(o),o}(t,n):function(t,n){if(t=bt(t),!Ie(t))return vt(t,n);const o={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of gt(t,n)){Me(o,o,Xe(e))}return We(o,o,n.bracketSpacing),Be(o,o,n.trailingComma),Ze(o),o}(t,n)}function bt(e){return e?Se(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const Tt=/(\r\n|\n)/g;function $t(t,n){const o=[];function r(t){switch(t.type){case e.Document:for(let e=0;e<t.items.length;e++)r(t.items[e]);break;case e.Table:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableKey:{const e=t,{start:n,end:l}=e.loc;St(o,n.line,n.column,"["),St(o,l.line,l.column-1,"]"),r(e.item);break}case e.TableArray:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableArrayKey:{const e=t,{start:n,end:l}=e.loc;It(o,n.line,n.column,n.column+2,"[["),It(o,l.line,l.column-2,l.column,"]]"),r(e.item);break}case e.KeyValue:{const e=t,n=e.loc.start.line;St(o,n,e.equals,"="),r(e.key),r(e.value);break}case e.Key:case e.String:case e.Integer:case e.Float:kt(o,t.loc,t.raw);break;case e.Boolean:kt(o,t.loc,t.value.toString());break;case e.DateTime:kt(o,t.loc,t.raw);break;case e.InlineArray:{const e=t,{start:n,end:l}=e.loc;St(o,n.line,n.column,"["),St(o,l.line,l.column-1,"]");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineTable:{const e=t,{start:n,end:l}=e.loc;St(o,n.line,n.column,"{"),St(o,l.line,l.column-1,"}");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineItem:{const e=t;if(r(e.item),e.comma){const t=e.loc.end;St(o,t.line,t.column,",")}break}case e.Comment:kt(o,t.loc,t.raw);break;default:{const e=t.type;throw new Error(`toTOML: Unrecognized node type: ${String(e)}`)}}}if(Ee(t))for(const e of t)r(e);else r(t);if(n.useTabsForIndentation)for(let e=0;e<o.length;e++){const t=o[e],n=t.match(/^( +)/);if(n){const r=n[1],l="\t".repeat(r.length);o[e]=l+t.substring(r.length)}}return o.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function kt(e,t,n){if(t.start.line===t.end.line){const o=Et(e,t.start.line),r=o.substring(0,t.start.column),l=r.length<t.start.column?r.padEnd(t.start.column,$):r,i=o.substring(t.end.column);return void(e[t.start.line-1]=l+n+i)}const o=n.split(Tt).filter(e=>"\n"!==e&&"\r\n"!==e),r=t.end.line-t.start.line+1;if(o.length!==r)throw new Error(`Mismatch between location and raw string, expected ${r} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){const r=Et(e,n),l=n===t.start.line,i=n===t.end.line;let a="";if(l){const e=r.substring(0,t.start.column);a=e.length<t.start.column?e.padEnd(t.start.column,$):e}const s=i?r.substring(t.end.column):"";e[n-1]=a+o[n-t.start.line]+s}}function St(e,t,n,o){const r=Et(e,t),l=r.length<n?r.padEnd(n,$):r.substring(0,n),i=r.substring(n+1);e[t-1]=l+o+i}function It(e,t,n,o,r){const l=Et(e,t),i=l.length<n?l.padEnd(n,$):l.substring(0,n),a=l.substring(o);e[t-1]=i+r+a}function Et(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function At(t,n,o){for(const r of t.items){const t=r.item;if(t.value.type===e.InlineTable){const e=n.concat(t.key.value);o.add(Lt(e)),At(t.value,e,o)}}}function Ct(t,n=""){const o=$e(),r=new Set,l=new Set,i=new Set,a=new Set,s=new Set;let c=o,u=[];const f={tables:r,table_arrays:l,defined:i,implicit_tables:a,inline_tables:s};for(const n of t)switch(n.type){case e.Table:m(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.TableArray:d(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.KeyValue:h(n)}return o;function m(e){const t=e.key.item.value;try{_t(o,[],t,e.type,f)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const l=Lt(t);r.add(l),i.add(l),c=Ot(o,t),u=t}function d(e){const t=e.key.item.value;try{_t(o,[],t,e.type,f)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const r=Lt(t);l.add(r),i.add(r),c=function(e,t){const n=Dt(e,t.slice(0,-1)),o=Te(t);n[o]||(n[o]=[]);const r=$e();return n[Te(t)].push(r),r}(o,t),u=t}function h(t){const o=t.key.value;try{_t(c,u,o,t.type,f)}catch(e){const o=e;throw new v(n,t.key.loc.start,o.message)}if(o.length>1)for(let e=1;e<o.length;e++){const t=Lt(u.concat(o.slice(0,e)));a.add(t),i.add(t)}let r;try{r=xt(t.value)}catch(e){const o=e;throw new v(n,t.value.loc.start,o.message)}if(t.value.type===e.InlineTable){const e=u.concat(o);s.add(Lt(e)),At(t.value,e,s)}(o.length>1?Ot(c,o.slice(0,-1)):c)[Te(o)]=r,i.add(Lt(u.concat(o)))}}function xt(t){switch(t.type){case e.InlineTable:const n=$e(),o=new Set,r=new Map;return t.items.forEach(({item:e})=>{const t=e.key.value,l=xt(e.value),i=Lt(t);if(o.has(i))throw new Error(`Duplicate key "${i}" in inline table`);for(let e=1;e<t.length;e++){const n=Lt(t.slice(0,e));if(o.has(n))throw new Error(`Key "${i}" conflicts with key: "${n}"`)}if(r.has(i)){const e=r.get(i);throw new Error(`Key "${i}" conflicts with key: "${e}"`)}o.add(i);for(let e=1;e<t.length;e++){const n=Lt(t.slice(0,e));r.has(n)||r.set(n,i)}(t.length>1?Ot(n,t.slice(0,-1)):n)[Te(t)]=l}),n;case e.InlineArray:return t.items.map(e=>xt(e.item));case e.DateTime:case e.String:case e.Integer:case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function _t(t,n,o,r,l){const i=n.length>0?Lt(n):"",a=new Array(o.length);let s=i;for(let e=0;e<o.length;e++)s=s?s+"."+o[e]:o[e],a[e]=s;const c=a[o.length-1];if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=a[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.inline_tables.has(c))throw new Error(`Cannot extend inline table at ${c}`);if(r===e.Table||r===e.TableArray)for(let e=1;e<o.length;e++){const t=a[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=a[e-1];if(l.table_arrays.has(t))throw new Error(`Cannot traverse Array of Tables at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.implicit_tables.has(c))throw new Error(`Implicit table already defined: ${c}`);if(r===e.KeyValue&&l.implicit_tables.has(c))throw new Error(`Table already defined: ${c}`);if(r===e.KeyValue&&o.length>1)for(let e=1;e<=o.length;e++){const t=a[e-1];if(l.tables.has(t))throw new Error(`Cannot extend explicit table ${t} with dotted keys`)}let u=0;for(const e of o){if(!Ae(t,e))return;if(Ft(t[e]))throw new Error(`Value already defined for ${a[u]}`);const n=a[u];if(Array.isArray(t[e])&&!l.table_arrays.has(n))throw new Error(`Cannot add to static array at ${n}`);const r=u++<o.length-1;t=Array.isArray(t[e])&&r?Te(t[e]):t[e]}const f=c;if(t&&r===e.Table&&l.defined.has(f))throw new Error(`Table already defined: ${f}`);if(t&&r===e.KeyValue&&1===o.length&&l.defined.has(f)&&!Ft(t))throw new Error(`Table already defined: ${f}`);if(t&&r===e.TableArray&&!l.table_arrays.has(f))throw new Error(`Cannot add Array of Tables to table at ${f}`)}function Ot(e,t){const n=Dt(e,t.slice(0,-1)),o=Te(t);return n[o]||(n[o]=$e()),n[o]}function Dt(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=$e()),Array.isArray(e[t])?Te(e[t]):e[t]),e)}function Ft(e){return"object"!=typeof e&&!Se(e)}function Lt(e){return e.join(".")}var Kt;function Ut(e){return e.type===Kt.Remove}function Mt(e,t,n=[]){return e===t||(r=t,Se(o=e)&&Se(r)&&o.toISOString()===r.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let o=[];const r=e.map(Ce),l=t.map(Ce);l.forEach((i,a)=>{const s=a>=r.length;if(!s&&r[a]===i)return;const c=r.indexOf(i,a+1);if(!s&&c>-1){o.push({type:Kt.Move,path:n,from:c,to:a});const e=r.splice(c,1);return void r.splice(a,0,...e)}const u=!l.includes(r[a]);if(!s&&u)return xe(o,Mt(e[a],t[a],n.concat(a))),void(r[a]=i);o.push({type:Kt.Add,path:n.concat(a)}),r.splice(a,0,i)});for(let e=l.length;e<r.length;e++)o.push({type:Kt.Remove,path:n.concat(e)});return o}(e,t,n):Ie(e)&&Ie(t)?function(e,t,n=[]){let o=[];const r=Object.keys(e),l=r.map(t=>Ce(e[t])),i=Object.keys(t),a=i.map(e=>Ce(t[e])),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=r[l.indexOf(e)];return!i.includes(n)};return r.forEach((r,c)=>{const u=n.concat(r);if(i.includes(r))xe(o,Mt(e[r],t[r],u));else if(s(l[c],a)){const e=i[a.indexOf(l[c])];o.push({type:Kt.Rename,path:n,from:r,to:e})}else o.push({type:Kt.Remove,path:u})}),i.forEach((e,t)=>{r.includes(e)||s(a[t],l)||o.push({type:Kt.Add,path:n.concat(e)})}),o}(e,t,n):[{type:Kt.Edit,path:n}];var o,r}function Nt(e,t){if(!t.length)return c(e)&&l(e.item)?e.item:e;if(l(e))return Nt(e.value,t);const n={};let i;if(m(e)&&e.items.some((e,a)=>{try{let s=[];if(l(e))s=e.key.value;else if(o(e))s=e.key.item.value;else if(r(e)){s=e.key.item.value;const t=Ce(s);n[t]||(n[t]=0);const o=n[t]++;s=s.concat(o)}else c(e)&&l(e.item)?s=e.item.key.value:c(e)&&(s=[a]);return!(!s.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}(s,t.slice(0,s.length)))&&(i=c(e)&&l(e.item)?t.length===s.length?e:Nt(e.item.value,t.slice(s.length)):c(e)&&t.length>s.length?Nt(e.item,t.slice(s.length)):Nt(e,t.slice(s.length)),!0)}catch(e){return!1}}),!i)throw new Error(`Node not found at ${t.join(".")}`);return i}function jt(e,t){try{return Nt(e,t)}catch(e){}}function Wt(e,t){let n,o=t;for(;o.length&&!n;)o=o.slice(0,-1),n=jt(e,o);if(!n)throw new Error(`Parent not found for ${t.join(".")}`);return n}function Bt(e,t,n){return Zt(fe(e),t,st(n,ct.autoDetectFormat(e))).tomlString}function Zt(t,i,a){const f=[...t];let h=1,p=0;for(const e of f){const t=e.loc.end;(t.line>h||t.line===h&&t.column>p)&&(h=t.line,p=t.column)}const w=Ct(f),y={type:e.Document,loc:{start:{line:1,column:0},end:{line:h,column:p}},items:f},g=yt(i,st(Object.assign(Object.assign({},a),{inlineTableStart:void 0}),a)),v=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Ut(n)){let o=t+1;for(;o<e.length;){const r=e[o];if(Ut(r)&&r.path[0]===n.path[0]&&r.path[1]>n.path[1]){e.splice(o,1),e.splice(t,0,r),t=-1;break}o++}}}return e}(Mt(w,i));if(0===v.length)return{tomlString:$t(f,a),document:y};const b=function(e,t,i,a){return i.forEach(i=>{if(function(e){return e.type===Kt.Add}(i)){const f=Nt(t,i.path),m=i.path.slice(0,-1);let d,h=Te(i.path),p=r(f);if(ke(h)&&!m.some(ke)){const t=jt(e,m.concat(0));t&&r(t)&&(p=!0)}if(o(f))d=e;else if(p){d=e;const t=e,n=jt(t,m.concat(h-1)),o=jt(t,m.concat(h));h=o?t.items.indexOf(o):n?t.items.indexOf(n)+1:t.items.length}else d=Wt(e,i.path),l(d)?d=d.value:c(d)&&l(d.item)&&(d=d.item.value);if(r(d)||s(d)||n(d)){if(s(d)){const e=ut(d);c(f)&&(f.comma=e)}if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&n(d)&&o(f)){const t=qt(f,e,a);Me(e,d,f,h);for(const n of t)Me(e,e,n,void 0)}else Me(e,d,f,h)}else if(u(d)){const t=ft(d);if(l(f)){const n=Xe(f);n.comma=t,Me(e,d,n)}else Me(e,d,f)}else if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&l(f)&&u(f.value)&&o(d)){pt([...d.key.item.value,...f.key.value])<a.inlineTableStart?function(e,t,n,o){const r=t.key.item.value,i=[...r,...e.key.value],a=Pe(i);if(u(e.value))for(const t of e.value.items)c(t)&&l(t.item)&&Me(n,a,t.item,void 0);Me(n,n,a,void 0),ht(t);const s=qt(a,n,o);for(const e of s)Me(n,n,e,void 0)}(f,d,e,a):Me(e,d,f)}else if(0===a.inlineTableStart&&l(f)&&u(f.value)&&n(d))Me(e,d,f,void 0,!0);else{let t=f;c(f)&&(o(d)||n(d))&&(t=f.item),Me(e,d,t)}}else if(function(e){return e.type===Kt.Edit}(i)){let n,o=Nt(e,i.path),r=Nt(t,i.path);if(l(o)&&l(r))Vt(o.value,r.value),n=o,o=o.value,r=r.value;else if(l(o)&&c(r)&&l(r.item))n=o,o=o.value,r=r.item.value;else if(c(o)&&l(o.item)&&l(r)){const e=o.item;Vt(e.value,r.value),n=e,o=e.value,r=r.value}else if(c(o)&&c(r)&&l(o.item)&&l(r.item))Vt(o.item.value,r.item.value),n=o.item,o=o.item.value,r=r.item.value;else if(n=Wt(e,i.path),l(n)){const t=i.path.slice(0,-1),o=Nt(e,t);l(o)&&s(o.value)&&(n=o.value)}Ue(e,n,o,r)}else if(Ut(i)){const t=jt(e,i.path);if(t){let n=Wt(e,i.path);l(n)&&(n=n.value),c(n)&&l(n.item)&&(n=n.item.value),m(n)&&!n.items.includes(t)&&(n=e),je(e,n,t)}else{if(jt(e,i.path.concat(0))){let t;for(;t=jt(e,i.path.concat(0));)je(e,e,t)}else Nt(e,i.path)}}else if(function(e){return e.type===Kt.Move}(i)){let t=jt(e,i.path);if(t){d(t)&&(t=t.item),l(t)&&(t=t.value);const n=t.items[i.from];je(e,t,n),Me(e,t,n,i.to)}else{const t=Nt(e,i.path.concat(i.from));je(e,e,t);const n=jt(e,i.path.concat(i.to)),o=n?e.items.indexOf(n):e.items.length;Me(e,e,t,o)}}else if(function(e){return e.type===Kt.Rename}(i)){let n=Nt(e,i.path.concat(i.from)),o=Nt(t,i.path.concat(i.to));d(n)&&(n=n.item),d(o)&&(o=o.item),Ue(e,n,n.key,o.key)}}),Ze(e),e}(y,g,v,a);return{tomlString:$t(b.items,a),document:b}}function Vt(e,t){if(i(e)&&i(t)&&_e(e.raw)){const n=Qe(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(a(e)&&a(t)){const n=e.raw,o=t.value,r=B.createDateWithOriginalFormat(o,n);t.value=r,t.raw=r.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(s(e)&&s(t)){const n=ut(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=ft(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function qt(e,t,n){const o=[],r=(e,o)=>{var i;for(let a=e.items.length-1;a>=0;a--){const s=e.items[a];if(l(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(pt(u)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Pe(u);for(const e of s.value.items)c(e)&&l(e.item)&&Me(t,n,e.item,void 0);e.items.splice(a,1),ht(e),o.push(n),r(n,o)}}}};return r(e,o),o}function zt(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(Kt||(Kt={}));class Rt{constructor(e){this._currentTomlString=e,this._ast=Array.from(fe(e)),this._format=ct.autoDetectFormat(e)}get toTomlString(){return this._currentTomlString}get toJsObject(){return Pt(Ct(this._ast))}get ast(){return this._ast}patch(e,t){const n=st(t,this._format),{tomlString:o,document:r}=Zt(this._ast,e,n);this._ast=r.items,this._currentTomlString=o}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(this._format.newLine),n=at(e),o=e.split(n);let r=0;for(;r<t.length&&r<o.length&&t[r]===o[r];)r++;let l=0;if(r<t.length&&r<o.length){const e=t[r],n=o[r];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){l=t;break}}let i=r+1;const{truncatedAst:a,lastEndPosition:s}=function(e,t,n){const o={line:t,column:n},r=[];let l=null;for(const t of e){const e=zt(t.loc.end,o)<0,n=zt(t.loc.start,o)<0;if(!e){if(n&&!e)break;break}r.push(t),l=t.loc.end}return{truncatedAst:r,lastEndPosition:l}}(this._ast,i,l),c=s?s.line:1,u=s?s.column+1:0,f=o.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const m=f.join(this._format.newLine);this._ast=Array.from(function*(e,t){for(const t of e)yield t;const n=new K(A(t));for(;!n.next().done;){const e=ve(n,t);for(const t of e)yield t}}(a,m)),this._currentTomlString=e,this._format=ct.autoDetectFormat(e)}overwrite(e){e!==this.toTomlString&&(this._ast=Array.from(fe(e)),this._currentTomlString=e,this._format=ct.autoDetectFormat(e))}}function Pt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Pt);if(e&&"object"==typeof e){const t={};for(const[n,o]of Object.entries(e))t[n]=Pt(o);return t}return e}function Ht(e){return Ct(fe(e),e)}function Jt(e,t){const n=st(t,ct.default());return $t(yt(e,n).items,n)}export{Rt as TomlDocument,ct as TomlFormat,Ht as parse,Bt as patch,Jt as stringify};
1
+ //! @decimalturn/toml-patch v1.1.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ var e,t;function n(t){return t.type===e.Document}function o(t){return t.type===e.Table}function r(t){return t.type===e.TableArray}function l(t){return t.type===e.KeyValue}function i(t){return t.type===e.String}function s(t){return t.type===e.DateTime}function a(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function m(e){return n(e)||o(e)||r(e)||u(e)||a(e)}function d(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function h(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function p(e,t){const n=Array.isArray(e)?e:g(e);if(0===n.length)return{line:1,column:t};let o=0,r=n.length-1;for(;o<r;){const e=o+r>>>1;n[e]<t?o=e+1:r=e}n[o]<t&&o++;const l=o+1;return{line:l,column:t-(n[l-2]+1||0)}}function g(e){const t=[];for(let n=0;n<e.length;n++){const o=e.charCodeAt(n);10===o?t.push(n):13===o&&(10===e.charCodeAt(n+1)?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function w(e){return{line:e.line,column:e.column}}function y(e){return{start:w(e.start),end:w(e.end)}}!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"}(e||(e={}));class v extends Error{constructor(e,t,n){let o=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=g(e),o=void 0!==n[t.line-2]?n[t.line-2]+1:0,r=n[t.line-1]||e.length;return e.substring(o,r)}(e,t),r=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(o+=`${n}\n${r}\n`)}o+=n,super(o),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"}(t||(t={}));const b=/^[\w-]+$/,$='"',T="'",k=" ",S=/[\w,\d,",',+,\-,_]/,I=10,E=13,A=127;function*C(e){const n=e.length;let o=0;const r=[],l=(e,t)=>({start:p(r,e),end:p(r,t)});for(;o<n;){const c=e.charCodeAt(o);if((c<=31||c===A)&&9!==c&&c!==E&&c!==I)throw new v(e,p(r,o),`Control char 0x${c.toString(16).toUpperCase().padStart(2,"0")} not allowed`);if(c===E&&(o+1>=n||e.charCodeAt(o+1)!==I))throw new v(e,p(r,o),"Standalone CR; must be CRLF or LF");if(32===c||9===c||c===E);else if(c===I)r.push(o);else if(91===c||93===c)yield{type:t.Bracket,raw:e[o],loc:l(o,o+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[o],loc:l(o,o+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:l(o,o+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:l(o,o+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:l(o,o+1)};else if(35===c)yield i();else{const t=x(e,o,T)||x(e,o,$);t?yield s(t):yield a()}o++}function i(){const i=o;for(;o+1<n;){const t=e.charCodeAt(o+1);if(t===I||t===E)break;o++;const n=e.charCodeAt(o);if((n<=31||n===A)&&9!==n)throw new v(e,p(r,o),`Control char 0x${n.toString(16).toUpperCase().padStart(2,"0")} not allowed`)}return{type:t.Comment,raw:e.slice(i,o+1),loc:l(i,o+1)}}function s(i){const s=o,a=i+i+i;for(o+=3;o<n;){if(x(e,o,i)){let t=3;for(;e[o+t]===i;)t++;if(t>=6)throw new v(e,p(r,o),`Invalid multiline string: ${t} consecutive ${i} characters`);if(3===t){o+=2;break}o+=t-3,o+=2;break}const t=e.charCodeAt(o);if(t===E&&(o+1>=n||e.charCodeAt(o+1)!==I))throw new v(e,p(r,o),"Standalone CR in multiline string; must be CRLF or LF");if((t<=31||t===A)&&9!==t&&t!==I&&t!==E){const n=i===$?"multiline basic strings":"multiline literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let s="";0===t?s="Null":t===A&&(s="DEL");const a=s?`${s} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),a)}t===I&&r.push(o),o++}if(o>=n){if(i===$){let t=0,l=n-1;for(;l>=0&&"\\"===e[l];)t++,l--;if(t>0&&t%2!=0)throw new v(e,p(r,o),`Unterminated multiline ${a} (possible escape issue)`)}throw new v(e,p(r,o),`Unterminated multiline ${a}`)}return{type:t.Literal,raw:e.slice(s,o+1),loc:l(s,o+1)}}function a(){const i=e[o];if(!S.test(i))throw new v(e,p(r,o),`Unexpected char "${i}"`);const s=o;let a=i===$,c=i===T;for(;o<n&&!(o+1>=n);){const t=e.charCodeAt(o+1);if(!(a||c||32!==t&&9!==t&&t!==I&&t!==E&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(o++,a||c){const t=e.charCodeAt(o);if((t<=31||t===A)&&9!==t){const n=a?"basic strings":"literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";t===I?i="Newline":t===E?i="Carriage return":0===t?i="Null":t===A&&(i="DEL");const s=i?`${i} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),s)}}const l=e[o];if(l===$&&(a=!a),l!==T||a||(c=!c),o+1>=n)break;if(a&&"\\"===l){const t=e[o+1];t!==$&&"\\"!==t||o++}}if(a||c)throw new v(e,p(r,s),`Expected close of string with ${a?$:T}`);return{type:t.Literal,raw:e.slice(s,o+1),loc:l(s,o+1)}}}function x(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===T)return n;let o=0,r=t-1;for(;r>=0&&"\\"===e[r];)o++,r--;if(0===o)return n;return!(o%2!=0)&&n}const _=new Int8Array(128);_.fill(-1);for(let e=0;e<10;e++)_[48+e]=e;for(let e=0;e<6;e++)_[65+e]=10+e,_[97+e]=10+e;function D(e){const t=e.charCodeAt(0);return t<128&&-1!==_[t]}function O(e,t){return _[e.charCodeAt(t)]<<12|_[e.charCodeAt(t+1)]<<8|_[e.charCodeAt(t+2)]<<4|_[e.charCodeAt(t+3)]}function F(e){return e.startsWith("'''")?N(e.slice(3,e.length-3)):e.startsWith(T)?e.slice(1,e.length-1):e.startsWith('"""')?L(N(e.slice(3,e.length-3)),!0):e.startsWith($)?L(e.slice(1,e.length-1),!1):e}function L(e,t){const n=e.length;if(!t&&-1===e.indexOf("\\"))return e;const o=[];let r=0;for(let l=0;l<n;l++){if("\\"!==e[l])continue;if(l>r&&o.push(e.slice(r,l)),l++,l>=n)throw new Error("Trailing backslash");const i=e[l];switch(i){case"b":o.push("\b");break;case"t":o.push("\t");break;case"n":o.push("\n");break;case"f":o.push("\f");break;case"r":o.push("\r");break;case'"':o.push('"');break;case"\\":o.push("\\");break;case"e":o.push("");break;case"u":{if(l+4>n||!D(e[l+1])||!D(e[l+2])||!D(e[l+3])||!D(e[l+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(l+1,l+5)}`);const t=O(e,l+1);if(t>=55296&&t<=57343)throw new Error(`Invalid \\u${e.slice(l+1,l+5)}: surrogates not allowed`);o.push(String.fromCharCode(t)),l+=4;break}case"U":{if(l+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);for(let t=1;t<=8;t++)if(!D(e[l+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);const t=parseInt(e.slice(l+1,l+9),16);o.push(String.fromCodePoint(t)),l+=8;break}case"x":{if(l+2>n||!D(e[l+1])||!D(e[l+2]))throw new Error(`Invalid hex escape: \\x${e.slice(l+1,l+3)}`);const t=_[e.charCodeAt(l+1)]<<4|_[e.charCodeAt(l+2)];o.push(String.fromCharCode(t)),l+=2;break}default:if(t&&("\n"===i||"\r"===i||" "===i||"\t"===i)){let t="\n"===i||"\r"===i,o=l;for(;o<n&&(" "===e[o]||"\t"===e[o]||"\n"===e[o]||"\r"===e[o]);)"\n"!==e[o]&&"\r"!==e[o]||(t=!0),o++;if(!t)throw new Error(`Invalid escape sequence: \\${i}`);l=o-1;break}throw new Error(`Invalid escape sequence: \\${i}`)}r=l+1}return 0===r?e:(r<n&&o.push(e.slice(r)),o.join(""))}function N(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class W{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 K();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?K():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const M=Object.freeze({value:void 0,done:!0});function K(){return M}function U(e){return{year:String(e.getUTCFullYear()).padStart(4,"0"),month:String(e.getUTCMonth()+1).padStart(2,"0"),day:String(e.getUTCDate()).padStart(2,"0"),hours:String(e.getUTCHours()).padStart(2,"0"),minutes:String(e.getUTCMinutes()).padStart(2,"0"),seconds:String(e.getUTCSeconds()).padStart(2,"0"),ms:e.getUTCMilliseconds()}}function B(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(".")){const o=t.match(n),r=o?o[1].length:3;return"."+String(e).padStart(3,"0").slice(0,r)}return e>0?"."+String(e).padStart(3,"0").replace(/0+$/,""):""}function j(e){if("Z"===e)return 0;const t="+"===e[0]?1:-1,[n,o]=e.slice(1).split(":");return t*(60*parseInt(n)+parseInt(o))}class Z{static createDateWithOriginalFormat(e,t){if(Z.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof R)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new q(t,!1)}const t=e.toISOString().split("T")[0];return new V(t)}if(Z.IS_TIME_ONLY.test(t)){if(e instanceof z)return e;{const n=U(e),o=B(n.ms,t);return new z(`${n.hours}:${n.minutes}:${n.seconds}${o}`,t)}}if(Z.IS_LOCAL_DATETIME_T.test(t)){const n=U(e),o=B(n.ms,t);return new q(`${n.year}-${n.month}-${n.day}T${n.hours}:${n.minutes}:${n.seconds}${o}`,!1,t)}if(Z.IS_LOCAL_DATETIME_SPACE.test(t)){const n=U(e),o=B(n.ms,t);return new q(`${n.year}-${n.month}-${n.day} ${n.hours}:${n.minutes}:${n.seconds}${o}`,!0,t)}if(Z.IS_OFFSET_DATETIME_T.test(t)||Z.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),o=n?"z"===n[1]?"Z":n[1]:"Z",r=Z.IS_OFFSET_DATETIME_SPACE.test(t),l=U(new Date(e.getTime()+6e4*j(o))),i=r?" ":"T",s=B(l.ms,t,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),a=`${l.year}-${l.month}-${l.day}${i}${l.hours}:${l.minutes}:${l.seconds}${s}${o}`;return new R(a,r)}return e}}Z.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,Z.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,Z.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,Z.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,Z.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,Z.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,Z.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,Z.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class V extends Date{constructor(e){super(e)}toISOString(){const e=U(this);return`${e.year}-${e.month}-${e.day}`}}class z extends Date{constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+":00"),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){const e=U(this);return`${e.hours}:${e.minutes}:${e.seconds}${B(e.ms,this.originalFormat)}`}}class q extends Date{constructor(e,t=!1,n){let o=e;/\d{2}:\d{2}:\d{2}/.test(e)||(o=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(o.replace(" ","T")+"Z"),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=U(this),t=this.useSpaceSeparator?" ":"T";return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${B(e.ms,this.originalFormat)}`}}class R extends Date{constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(n.replace(" ","T")),this.useSpaceSeparator=!1,this.useSpaceSeparator=t,this.originalFormat=e;const o=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);o&&(this.originalOffset="z"===o[1]?"Z":o[1])}toISOString(){if(this.originalOffset){const e=U(new Date(this.getTime()+6e4*j(this.originalOffset))),t=this.useSpaceSeparator?" ":"T",n=B(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const P=Z,H="true",J=/e/i,Y=/_/g,G=/^[+-]?inf$/,X=/^[+-]?nan$/,Q=/^[+-]?0x/i;function ee(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const te=/^[+-]?0o/i,ne=/^[+-]?0b/i;function oe(e,t,n){for(let o=0;o<e.length;o++)if(!ee(e.charCodeAt(o)))throw new v(t,{line:n.line,column:n.column+o},`Invalid bare key char '${e[o]}'`)}function re(e,t,n){if(e.startsWith('"""')||e.startsWith("'''"))throw new v(t,n,"Multiline strings cannot be keys")}function le(e,t,n){try{return F(e)}catch(e){throw new v(t,n,e.message)}}function ie(e,t,n,o=!0){if(e.endsWith("_"))throw new v(t,n,"Underscore must be between digits");if(o?/^[+-]?_/.test(e):e.startsWith("_"))throw new v(t,n,"Underscore must be between digits");if(/__/.test(e))throw new v(t,n,"Consecutive underscores not allowed")}function se(e,t,n,o){const r=e.replace(Y,"");if(/^[+-]?0\d/.test(r)&&!Q.test(e)&&!te.test(e)&&!ne.test(e))throw new v(t,n,`Leading zeros are not allowed in ${o}`)}function ae(e,t,n,o){if(/_[eE]/.test(e))throw new v(n,o,"Underscore before exponent is not allowed");if(/[eE][+-]?_/.test(e))throw new v(n,o,"Underscore at start of exponent is not allowed");if(/[eE][+-]?$/.test(e))throw new v(n,o,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new v(n,o,`Invalid float "${t}": decimal point not allowed in exponent`)}function ce(e,t,n,o,r,l){if(2!==e.length)throw new v(r,l,`"${o}": hour must be 2 digits`);if(2!==t.length)throw new v(r,l,`"${o}": minute must be 2 digits`);if(n&&2!==n.length)throw new v(r,l,`"${o}": second must be 2 digits`)}function ue(e,t,n,o,r,l){if(void 0!==e){const t=parseInt(e,10);if(t<0||t>23)throw new v(r,l,`"${o}": hour must be 00-23`)}if(void 0!==t){const e=parseInt(t,10);if(e<0||e>59)throw new v(r,l,`"${o}": minute must be 00-59`)}if(void 0!==n){const e=parseInt(n,10);if(e<0||e>60)throw new v(r,l,`"${o}": second must be 00-60`)}}function fe(e,t,n,o,r,l,i){const s=o[0]+o[1].toUpperCase();if(new RegExp("^[+\\-]?"+s.replace(/([[\]])/g,"\\$1")).test(e))throw new v(t,n,`${l} prefix must be lowercase "${o}"`);if(new RegExp("^[+\\-]?"+o+"_","i").test(e))throw new v(t,n,"Underscore must be between digits");const a=new RegExp("^[+\\-]?"+o,"i"),c=e.replace(a,"");if(!c||"_"===c||c.startsWith("_"))throw new v(t,n,`Incomplete ${l.toLowerCase()} number`);const u=c.replace(/_/g,"");if(!r.test(u))throw new v(t,n,null!=i?i:`Invalid ${l.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new v(t,n,`${l} numbers cannot have a sign prefix`)}function*me(e){const t=new W(C(e));for(;!t.next().done;){const n=be(t,e);for(const e of n)yield e}}function de(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function he(n,o){const r=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,l=r===e.Table;if(l&&"["!==n.value.raw)throw new v(o,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!l){const e=n.peek();if(e.done)throw new v(o,n.value.loc.start,'Expected "[[" for Array of Tables, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new v(o,n.value.loc.start,`Expected "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,r=e.value;if(t.loc.end.line!==r.loc.start.line||t.loc.end.column!==r.loc.start.column)throw new v(o,t.loc.start,'"[[" brackets must be adjacent (no whitespace)')}const i=l?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),r===e.TableArray&&n.next(),n.done)throw new v(o,i.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new v(o,n.value.loc.start,r===e.TableArray?"Array of Tables header [[]] requires a table name":"Table header [] requires a table name");const s=n.value.raw;re(s,o,n.value.loc.start);let a;for(s.startsWith('"')||s.startsWith("'")||oe(s,o,n.value.loc.start),a=[le(n.value.raw,o,n.value.loc.start)],i.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:a};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;t.startsWith('"')||t.startsWith("'")||oe(t,o,n.value.loc.start);const r=" ".repeat(e.loc.start.column-i.item.loc.end.column),l=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${r}.${l}${n.value.raw}`;try{i.item.value.push(F(n.value.raw))}catch(e){const t=e;throw new v(o,n.value.loc.start,t.message)}}if(n.next(),!n.done){const e=i.loc.start.line;if(n.value.loc.start.line!==e)throw new v(o,n.value.loc.start,l?"Table header must be single-line":"Array of Tables header must be single-line")}if(l&&(n.done||"]"!==n.value.raw))throw new v(o,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!l&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(o,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected "]]" closing, found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);if(!l){const e=n.value,t=n.peek().value;if(e.loc.end.line!==t.loc.start.line||e.loc.end.column!==t.loc.start.column)throw new v(o,e.loc.start,'"]]" brackets must be adjacent (no whitespace)')}if(l||n.next(),i.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===i.loc.end.line&&e.type!==t.Comment)throw new v(o,e.loc.start,`Extra content after ${l?"table":"Array of Tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=be(n,o);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:l?e.Table:e.TableArray,loc:{start:w(i.loc.start),end:c.length?w(c[c.length-1].loc.end):w(i.loc.end)},key:i,items:c}}function pe(t,n){const o=le(t.value.raw,n,t.value.loc.start);return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:o}}function ge(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===H}}function we(n,o){let r,l=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&P.IS_FULL_DATE.test(i)&&P.IS_FULL_TIME.test(n.peek().value.raw)){const e=l.start;n.next(),l={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=l.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fractional value for DateTime");n.next(),l={start:e,end:n.value.loc.end},i+=`.${n.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new v(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new v(t,n,`"${e}": offset needs HH:MM`);const o=/\d{2}:\d{2}/.test(e),r=o?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){const e=r[0],o=r[2],l=r[3],i=r[4];if(":"!==l)throw new v(t,n,`Offset "${e}": missing colon separator`);if(2!==o.length)throw new v(t,n,`Offset "${e}": hour must be 2 digits`);if(!i||0===i.length)throw new v(t,n,`Offset "${e}": minute required`);if(2!==i.length)throw new v(t,n,`Offset "${e}": minute must be 2 digits`);const s=parseInt(o,10);if(s<0||s>23)throw new v(t,n,`Offset "${e}": hour must be 00-23`);const a=parseInt(i,10);if(a<0||a>59)throw new v(t,n,`Offset "${e}": minute must be 00-59`)}const l=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!l.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new v(t,n,`"${e}": 'T' requires time component`);if(/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e))throw new v(t,n,`Invalid date "${e}": unexpected character after date`);if(/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e))throw new v(t,n,`"${e}": missing 'T' or space separator`);throw new v(t,n,`Invalid datetime "${e}"`)}const i=e.match(/^(\d+)-/);if(i&&4!==i[1].length)throw new v(t,n,`"${e}": year must be 4 digits`);const s=/^(\d+)-(\d+)-(\d+)/,a=e.match(s);if(a){const[,,o,r]=a;if(2!==o.length)throw new v(t,n,`"${e}": month must be 2 digits`);if(2!==r.length)throw new v(t,n,`"${e}": day must be 2 digits`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,o,r,l]=u;ce(o,r,l,e,t,n)}const f=/^(\d+):(\d+)(?::(\d+))?/,m=e.match(f);if(m&&!a){const[,o,r,l]=m;ce(o,r,l,e,t,n)}const d=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(d){const[,o,r,l,i,s,a]=d,c=parseInt(r,10);if(c<1||c>12)throw new v(t,n,`"${e}": month must be 01-12`);const u=parseInt(l,10);if(u<1||u>31)throw new v(t,n,`"${e}": day must be 01-31`);const f=function(e,t){const n=[31,28,31,30,31,30,31,31,30,31,30,31];if(2===t){return e%4==0&&e%100!=0||e%400==0?29:28}return n[t-1]}(parseInt(o,10),c);if(u>f)throw new v(t,n,`"${e}": day ${l} invalid for ${o}-${r}`);ue(i,s,a,e,t,n)}else if(h){const[,o,r,l]=h;ue(o,r,l,e,t,n)}}(i,o,l.start),P.IS_FULL_DATE.test(i))r=P.IS_DATE_ONLY.test(i)?new V(i):P.IS_LOCAL_DATETIME_T.test(i)?new q(i,!1):P.IS_LOCAL_DATETIME_SPACE.test(i)?new q(i,!0):P.IS_OFFSET_DATETIME_T.test(i)?new R(i,!1):P.IS_OFFSET_DATETIME_SPACE.test(i)?new R(i,!0):new Date(i.replace(" ","T"));else if(P.IS_TIME_ONLY.test(i))r=new z(i,i);else{const[e]=(new Date).toISOString().split("T");r=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:l,raw:i,value:r}}function ye(n,o){let r,l=n.value.loc,i=n.value.raw;if(G.test(i))r=i.startsWith("-")?-1/0:1/0;else if(X.test(i))r=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(ie(i,o,l.start),ae(i,i,o,l.start),!n.peek().done&&n.peek().value.type===t.Dot)throw new v(o,n.peek().value.loc.start,`Float "${i}.": dot after exponent`);se(i,o,l.start,"the integer part of a float"),r=Number(i.replace(Y,""))}else{const e=l.start;{if(J.test(i)&&!Q.test(i))throw new v(o,l.start,`Float "${i}": dot after exponent`);const e=i;se(e,o,l.start,"the integer part of a float");const t=e.replace(/^[+-]/,"");if(""===t||"_"===t)throw new v(o,l.start,"Float: digit required before dot");ie(e,o,l.start)}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,l={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new v(o,n.value.loc.start,`Float: fraction must start with digit, found "${e}"`);ie(e,o,n.value.loc.start,!1),ae(e,i,o,n.value.loc.start)}r=Number(i.replace(Y,""))}if(Number.isNaN(r)&&!X.test(i))throw new v(o,l.start,`Invalid float "${i}"`);return{type:e.Float,loc:l,raw:i,value:r}}function ve(t,n){const o=t.value.raw,r=t.value.loc;if(/^\d{1,}-\d{1,}/.test(o)||/^\d{1,}:\d{1,}/.test(o)||/^\d{6}-\d{2}$/.test(o))throw new v(n,r.start,`Invalid integer "${o}"`);if("-0"===o||"+0"===o)return{type:e.Integer,loc:r,raw:o,value:0};if(/^[+-]{2,}/.test(o))throw new v(n,r.start,"Double sign is not allowed in integers");se(o,n,r.start,"decimal integers"),ie(o,n,r.start);let l=10;Q.test(o)?(l=16,fe(o,n,r.start,"0x",/^[0-9a-fA-F]+$/,"Hexadecimal")):te.test(o)?(l=8,fe(o,n,r.start,"0o",/^[0-7]+$/,"Octal","Invalid octal digits (must be 0-7)")):ne.test(o)&&(l=2,fe(o,n,r.start,"0b",/^[01]+$/,"Binary","Invalid binary digits (must be 0 or 1)"));const i=parseInt(o.replace(Y,"").replace(te,"").replace(ne,""),l);if(Number.isNaN(i))throw new v(n,r.start,`Invalid integer "${o}"`);return{type:e.Integer,loc:r,raw:o,value:i}}function be(n,o){if(n.value.type===t.Comment)return[de(n)];if(n.value.type===t.Bracket)return[he(n,o)];if(n.value.type===t.Literal)return function(n,o){const r=n.value.raw;if(r.endsWith(":"))throw new v(o,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...r].length-1},"Use '=' to separate keys and values, not ':'");re(r,o,n.value.loc.start);r.startsWith('"')||r.startsWith("'")||oe(r,o,n.value.loc.start);let l;l=[le(n.value.raw,o,n.value.loc.start)];const i={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:l};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;re(e,o,n.value.loc.start);e.startsWith('"')||e.startsWith("'")||oe(e,o,n.value.loc.start),i.loc.end=n.value.loc.end,i.raw+=`.${n.value.raw}`,i.value.push(le(n.value.raw,o,n.value.loc.start))}if(n.next(),!n.done&&n.value.loc.start.line!==i.loc.end.line)throw new v(o,n.value.loc.start,'"=" must be on same line as key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new v(o,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new v(o,n.done?i.loc.end:n.value.loc.start,'Expected "=" for key-value')}const s=n.value.loc.start.column,a=n.value.loc.start.line;if(n.next(),n.done)throw new v(o,i.loc.start,"Expected value, reached EOF");if(n.value.loc.start.line!==a)throw new v(o,n.value.loc.start,"Value must be on same line as '='");if(n.done)throw new v(o,i.loc.start,"Expected value for key-value");const c=$e(n,o),u=c[0];if(!n.peek().done){const r=n.peek().value;if(r.type===t.Dot&&r.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new v(o,r.loc.start,"Invalid number: multiple decimal points not allowed");if((r.type===t.Literal||r.type===t.Bracket)&&r.loc.start.line===u.loc.end.line)throw new v(o,r.loc.start,"Key/value pairs must be separated by a newline")}return c[0]={type:e.KeyValue,key:i,value:u,loc:{start:w(i.loc.start),end:w(u.loc.end)},equals:s},c}(n,o);throw n.value.type===t.Equal?new v(o,n.value.loc.start,"Missing key before '='"):new v(o,n.value.loc.start,`Unexpected token "${n.value.type}"`)}function $e(n,o){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===$||e[0]===T?[pe(n,o)]:e===H||"false"===e?[ge(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[we(n,o)]:!n.peek().done&&n.peek().value.type===t.Dot||G.test(e)||X.test(e)||J.test(e)&&!Q.test(e)?[ye(n,o)]:[ve(n,o)]}if(n.value.type===t.Curly){const[r,l]=function(n,o){if("{"!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "{" for inline table');const r={type:e.InlineTable,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){l.push(de(n)),n.next();continue}if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in inline table");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in inline table");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const i=r.items[r.items.length-1];if(i&&!i.comma)throw new v(o,n.value.loc.start,"Missing comma between inline table items");const s=be(n,o),a=s[0];if(a.type===e.KeyValue){r.items.push({type:e.InlineItem,loc:y(a.loc),item:a,comma:!1});for(let e=1;e<s.length;e++)l.push(s[e])}n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "}"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}if(n.value.type===t.Bracket){const[r,l]=function(n,o){if("["!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "[" for inline array');const r={type:e.InlineArray,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in array");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in array");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)l.push(de(n));else{const t=r.items[r.items.length-1];if(t&&!t.comma)throw new v(o,n.value.loc.start,"Missing comma between array elements");const i=$e(n,o),s=i[0];r.items.push({type:e.InlineItem,loc:y(s.loc),item:s,comma:!1});for(let e=1;e<i.length;e++)l.push(i[e])}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "]"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}throw n.value.type===t.Dot?new v(o,n.value.loc.start,"Number cannot start with a dot"):new v(o,n.value.loc.start,"Unrecognized token type")}function Te(e){return e[e.length-1]}function ke(){return Object.create(null)}function Se(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function Ie(e){return"[object Date]"===Object.prototype.toString.call(e)}function Ee(e){return e&&"object"==typeof e&&!Ie(e)&&!Array.isArray(e)}function Ae(e){return null!=e&&"function"==typeof e[Symbol.iterator]}function Ce(e,t){return t in e}function xe(e){if(Ee(e)){return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${xe(e[t])}`).join(",")}}`}return Array.isArray(e)?`[${e.map(xe).join(",")}]`:JSON.stringify(e)}function _e(e,t){const n=e.length,o=t.length;e.length=n+o;for(let r=0;r<o;r++)e[n+r]=t[r]}const De=new WeakSet,Oe=new WeakMap,Fe=e=>(Oe.has(e)||Oe.set(e,new WeakMap),Oe.get(e)),Le=new WeakMap,Ne=e=>(Le.has(e)||Le.set(e,new WeakMap),Le.get(e));function We(e,t,n,o){if(m(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.items.splice(e,1,o)}else if(l(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.value.items.splice(e,1,o)}else if(d(t))t.item=o;else{if(!l(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=o:t.value=o}Ve(o,{lines:n.loc.start.line-o.loc.start.line,columns:n.loc.start.column-o.loc.start.column});const r=h(n.loc),i=h(o.loc);qe({lines:i.lines-r.lines,columns:i.columns-r.columns},Ne(e),o,n),De.add(e)}function Me(e,t,i,s,d){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,g;s=null!=s&&"number"==typeof s?s:t.items.length,a(t)||u(t)?({shift:p,offset:g}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const o=null!=n?e.items[n-1]:Te(e.items),r=null==n||n===e.items.length;e.items.splice(n,0,t);const l=!!o,i=!r;l&&(o.comma=!0);i&&(t.comma=!0);const s=ze(e),a=r&&!0===t.comma;return Ke(e,t,n,{useNewLine:s,hasCommaHandling:!0,isLastElement:r,hasSeparatingCommaBefore:l,hasSeparatingCommaAfter:i,hasTrailingComma:a})}(t,i,s)):d&&n(t)?({shift:p,offset:g}=function(e,t,n){const o=Ke(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),o}(t,i,s)):({shift:p,offset:g}=function(e,t,i){if(s=t,!(l(s)||o(s)||r(s)||f(s)))throw new Error(`Incompatible child type "${t.type}"`);var s;const a=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const u=a?{line:a.loc.end.line,column:f(a)?e.loc.start.column:a.loc.start.column}:w(e.loc.start),m=o(t)||r(t);let d=0;c||(d=m?2:1);u.line+=d;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},g=h(t.loc),y={lines:g.lines+(d-1),columns:g.columns};return{shift:p,offset:y}}(t,i,s)),Ve(i,p);const y=t.items[s-1],v=y&&Ne(e).get(y);if(v&&(g.lines+=v.lines,g.columns+=v.columns,Ne(e).delete(y)),u(t)&&0!==g.lines&&m(e)&&e!==t){const t=i.loc.start.line,n=e.items;for(let e=0;e<n.length;e++){const o=n[e];if(!f(o))continue;o.loc.start.line<t&&(o.loc.start.line-=g.lines,o.loc.end.line-=g.lines)}}Ne(e).set(i,g),De.add(e)}function Ke(e,t,n,o={}){const{useNewLine:r=!1,skipCommaSpace:l=2,skipBracketSpace:i=1,hasCommaHandling:s=!1,isLastElement:a=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:m=!1}=o,d=n>0?e.items[n-1]:void 0,p=d?{line:d.loc.end.line,column:r?f(d)?e.loc.start.column:d.loc.start.column:d.loc.end.column}:w(e.loc.start);let g=0;if(r)g=1;else{const e=c||!s&&!!d;e&&s?p.column+=l:(e||s&&!d)&&(p.column+=i)}p.line+=g;const y={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=h(t.loc);if(!s){return{shift:y,offset:{lines:v.lines+(g-1),columns:v.columns}}}let b=0;c&&m&&!u&&a&&(b=-1);return{shift:y,offset:{lines:v.lines+(g-1),columns:v.columns+(c||u?l:0)+(m?1+b:0)}}}function Ue(e,t,n){if(!m(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=>d(e)&&e.item===n),l<0)throw new Error("Node not found in parent for removal");n=t.items[l]}const i=t.items[l-1];let s=t.items[l+1];t.items.splice(l,1);let a=h(n.loc);s&&f(s)&&s.loc.start.line===n.loc.end.line&&(a=h({start:n.loc.start,end:s.loc.end}),s=t.items[l+1],t.items.splice(l,1));const p=i&&c(i)||s&&c(s),g=i&&i.loc.end.line===n.loc.start.line,w=s&&s.loc.start.line===n.loc.end.line,y=p&&(g||w),v={lines:-(a.lines-(y?1:0)),columns:y?-a.columns:0};if(void 0===i&&void 0===s&&(v.lines=0,v.columns=0),p&&g&&(v.columns-=2),p&&!i&&s&&(ze(t)||(v.columns-=2)),p&&i&&!s){const e=n.comma;i.comma=!!e}let b,$;i?(b=i,$=Ne(e)):(o(t)||r(t))&&"key"in t?(b=t.key,$=Ne(e)):(b=t,$=Fe(e));const T=Ne(e),k=$.get(b);k&&(v.lines+=k.lines,v.columns+=k.columns);const S=T.get(n);if(S&&(v.lines+=S.lines,v.columns+=S.columns),$.set(b,v),De.add(e),u(t)&&0!==v.lines&&m(e)&&e!==t){const t=n.loc.start.line,o=e.items,r=[];for(let e=0;e<o.length;e++){const n=o[e];if(!f(n))continue;const l=n.loc.start.line;l===t?r.push(e):l<t&&(n.loc.start.line-=v.lines,n.loc.end.line-=v.lines)}for(let e=r.length-1;e>=0;e--)o.splice(r[e],1)}}function Be(e,t,n=!0){if(!n)return;if(!t.items.length)return;qe({lines:0,columns:1},Fe(e),t);const o=Te(t.items);qe({lines:0,columns:1},Ne(e),o),De.add(e)}function je(e,t,n=!1){if(!n)return;if(!t.items.length)return;const o=Te(t.items);o.comma=!0,qe({lines:0,columns:1},Ne(e),o),De.add(e)}function Ze(t){if(!De.has(t))return;const n=Fe(t),o=Ne(t);let r=0;const l={};function i(e){let t=e.loc.start.line,n=e.loc.start.column;if("key"in e){const o=e.key.loc.end;(o.line>t||o.line===t&&o.column>n)&&(t=o.line,n=o.column)}for(let o=0;o<e.items.length;o++){const r=e.items[o].loc.end;(r.line>t||r.line===t&&r.column>n)&&(t=r.line,n=r.column)}e.loc.end={line:t,column:n}}function s(e){e.loc.start.line+=r;const t=l[e.loc.start.line]||0;e.loc.start.column+=t;const o=n.get(e);o&&(r+=o.lines,l[e.loc.start.line]=(l[e.loc.start.line]||0)+o.columns)}function a(e){e.loc.end.line+=r;const t=l[e.loc.end.line]||0;e.loc.end.column+=t;const n=o.get(e);n&&(r+=n.lines,l[e.loc.end.line]=(l[e.loc.end.line]||0)+n.columns)}!function t(n){switch(n.type){case e.Document:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.Table:{const e=n;s(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.TableArray:{const e=n;s(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.TableKey:{const e=n;s(e),t(e.item),a(e);break}case e.TableArrayKey:{const e=n;s(e),t(e.item),a(e);break}case e.KeyValue:{const e=n,i=e.loc.start.line+r,c=o.get(e.key);e.equals+=(l[i]||0)+(c?c.columns:0),s(e),t(e.key),t(e.value),a(e);break}case e.InlineArray:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e);break}case e.InlineTable:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e);break}case e.InlineItem:{const e=n;s(e),t(e.item),a(e);break}case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:s(n),a(n);break;default:throw new Error(`Unrecognized node type "${n.type}"`)}}(t),De.delete(t),Oe.delete(t),Le.delete(t)}function Ve(t,n,o={}){const{lines:r,columns:l}=n;if(0===r&&0===l)return t;const{first_line_only:i=!1}=o,s=t.loc.start.line,a=t.type;if(a===e.Key||a===e.String||a===e.Integer||a===e.Float||a===e.Boolean||a===e.DateTime||a===e.Comment)return i&&t.loc.start.line!==s||(t.loc.start.column+=l,t.loc.end.line===t.loc.start.line&&(t.loc.end.column+=l)),t.loc.start.line+=r,t.loc.end.line+=r,t;if(a===e.KeyValue){const n=t,o=n.value.type;if(o===e.String||o===e.Integer||o===e.Float||o===e.Boolean||o===e.DateTime){i&&n.loc.start.line!==s||(n.loc.start.column+=l,n.loc.end.column+=l),n.loc.start.line+=r,n.loc.end.line+=r,n.equals+=l;const e=n.key;i&&e.loc.start.line!==s||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r;const o=n.value;return i&&o.loc.start.line!==s||(o.loc.start.column+=l,o.loc.end.column+=l),o.loc.start.line+=r,o.loc.end.line+=r,t}}const c=e=>{i&&e.loc.start.line!==s||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r};return function(t,n){function o(e,t){for(const n of e)r(n,t)}function r(t,l){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,l),i&&i.enter&&i.enter(t,l),t.type){case e.Document:o(t.items,t);break;case e.Table:r(t.key,t),o(t.items,t);break;case e.TableKey:r(t.item,t);break;case e.TableArray:r(t.key,t),o(t.items,t);break;case e.TableArrayKey:r(t.item,t);break;case e.KeyValue:r(t.key,t),r(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:r(t.item,t);break;case e.InlineTable:o(t.items,t);break;case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:break;default:throw new Error(`Unrecognized node type "${t.type}"`)}i&&i.exit&&i.exit(t,l)}Ae(t)?o(t,null):r(t,null)}(t,{[e.Table]:c,[e.TableKey]:c,[e.TableArray]:c,[e.TableArrayKey]:c,[e.KeyValue](e){c(e),e.equals+=l},[e.Key]:c,[e.String]:c,[e.Integer]:c,[e.Float]:c,[e.Boolean]:c,[e.DateTime]:c,[e.InlineArray]:c,[e.InlineItem]:c,[e.InlineTable]:c,[e.Comment]:c}),t}function ze(e){if(!e.items.length)return!1;return h(e.loc).lines>e.items.length}function qe(e,t,n,o){const r=t.get(o||n);r&&(e.lines+=r.lines,e.columns+=r.columns),t.set(n,e)}function Re(e){switch(e){case"b":return"\b";case"t":return"\t";case"n":return"\n";case"f":return"\f";case"r":return"\r";case'"':return'"';case"\\":return"\\";default:return null}}function Pe(e,t){switch(e){case"\\":return"\\\\";case"\b":return"\\b";case"\t":return"\\t";case"\f":return"\\f";case'"':return"singleline-basic"===t?'\\"':'"';case"\n":return"singleline-basic"===t?"\\n":"\n";case"\r":return"singleline-basic"===t?"\\r":"\r";default:{const n=e.charCodeAt(0);return function(e,t){return"singleline-basic"===t?e<=31||127===e:e>=0&&e<=7||11===e||e>=14&&e<=31||127===e}(n,t)?`\\u${n.toString(16).padStart(4,"0").toUpperCase()}`:e}}}function He(e,t,n){const o=function(e){const t=new Map;for(let n=0;n<e.length;n++){if("\\"!==e[n])continue;const o=e[n+1];if(!o)continue;const r=Re(o);if(null===r){if("x"===o&&/^[0-9A-Fa-f]{2}$/.test(e.slice(n+2,n+4))){const o=e.slice(n,n+4),r=Number.parseInt(e.slice(n+2,n+4),16),l=String.fromCharCode(r);t.has(l)||t.set(l,o),n+=3;continue}if("u"===o&&/^[0-9A-Fa-f]{4}$/.test(e.slice(n+2,n+6))){const o=e.slice(n,n+6),r=Number.parseInt(e.slice(n+2,n+6),16),l=String.fromCodePoint(r);t.has(l)||t.set(l,o),n+=5;continue}if("U"===o&&/^[0-9A-Fa-f]{8}$/.test(e.slice(n+2,n+10))){const o=e.slice(n,n+10),r=Number.parseInt(e.slice(n+2,n+10),16),l=String.fromCodePoint(r);t.has(l)||t.set(l,o),n+=9;continue}}else"\n"===r||"\r"===r||t.has(r)||t.set(r,"\\"+o),n+=1}return t}(t);if(0===o.size&&"singleline-basic"===n){return JSON.stringify(e).slice(1,-1).replace(/\x7f/g,"\\u007F")}const r=function(e,t,n){let o="";for(const r of e){const e=t.get(r);o+=e||Pe(r,n)}return o}(e,o,n);return"multiline-basic"===n?r.replace(/"""/g,'""\\"'):r}function Je(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Ye(t){const n=function(t){const n=et(t);return{type:e.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:e.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:t,raw:n}}}(t);return{type:e.Table,loc:y(n.loc),key:n,items:[]}}function Ge(t){const n=function(t){const n=et(t);return{type:e.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:e.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:t,raw:n}}}(t);return{type:e.TableArray,loc:y(n.loc),key:n,items:[]}}function Xe(t,n){const o=function(t){const n=et(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:r}=o.loc.end,l=r+1;return Ve(n,{lines:0,columns:r+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:w(o.loc.start),end:w(n.loc.end)},key:o,equals:l,value:n}}function Qe(e){return JSON.stringify(e).replace(/\x7f/g,"\\u007f")}function et(e){return e.map(e=>b.test(e)?e:Qe(e)).join(".")}function tt(t,n){return n?function(t,n){if(o=n,o.startsWith('"')&&!o.startsWith('"""'))return nt(t,n);var o;if(function(e){return e.startsWith("'")&&!e.startsWith("'''")}(n)){if(!t.includes("'"))return function(t){const n=`'${t}'`;let o;if(n.includes("\n")){const e=n.split(/\r\n|\n/),t=e[e.length-1];o={line:e.length,column:t.length}}else o={line:1,column:n.length};return{type:e.String,loc:{start:{line:1,column:0},end:o},raw:n,value:t}}(t);if(!t.includes("'''")){return rt(t,`'''${n.slice(1,-1)}'''`)}return nt(t)}if(function(e){return e.startsWith("'''")}(n)){if(!t.includes("'''"))return rt(t,n);return ot(t,`"""${n.slice(3,-3)}"""`)}if(function(e){return e.startsWith('"""')}(n))return ot(t,n);throw new Error(`Existing raw string value is not valid: ${n}`)}(t,n):nt(t)}function nt(t,n){let o="";return o=n?`"${He(t,n,"singleline-basic")}"`:Qe(t),{type:e.String,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}function ot(t,n){const o=He(t,n,"multiline-basic");let r='"""'+(n.startsWith('"""\r\n')?"\r\n":n.startsWith('"""\n')?"\n":"")+o+'"""';const l=n.slice(3,-3);if(/(^|[^\\])(\\\\)*\\$/m.test(l)){const e=function(e,t){var n,o,r,l,i,s,a,c;const u=function(e){const t=e.match(/\r\n|\n/);return"\r\n"===(null==t?void 0:t[0])?"\r\n":"\n"}(e),f='"""';let m,d;(e=e.replace(/\r\n/g,"\n").replace(/\n/g,u)).startsWith(`${f}\\${u}`)?(m=4+u.length,d=`${f}\\${u}`):e.startsWith(`${f}${u}`)?(m=3+u.length,d=`${f}${u}`):(m=3,d=f);const h=e.length-3,p=e.slice(m,h).split(u),g=p[p.length-1],w=p.length>1&&/^[\t ]*$/.test(g),y=w?g:"",v=(w?p.slice(0,-1):p).map(e=>{var t,n;if(/^[\t ]*$/.test(e))return{indent:e,content:"",trailingWs:"",hasBackslash:!1,isBlank:!0};let o=e,r=0;for(let e=o.length-1;e>=0&&"\\"===o[e];e--)r++;const l=r%2==1;l&&(o=o.slice(0,-1));const i=null!==(n=null===(t=o.match(/^[\t ]*/))||void 0===t?void 0:t[0])&&void 0!==n?n:"",s=o.slice(i.length),a=s.match(/([\t ]+)$/),c=a?a[1]:"";return{indent:i,content:s.slice(0,s.length-c.length),trailingWs:c,hasBackslash:l,isBlank:!1}}),b=v.filter(e=>!e.isBlank),$=Math.max(...b.map(e=>e.content.length+e.trailingWs.length),1),T=b.filter(e=>e.hasBackslash),k=null!==(o=null!==(n=T[T.length-1])&&void 0!==n?n:b[b.length-1])&&void 0!==o?o:{indent:"",trailingWs:"",hasBackslash:!1,content:""},S=null!==(r=b[b.length-1])&&void 0!==r?r:k,I=[];{let e=[],t=0;for(const n of v)n.isBlank?e.push(n.indent):(t>0&&I.push(e),e=[],t++)}const E=b.some((e,t)=>!e.hasBackslash&&t<b.length-1),A=d===`${f}${u}`,C=A&&b.length>0&&null!==(i=null===(l=t.match(/^[\t ]*/))||void 0===l?void 0:l[0])&&void 0!==i?i:"",x=e=>{var t;const n=null!==(t=e.match(/\S+| +/g))&&void 0!==t?t:[],o=[];let r=0;for(;r<n.length;){let e=n[r++];for(;r<n.length&&" "===n[r][0];){const t=n[r],o=n[r+1];if(!o){r++;break}if(!(e.length+t.length+o.length<=$)){e+=t,r++;break}e+=t+o,r+=2}o.push(e)}return 0===o.length&&o.push(""),o},_=[],D=[],O=new Set,F=new Set,L=new Map;let N=!1;if(!E||!t.includes(u)||"\r\n"!==u&&t.includes("\r\n")){const e=t.replace(/\r\n/g,"\\r\\n").replace(/\n/g,"\\n").slice(C.length);if(e.length>0){if(" "===e[0])return null;if(e.length-e.trimEnd().length!==S.trailingWs.length)return null}if(!E){let t=0,n=0;for(let o=0;o<b.length-1;o++){const r=b[o];if(!r.hasBackslash)break;const l=r.content+r.trailingWs;if(e.slice(n,n+l.length)!==l)break;t++,n+=l.length}let o=0,r=0;for(let l=b.length-1;l>=t;l--){const t=b[l],i=t.content+t.trailingWs;if(0===i.length)break;const s=e.length-r-i.length;if(!(s>=n&&e.slice(s,s+i.length)===i))break;o++,r+=i.length}if(o>0){const l=e.slice(n,e.length-r);if(0===l.length||" "!==l[0]){for(let e=0;e<t;e++){const n=b[e];if(D.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}if(l.length>0){const e=x(l),n=e.join(""),r=/(?<!\\)\\n/.test(n);if(t>0&&!r){const e=t-1;if(e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}for(let n=0;n<e.length;n++){const o=e[n],i=t+n,s=i<b.length?b[i]:null,a=s?A&&0===i?C:s.indent:k.indent,c=o.length>0&&/\s$/.test(o)?"":l.endsWith(" ")?" ":"";if(D.push(`${a}${o}${c}\\`),n<e.length-1&&!r){const e=t+n;if(e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}}const i=b.length-o-1;if(!r&&i>=0&&i<I.length&&I[i].length>0)for(const e of I[i])D.push(e)}else if(t>0){const e=t-1;if(e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}const e=b.length-o;for(let t=e;t<b.length;t++){const n=b[t],o=t===b.length-1;if(t>e){const e=t-1;if(e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}D.push(o?`${n.indent}${n.content}${n.trailingWs}${n.hasBackslash&&""!==n.content?"\\":""}`:`${n.indent}${n.content}${n.trailingWs}\\`)}return!w||S.hasBackslash&&""===S.content?`${d}${D.join(u)}${f}`:`${d}${D.join(u)}${u}${y}${f}`}}const l=e.slice(n);if(t>0&&(n===e.length||l.length>0&&" "!==l[0])){for(let e=0;e<t;e++){const n=b[e];if(D.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}if(n===e.length){const e=b[t-1],n=S.hasBackslash&&""!==e.content?"\\":"";D[D.length-1]=`${e.indent}${e.content}${S.trailingWs}${n}`}else{const e=x(l),n=e.join(""),o=/(?<!\\)\\n/.test(n),r=t-1;if(!o&&r<I.length&&I[r].length>0)for(const e of I[r])D.push(e);for(let n=0;n<e.length;n++){const r=n===e.length-1,l=e[n],i=t+n,s=i<b.length?b[i]:null,a=s?A&&0===i?C:s.indent:r?S.indent:k.indent;let c,u;if(r?(c=S.trailingWs,u=S.hasBackslash&&""!==S.content?"\\":""):(c=l.length>0&&/\s$/.test(l)?"":" ",u="\\"),D.push(`${a}${l}${c}${u}`),!r){const e=t+n;if(!o&&e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}}}return!w||S.hasBackslash&&""===S.content?`${d}${D.join(u)}${f}`:`${d}${D.join(u)}${u}${y}${f}`}}const n=x(e);for(const e of n)_.push(e)}else{N=!0;const e=t.split(u),n=e[0].slice(C.length);if(n.length>0&&" "===n[0])return null;const o=e[e.length-1];if(o.length>0&&o.length-o.trimEnd().length!==S.trailingWs.length)return null;for(let t=0;t<e.length;t++){const n=e[t],o=0===t?n.slice(C.length):n,r=null!==(a=null===(s=o.match(/^[\t ]*/))||void 0===s?void 0:s[0])&&void 0!==a?a:"",l=x(o.slice(r.length)),i=_.length;F.add(i),t>0&&L.set(i,r);for(const e of l)_.push(e);t<e.length-1&&O.add(i+l.length-1)}}for(let e=0;e<_.length;e++){const t=e===_.length-1,n=O.has(e),o=t||n,r=e<b.length?b[e]:null,l=N&&F.has(e)&&e>0?null!==(c=L.get(e))&&void 0!==c?c:"":r?A&&0===e?C:r.indent:o?S.indent:k.indent,i=_[e];let s,a;if(o&&t?(s=S.trailingWs,a=S.hasBackslash&&""!==S.content?"\\":""):o?(s=S.trailingWs,a=""):(s=i.length>0&&/\s$/.test(i)?"":" ",a="\\"),D.push(`${l}${i}${s}${a}`),!t&&!n&&!N){const t=_.join("");if(!/(?<!\\)\\n/.test(t)&&e<I.length&&I[e].length>0)for(const t of I[e])D.push(t)}}return!w||S.hasBackslash&&""===S.content?`${d}${D.join(u)}${f}`:`${d}${D.join(u)}${u}${y}${f}`}(n,o);null!==e&&(r=e)}const i=lt(r);return{type:e.String,loc:{start:{line:1,column:0},end:i},raw:r,value:t}}function rt(t,n){const o="'''"+(n.startsWith("'''\r\n")?"\r\n":n.startsWith("'''\n")?"\n":"")+t+"'''",r=lt(o);return{type:e.String,loc:{start:{line:1,column:0},end:r},raw:o,value:t}}function lt(e){if(e.includes("\n")){const t=e.split(/\r\n|\n/),n=t[t.length-1];return{line:t.length,column:n.length}}return{line:1,column:e.length}}function it(t){const n=t.toString();return{type:e.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}function st(t,n=1){let o;if(t===1/0)o="inf";else if(t===-1/0)o="-inf";else if(Number.isNaN(t))o="nan";else if(Object.is(t,-0))o="-0."+"0".repeat(Math.max(n,1));else{o=t.toString();const e=o.search(/[eE]/);if(-1!==e){const t=o.slice(0,e),r=o.slice(e),l=t.indexOf(".");if(-1===l)o=`${t}.${"0".repeat(Math.max(n,1))}${r}`;else{const e=t.length-l-1;o=e<n?`${t}${"0".repeat(n-e)}${r}`:`${t}${r}`}}else{const e=o.indexOf(".");if(-1===e)o+="."+"0".repeat(Math.max(n,1));else{const t=o.length-e-1;t<n&&(o+="0".repeat(n-t))}}}return{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}function at(t){return{type:e.InlineItem,loc:y(t.loc),item:t,comma:!1}}const ct=!1,ut=!0,ft=!1,mt=!1;function dt(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const o=t.split(/\r?\n/),r=e.start.line-1,l=e.end.line-1,i=e.start.column,s=e.end.column;let a="";if(r===l)a=(null===(n=o[r])||void 0===n?void 0:n.substring(i,s+1))||"";else{o[r]&&(a+=o[r].substring(i));for(let e=r+1;e<l;e++)a+="\n"+(o[e]||"");o[l]&&(a+="\n"+o[l].substring(0,s+1))}const c=a.match(/^\[(\s*)/),u=a.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[1].length>0;return null}(e.loc,t);if(null!==n)return n}if(e.items&&Array.isArray(e.items))for(const n of e.items){const e=dt(n,t);if(null!==e)return e;if(n.item){const e=dt(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const o=dt(e[n],t);if(null!==o)return o}return null}function ht(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return pt(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return pt(e.items);if("KeyValue"===e.type&&e.value)return ht(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=ht(t);if(null!==e)return e}return null}function pt(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function gt(e){const t=e.indexOf("\n");return t>0&&"\r"===e[t-1]?"\r\n":"\n"}function wt(e,t){var n,o,r,l,i,s,a;if(e){if(e instanceof yt)return e;{const c=function(e){if(!e||"object"!=typeof e)return{};const t=e=>"boolean"==typeof e?null:"expected boolean, got "+typeof e,n={newLine:e=>"string"==typeof e?null:"expected string, got "+typeof e,trailingNewline:e=>"boolean"==typeof e||"number"==typeof e?null:"expected boolean or number, got "+typeof e,trailingComma:t,bracketSpacing:t,inlineTableStart:e=>null==e||"number"==typeof e&&Number.isInteger(e)&&e>=0?null:"expected non-negative integer or undefined, got "+typeof e,truncateZeroTimeInDates:t,useTabsForIndentation:t,minimumDecimals:e=>null==e||"number"==typeof e&&Number.isInteger(e)&&e>=0?null:"expected non-negative integer or undefined, got "+typeof e},o={},r=[],l=[];for(const t in e){const i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0;if(i){const n=e[t],r=i(n);r?l.push(`${t} (${r})`):o[t]=n}else Object.prototype.hasOwnProperty.call(e,t)&&r.push(t)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Object.keys(n).join(", ")}`),l.length>0)throw new TypeError(`Invalid types for format properties: ${l.join(", ")}`);return o}(e);return new yt(null!==(n=c.newLine)&&void 0!==n?n:t.newLine,null!==(o=c.trailingNewline)&&void 0!==o?o:t.trailingNewline,null!==(r=c.trailingComma)&&void 0!==r?r:t.trailingComma,null!==(l=c.bracketSpacing)&&void 0!==l?l:t.bracketSpacing,void 0!==c.inlineTableStart?c.inlineTableStart:t.inlineTableStart,null!==(i=c.truncateZeroTimeInDates)&&void 0!==i?i:t.truncateZeroTimeInDates,null!==(s=c.useTabsForIndentation)&&void 0!==s?s:t.useTabsForIndentation,null!==(a=c.minimumDecimals)&&void 0!==a?a:t.minimumDecimals)}}return t}class yt{constructor(e,t,n,o,r,l,i,s){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:ct,this.bracketSpacing=null!=o?o:ut,this.inlineTableStart=null!=r?r:1,this.truncateZeroTimeInDates=null!=l?l:ft,this.useTabsForIndentation=null!=i?i:mt,this.minimumDecimals=null!=s?s:0}static default(){return new yt("\n",1,ct,ut,1,ft,mt)}static autoDetectFormat(e){const t=yt.default();t.newLine=gt(e),t.trailingNewline=function(e){let t=0,n=e.length;for(;n>0&&"\n"===e[n-1];)t++,n--,n>0&&"\r"===e[n-1]&&n--;return t}(e);try{const n=me(e),o=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=ht(e);if(null!==t)return t}return ct}(o),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=dt(t,e);if(null!==n)return n}return ut}(e,o)}catch(e){t.trailingComma=ct,t.bracketSpacing=ut}return t.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,o=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&o++,n+o>=5))break;return n>o}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=ft,t.minimumDecimals=0,t}}function vt(e){if(!a(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function bt(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function $t(e,t){if(0===t.inlineTableStart)return e;return e.items.filter(e=>{if(!l(e))return!1;const n=u(e.value),o=a(e.value)&&e.value.items.length>0&&e.value.items.every(e=>u(e.item));if(n||o){const n=St(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1}).forEach(t=>{Ue(e,e,t),u(t.value)?Me(e,e,Tt(t)):function(e){const t=Je();for(const n of e.value.items){const o=Ge(e.key.value);Me(t,t,o);for(const e of n.item.items)Me(t,o,e.item)}return Ze(t),t.items}(t).forEach(t=>{Me(e,e,t)})}),Ze(e),e}function Tt(e){const t=Ye(e.key.value);for(const n of e.value.items)Me(t,t,n.item);return Ze(t),t}function kt(e){if(e.items.length>0){const t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function St(e){return Math.max(0,e.length-1)}function It(e,t,n){var o;for(let r=e.items.length-1;r>=0;r--){const i=e.items[r];if(l(i)&&u(i.value)){const r=[...e.key.item.value,...i.key.value];if(St(r)<(null!==(o=n.inlineTableStart)&&void 0!==o?o:1)){const o=Ye(r);for(const e of i.value.items)Me(o,o,e.item);Ue(e,e,i),kt(e),t.push(o),It(o,t,n)}}}}function Et(e,t=yt.default()){e=xt(e);const n=Je();for(const o of At(e,t))Me(n,n,o);return Ze(n),$t(n,t),function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const o of e.items)if(l(o)&&u(o.value)){if(St(o.key.value)<t.inlineTableStart){const r=Tt(o);Ue(e,e,o),Me(e,e,r),It(r,n,t)}}else("Table"===o.type||r(o))&&It(o,n,t);for(const t of n)Me(e,e,t);Ze(e)}(n,t),function(e){let t=0,n=0;for(const o of e.items)0===n&&o.loc.start.line>1?t=1-o.loc.start.line:o.loc.start.line+t>n+2&&(t+=n+2-(o.loc.start.line+t)),Ve(o,{lines:t,columns:0}),n=o.loc.end.line;return e}(n)}function*At(e,t){for(const n of Object.keys(e)){const o=e[n];if(void 0===o)continue;const r=xt(o);void 0!==r&&(yield Xe([n],Ct(r,t)))}}function Ct(t,n){var o;const r=null!==(o=n.minimumDecimals)&&void 0!==o?o:0;if(null===t)throw new Error('"null" values are not supported');if(void 0===t)throw new Error('"undefined" values are not supported inside arrays');return function(e){return"string"==typeof e}(t)?tt(t):function(e){return"bigint"==typeof e}(t)?it(t):Se(t)?r>0?st(t,r):it(t):function(e){return"number"==typeof e&&(!Se(e)||!isFinite(e)||Object.is(e,-0))}(t)?st(t,Math.max(r,1)):function(e){return"boolean"==typeof e}(t)?function(t){return{type:e.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:t?4:5}},value:t}}(t):Ie(t)?function(t,n=!1){n&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new V(t.toISOString().split("T")[0]));const o=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}(t,n.truncateZeroTimeInDates):Array.isArray(t)?function(t,n){const o={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){Me(o,o,at(Ct(e,n)))}return Be(o,o,n.bracketSpacing),je(o,o,n.trailingComma),Ze(o),o}(t,n):function(t,n){if(t=xt(t),!Ee(t))return Ct(t,n);const o={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of At(t,n)){Me(o,o,at(e))}return Be(o,o,n.bracketSpacing),je(o,o,n.trailingComma),Ze(o),o}(t,n)}function xt(e){return e?Ie(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const _t=/(\r\n|\n)/g;function Dt(t,n){const o=[];function r(t){switch(t.type){case e.Document:for(let e=0;e<t.items.length;e++)r(t.items[e]);break;case e.Table:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableKey:{const e=t,{start:n,end:l}=e.loc;Ft(o,n.line,n.column,"["),Ft(o,l.line,l.column-1,"]"),r(e.item);break}case e.TableArray:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableArrayKey:{const e=t,{start:n,end:l}=e.loc;Lt(o,n.line,n.column,n.column+2,"[["),Lt(o,l.line,l.column-2,l.column,"]]"),r(e.item);break}case e.KeyValue:{const e=t,n=e.loc.start.line;Ft(o,n,e.equals,"="),r(e.key),r(e.value);break}case e.Key:case e.String:case e.Integer:case e.Float:Ot(o,t.loc,t.raw);break;case e.Boolean:Ot(o,t.loc,t.value.toString());break;case e.DateTime:Ot(o,t.loc,t.raw);break;case e.InlineArray:{const e=t,{start:n,end:l}=e.loc;Ft(o,n.line,n.column,"["),Ft(o,l.line,l.column-1,"]");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineTable:{const e=t,{start:n,end:l}=e.loc;Ft(o,n.line,n.column,"{"),Ft(o,l.line,l.column-1,"}");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineItem:{const e=t;if(r(e.item),e.comma){const t=e.loc.end;Ft(o,t.line,t.column,",")}break}case e.Comment:Ot(o,t.loc,t.raw);break;default:{const e=t.type;throw new Error(`toTOML: Unrecognized node type: ${String(e)}`)}}}if(Ae(t))for(const e of t)r(e);else r(t);if(n.useTabsForIndentation)for(let e=0;e<o.length;e++){const t=o[e],n=t.match(/^( +)/);if(n){const r=n[1],l="\t".repeat(r.length);o[e]=l+t.substring(r.length)}}return o.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function Ot(e,t,n){if(t.start.line===t.end.line){const o=Nt(e,t.start.line),r=o.substring(0,t.start.column),l=r.length<t.start.column?r.padEnd(t.start.column,k):r,i=o.substring(t.end.column);return void(e[t.start.line-1]=l+n+i)}const o=n.split(_t).filter(e=>"\n"!==e&&"\r\n"!==e),r=t.end.line-t.start.line+1;if(o.length!==r)throw new Error(`Mismatch between location and raw string, expected ${r} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){const r=Nt(e,n),l=n===t.start.line,i=n===t.end.line;let s="";if(l){const e=r.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column,k):e}const a=i?r.substring(t.end.column):"";e[n-1]=s+o[n-t.start.line]+a}}function Ft(e,t,n,o){const r=Nt(e,t),l=r.length<n?r.padEnd(n,k):r.substring(0,n),i=r.substring(n+1);e[t-1]=l+o+i}function Lt(e,t,n,o,r){const l=Nt(e,t),i=l.length<n?l.padEnd(n,k):l.substring(0,n),s=l.substring(o);e[t-1]=i+r+s}function Nt(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function Wt(t,n,o){for(const r of t.items){const t=r.item;if(t.value.type===e.InlineTable){const e=n.concat(t.key.value);o.add(Vt(e)),Wt(t.value,e,o)}}}function Mt(t,n="",o="asNeeded"){const r=ke(),l=new Set,i=new Set,s=new Set,a=new Set,c=new Set;let u=r,f=[];const m={tables:l,table_arrays:i,defined:s,implicit_tables:a,inline_tables:c};for(const n of t)switch(n.type){case e.Table:d(n);for(const t of n.items)t.type===e.KeyValue&&p(t);break;case e.TableArray:h(n);for(const t of n.items)t.type===e.KeyValue&&p(t);break;case e.KeyValue:p(n)}return r;function d(e){const t=e.key.item.value;try{Ut(r,[],t,e.type,m)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const o=Vt(t);l.add(o),s.add(o),u=Bt(r,t),f=t}function h(e){const t=e.key.item.value;try{Ut(r,[],t,e.type,m)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const o=Vt(t);i.add(o),s.add(o),u=function(e,t){const n=jt(e,t.slice(0,-1)),o=Te(t);n[o]||(n[o]=[]);const r=ke();return n[Te(t)].push(r),r}(r,t),f=t}function p(t){const r=t.key.value;try{Ut(u,f,r,t.type,m)}catch(e){const o=e;throw new v(n,t.key.loc.start,o.message)}if(r.length>1)for(let e=1;e<r.length;e++){const t=Vt(f.concat(r.slice(0,e)));a.add(t),s.add(t)}let l;try{l=Kt(t.value,o)}catch(e){const o=e;throw new v(n,t.value.loc.start,o.message)}if(t.value.type===e.InlineTable){const e=f.concat(r);c.add(Vt(e)),Wt(t.value,e,c)}(r.length>1?Bt(u,r.slice(0,-1)):u)[Te(r)]=l,s.add(Vt(f.concat(r)))}}function Kt(t,n="asNeeded"){switch(t.type){case e.InlineTable:const o=ke(),r=new Set,l=new Map;return t.items.forEach(({item:e})=>{const t=e.key.value,i=Kt(e.value,n),s=Vt(t);if(r.has(s))throw new Error(`Duplicate key "${s}" in inline table`);for(let e=1;e<t.length;e++){const n=Vt(t.slice(0,e));if(r.has(n))throw new Error(`Key "${s}" conflicts with key: "${n}"`)}if(l.has(s)){const e=l.get(s);throw new Error(`Key "${s}" conflicts with key: "${e}"`)}r.add(s);for(let e=1;e<t.length;e++){const n=Vt(t.slice(0,e));l.has(n)||l.set(n,s)}(t.length>1?Bt(o,t.slice(0,-1)):o)[Te(t)]=i}),o;case e.InlineArray:return t.items.map(e=>Kt(e.item,n));case e.DateTime:case e.String:return t.value;case e.Integer:return function(e,t="asNeeded"){const n=e.replace(/_/g,"");let o,r=n;if(/^[+-]?0x/i.test(n)||/^[+-]?0o/i.test(n)||/^[+-]?0b/i.test(n)){const e="+"===n[0]||"-"===n[0]?n[0]:"";r=e+n.slice(e?1:0).toLowerCase()}try{o=BigInt(r)}catch(e){return Number(n)}return!0===t?o:!1===t||o>=BigInt(Number.MIN_SAFE_INTEGER)&&o<=BigInt(Number.MAX_SAFE_INTEGER)?Number(o):o}(t.raw,n);case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function Ut(t,n,o,r,l){const i=n.length>0?Vt(n):"",s=new Array(o.length);let a=i;for(let e=0;e<o.length;e++)a=a?a+"."+o[e]:o[e],s[e]=a;const c=s[o.length-1];if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.inline_tables.has(c))throw new Error(`Cannot extend inline table at ${c}`);if(r===e.Table||r===e.TableArray)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.table_arrays.has(t))throw new Error(`Cannot traverse Array of Tables at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.implicit_tables.has(c))throw new Error(`Implicit table already defined: ${c}`);if(r===e.KeyValue&&l.implicit_tables.has(c))throw new Error(`Table already defined: ${c}`);if(r===e.KeyValue&&o.length>1)for(let e=1;e<=o.length;e++){const t=s[e-1];if(l.tables.has(t))throw new Error(`Cannot extend explicit table ${t} with dotted keys`)}let u=0;for(const e of o){if(!Ce(t,e))return;if(Zt(t[e]))throw new Error(`Value already defined for ${s[u]}`);const n=s[u];if(Array.isArray(t[e])&&!l.table_arrays.has(n))throw new Error(`Cannot add to static array at ${n}`);const r=u++<o.length-1;t=Array.isArray(t[e])&&r?Te(t[e]):t[e]}const f=c;if(t&&r===e.Table&&l.defined.has(f))throw new Error(`Table already defined: ${f}`);if(t&&r===e.KeyValue&&1===o.length&&l.defined.has(f)&&!Zt(t))throw new Error(`Table already defined: ${f}`);if(t&&r===e.TableArray&&!l.table_arrays.has(f))throw new Error(`Cannot add Array of Tables to table at ${f}`)}function Bt(e,t){const n=jt(e,t.slice(0,-1)),o=Te(t);return n[o]||(n[o]=ke()),n[o]}function jt(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=ke()),Array.isArray(e[t])?Te(e[t]):e[t]),e)}function Zt(e){return"object"!=typeof e&&!Ie(e)}function Vt(e){return e.join(".")}var zt;function qt(e){return e.type===zt.Remove}function Rt(e,t,n=[]){return e===t||(r=t,Ie(o=e)&&Ie(r)&&o.toISOString()===r.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let o=[];const r=e.map(xe),l=t.map(xe);l.forEach((i,s)=>{const a=s>=r.length;if(!a&&r[s]===i)return;const c=r.indexOf(i,s+1);if(!a&&c>-1){o.push({type:zt.Move,path:n,from:c,to:s});const e=r.splice(c,1);return void r.splice(s,0,...e)}const u=!l.includes(r[s]);if(!a&&u)return _e(o,Rt(e[s],t[s],n.concat(s))),void(r[s]=i);o.push({type:zt.Add,path:n.concat(s)}),r.splice(s,0,i)});for(let e=l.length;e<r.length;e++)o.push({type:zt.Remove,path:n.concat(e)});return o}(e,t,n):Ee(e)&&Ee(t)?function(e,t,n=[]){let o=[];const r=Object.keys(e),l=r.map(t=>xe(e[t])),i=Object.keys(t),s=i.map(e=>xe(t[e])),a=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=r[l.indexOf(e)];return!i.includes(n)};return r.forEach((r,c)=>{const u=n.concat(r);if(i.includes(r))_e(o,Rt(e[r],t[r],u));else if(a(l[c],s)){const e=i[s.indexOf(l[c])];o.push({type:zt.Rename,path:n,from:r,to:e})}else o.push({type:zt.Remove,path:u})}),i.forEach((e,t)=>{r.includes(e)||a(s[t],l)||o.push({type:zt.Add,path:n.concat(e)})}),o}(e,t,n):[{type:zt.Edit,path:n}];var o,r}function Pt(e,t){if(!t.length)return c(e)&&l(e.item)?e.item:e;if(l(e))return Pt(e.value,t);const n={};let i;if(m(e)&&e.items.some((e,s)=>{try{let a=[];if(l(e))a=e.key.value;else if(o(e))a=e.key.item.value;else if(r(e)){a=e.key.item.value;const t=xe(a);n[t]||(n[t]=0);const o=n[t]++;a=a.concat(o)}else c(e)&&l(e.item)?a=e.item.key.value:c(e)&&(a=[s]);return!(!a.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}(a,t.slice(0,a.length)))&&(i=c(e)&&l(e.item)?t.length===a.length?e:Pt(e.item.value,t.slice(a.length)):c(e)&&t.length>a.length?Pt(e.item,t.slice(a.length)):Pt(e,t.slice(a.length)),!0)}catch(e){return!1}}),!i)throw new Error(`Node not found at ${t.join(".")}`);return i}function Ht(e,t){try{return Pt(e,t)}catch(e){}}function Jt(e,t){let n,o=t;for(;o.length&&!n;)o=o.slice(0,-1),n=Ht(e,o);if(!n)throw new Error(`Parent not found for ${t.join(".")}`);return n}function Yt(e,t,n){return Gt(me(e),t,wt(n,yt.autoDetectFormat(e))).tomlString}function Gt(t,i,s){const f=[...t];let h=1,p=0;for(const e of f){const t=e.loc.end;(t.line>h||t.line===h&&t.column>p)&&(h=t.line,p=t.column)}const g=Mt(f),w={type:e.Document,loc:{start:{line:1,column:0},end:{line:h,column:p}},items:f},y=Et(i,wt(Object.assign(Object.assign({},s),{inlineTableStart:void 0}),s)),v=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(qt(n)){let o=t+1;for(;o<e.length;){const r=e[o];if(qt(r)&&r.path[0]===n.path[0]&&r.path[1]>n.path[1]){e.splice(o,1),e.splice(t,0,r),t=-1;break}o++}}}return e}(Rt(g,Mt(y.items)));if(0===v.length)return{tomlString:Dt(f,s),document:w};const $=function(e,t,i,s){return i.forEach(i=>{if(function(e){return e.type===zt.Add}(i)){const f=Pt(t,i.path),m=i.path.slice(0,-1);let d,h=Te(i.path),p=r(f);if(Se(h)&&!m.some(Se)){const t=Ht(e,m.concat(0));t&&r(t)&&(p=!0)}if(o(f))d=e;else if(p){d=e;const t=e,n=Ht(t,m.concat(h-1)),o=Ht(t,m.concat(h));h=o?t.items.indexOf(o):n?t.items.indexOf(n)+1:t.items.length}else d=Jt(e,i.path),l(d)?d=d.value:c(d)&&l(d.item)&&(d=d.item.value);if(r(d)||a(d)||n(d)){if(a(d)){const e=vt(d);c(f)&&(f.comma=e)}if(void 0!==s.inlineTableStart&&s.inlineTableStart>0&&n(d)&&o(f)){const t=Qt(f,e,s);Me(e,d,f,h);for(const n of t)Me(e,e,n,void 0)}else Me(e,d,f,h)}else if(u(d)){const t=bt(d);if(l(f)){const n=at(f);n.comma=t,Me(e,d,n)}else Me(e,d,f)}else if(void 0!==s.inlineTableStart&&s.inlineTableStart>0&&l(f)&&u(f.value)&&o(d)){St([...d.key.item.value,...f.key.value])<s.inlineTableStart?function(e,t,n,o){const r=t.key.item.value,i=[...r,...e.key.value],s=Ye(i);if(u(e.value))for(const t of e.value.items)c(t)&&l(t.item)&&Me(n,s,t.item,void 0);Me(n,n,s,void 0),kt(t);const a=Qt(s,n,o);for(const e of a)Me(n,n,e,void 0)}(f,d,e,s):Me(e,d,f)}else if(0===s.inlineTableStart&&l(f)&&u(f.value)&&n(d))Me(e,d,f,void 0,!0);else{let t=f;c(f)&&(o(d)||n(d))&&(t=f.item),Me(e,d,t)}}else if(function(e){return e.type===zt.Edit}(i)){let n,o=Pt(e,i.path),r=Pt(t,i.path);if(l(o)&&l(r))Xt(o.value,r.value),n=o,o=o.value,r=r.value;else if(l(o)&&c(r)&&l(r.item))n=o,o=o.value,r=r.item.value;else if(c(o)&&l(o.item)&&l(r)){const e=o.item;Xt(e.value,r.value),n=e,o=e.value,r=r.value}else if(c(o)&&c(r)&&l(o.item)&&l(r.item))Xt(o.item.value,r.item.value),n=o.item,o=o.item.value,r=r.item.value;else if(n=Jt(e,i.path),l(n)){const t=i.path.slice(0,-1),o=Pt(e,t);l(o)&&a(o.value)&&(n=o.value)}We(e,n,o,r)}else if(qt(i)){const t=Ht(e,i.path);if(t){let n=Jt(e,i.path);l(n)&&(n=n.value),c(n)&&l(n.item)&&(n=n.item.value),c(n)&&u(n.item)&&(n=n.item),m(n)&&!n.items.includes(t)&&(n=e),Ue(e,n,t)}else{if(Ht(e,i.path.concat(0))){let t;for(;t=Ht(e,i.path.concat(0));)Ue(e,e,t)}else Pt(e,i.path)}}else if(function(e){return e.type===zt.Move}(i)){let t=Ht(e,i.path);if(t){d(t)&&(t=t.item),l(t)&&(t=t.value);const n=t.items[i.from];Ue(e,t,n),Me(e,t,n,i.to)}else{const t=Pt(e,i.path.concat(i.from));Ue(e,e,t);const n=Ht(e,i.path.concat(i.to)),o=n?e.items.indexOf(n):e.items.length;Me(e,e,t,o)}}else if(function(e){return e.type===zt.Rename}(i)){let n=Pt(e,i.path.concat(i.from)),o=Pt(t,i.path.concat(i.to));d(n)&&(n=n.item),d(o)&&(o=o.item),o.key.raw=(f=n.key.raw,o.key.value.map(e=>b.test(e)?e:`"${He(e,f,"singleline-basic")}"`).join(".")),o.key.loc.end.column=o.key.loc.start.column+o.key.raw.length,We(e,n,n.key,o.key)}var f}),Ze(e),e}(w,y,v,s);return{tomlString:Dt($.items,s),document:$}}function Xt(e,t){if(i(e)&&i(t)){const n=tt(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(s(e)&&s(t)){const n=e.raw,o=t.value,r=Z.createDateWithOriginalFormat(o,n);t.value=r,t.raw=r.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(a(e)&&a(t)){const n=vt(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=bt(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function Qt(e,t,n){const o=[],r=(e,o)=>{var i;for(let s=e.items.length-1;s>=0;s--){const a=e.items[s];if(l(a)&&u(a.value)){const u=[...e.key.item.value,...a.key.value];if(St(u)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Ye(u);for(const e of a.value.items)c(e)&&l(e.item)&&Me(t,n,e.item,void 0);e.items.splice(s,1),kt(e),o.push(n),r(n,o)}}}};return r(e,o),o}function en(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(zt||(zt={}));class tn{constructor(e,t){var n;const o="string"==typeof e?e:new TextDecoder("utf-8",{fatal:!0}).decode(e);this._currentTomlString=o,this._ast=Array.from(me(o)),this._integersAsBigInt=null!==(n=null==t?void 0:t.integersAsBigInt)&&void 0!==n?n:"asNeeded",this._format=yt.autoDetectFormat(o)}get toTomlString(){return this._currentTomlString}get toJsObject(){return nn(Mt(this._ast,this._currentTomlString,this._integersAsBigInt))}get ast(){return this._ast}patch(e,t){const n=wt(t,this._format),{tomlString:o,document:r}=Gt(this._ast,e,n);this._ast=r.items,this._currentTomlString=o}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(this._format.newLine),n=gt(e),o=e.split(n);let r=0;for(;r<t.length&&r<o.length&&t[r]===o[r];)r++;let l=0;if(r<t.length&&r<o.length){const e=t[r],n=o[r];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){l=t;break}}let i=r+1;const{truncatedAst:s,lastEndPosition:a}=function(e,t,n){const o={line:t,column:n},r=[];let l=null;for(const t of e){const e=en(t.loc.end,o)<0,n=en(t.loc.start,o)<0;if(!e){if(n&&!e)break;break}r.push(t),l=t.loc.end}return{truncatedAst:r,lastEndPosition:l}}(this._ast,i,l),c=a?a.line:1,u=a?a.column+1:0,f=o.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const m=f.join(this._format.newLine);this._ast=Array.from(function*(e,t){for(const t of e)yield t;const n=new W(C(t));for(;!n.next().done;){const e=be(n,t);for(const t of e)yield t}}(s,m)),this._currentTomlString=e,this._format=yt.autoDetectFormat(e)}overwrite(e){e!==this.toTomlString&&(this._ast=Array.from(me(e)),this._currentTomlString=e,this._format=yt.autoDetectFormat(e))}}function nn(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(nn);if(e&&"object"==typeof e){const t={};for(const[n,o]of Object.entries(e))t[n]=nn(o);return t}return e}function on(e,t){var n;const o="string"==typeof e?e:new TextDecoder("utf-8",{fatal:!0}).decode(e);return Mt(me(o),o,null!==(n=null==t?void 0:t.integersAsBigInt)&&void 0!==n?n:"asNeeded")}function rn(e,t){const n=wt(t,yt.default());return Dt(Et(e,n).items,n)}export{V as LocalDate,q as LocalDateTime,z as LocalTime,R as OffsetDateTime,tn as TomlDocument,yt as TomlFormat,on as parse,Yt as patch,rn as stringify};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "contributors": [
5
5
  "Tim Hall <tim.hall.engr@gmail.com>",
6
6
  "Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
@@ -34,7 +34,8 @@
34
34
  }
35
35
  },
36
36
  "devDependencies": {
37
- "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.5",
37
+ "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.7",
38
+ "@playwright/test": "^1.59.1",
38
39
  "@rollup/plugin-terser": "^1.0.0",
39
40
  "@rollup/plugin-typescript": "^12.1.2",
40
41
  "@types/dedent": "^0.7.2",
@@ -47,7 +48,7 @@
47
48
  "jest": "^30.0.0",
48
49
  "js-yaml": "^4.0.0",
49
50
  "mri": "^1",
50
- "nano-staged": "^0.9.0",
51
+ "nano-staged": "^1.0.0",
51
52
  "npm-run-all2": "^8.0.0",
52
53
  "oxlint": "^1.55.0",
53
54
  "rimraf": "^6.0.0",
@@ -56,7 +57,7 @@
56
57
  "rollup-plugin-filesize": "^10",
57
58
  "ts-jest": "^29",
58
59
  "tslib": "^2.0.0",
59
- "typescript": "5.9"
60
+ "typescript": "6.0.2"
60
61
  },
61
62
  "prettier": {
62
63
  "singleQuote": true,
@@ -69,19 +70,30 @@
69
70
  "dist/",
70
71
  "CHANGELOG.md"
71
72
  ],
73
+ "json-comments": {
74
+ "tips": "Please install the JsonComments plugin to enable commenting functionality for JSON files, see: https://github.com/zhangfisher/json_comments_extension",
75
+ "package.json": {
76
+ "pnpm.overrides.lodash": "Override needed to avoid vuln detailed in https://github.com/DecimalTurn/toml-patch/security/dependabot/44",
77
+ "pnpm.overrides.serialize-javascript": "https://github.com/DecimalTurn/toml-patch/security/dependabot/40"
78
+ }
79
+ },
72
80
  "scripts": {
73
81
  "dev": "pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs",
74
82
  "test": "jest --config jest.config.json",
75
- "test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.mjs",
76
- "test:all": "pnpm run test && pnpm run test:js",
83
+ "test:go": "./run-toml-test.bash",
84
+ "test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.js.config.mjs",
85
+ "test:playwright": "playwright test",
86
+ "playwright:install": "playwright install --with-deps chromium",
87
+ "test:all": "pnpm run test && pnpm run test:js && pnpm run test:playwright",
77
88
  "typecheck": "tsc",
78
- "specs": "jest --config specs.config.cjs",
89
+ "specs": "jest --config jest.specs.config.cjs",
79
90
  "benchmark": "npm-run-all2 bench:*",
80
91
  "benchmark:ci": "npm-run-all2 \"bench:* -- --sample --versions latest\"",
81
92
  "bench:parse": "node benchmark/parse-benchmark.mjs",
82
93
  "bench:stringify": "node benchmark/stringify-benchmark.mjs",
83
94
  "profile": "node benchmark/profile.mjs",
84
95
  "build": "rimraf dist && rollup -c",
96
+ "build:demo": "node scripts/build-demo.mjs",
85
97
  "lint": "oxlint",
86
98
  "lint:fix": "oxlint --fix"
87
99
  }