@decimalturn/toml-patch 3.3.1 → 3.3.2-lite
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/dist/patch.d.ts +18 -0
- package/dist/patch.js +20 -0
- package/package.json +14 -106
- package/LICENSE +0 -22
- package/README.md +0 -203
- package/dist/toml-patch.d.ts +0 -564
- package/dist/toml-patch.js +0 -84
package/dist/toml-patch.d.ts
DELETED
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/toml-format.d.ts
|
|
3
|
-
type MultilineContainerMode = boolean | number | 'auto' | 'parent';
|
|
4
|
-
export declare class TomlFormat {
|
|
5
|
-
/**
|
|
6
|
-
* The line ending character(s) to use in the output TOML.
|
|
7
|
-
* This option affects only the stringification process, not the internal representation (CST).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* - '\n' for Unix/Linux line endings
|
|
11
|
-
* - '\r\n' for Windows line endings
|
|
12
|
-
*/
|
|
13
|
-
newLine: string;
|
|
14
|
-
/**
|
|
15
|
-
* The number of trailing newlines to add at the end of the TOML document.
|
|
16
|
-
* This option affects only the stringification process, not the internal representation (CST).
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* - 0: No trailing newline
|
|
20
|
-
* - 1: One trailing newline (standard)
|
|
21
|
-
* - 2: Two trailing newlines (adds extra spacing)
|
|
22
|
-
*/
|
|
23
|
-
trailingNewline: number;
|
|
24
|
-
/**
|
|
25
|
-
* Whether to add trailing commas after the last element in arrays and inline tables.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* - true: [1, 2, 3,] and { x = 1, y = 2, }
|
|
29
|
-
* - false: [1, 2, 3] and { x = 1, y = 2 }
|
|
30
|
-
*/
|
|
31
|
-
trailingComma: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Whether to add spaces after opening brackets/braces and before closing brackets/braces
|
|
34
|
-
* in arrays and inline tables.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* - true: [ 1, 2, 3 ] and { x = 1, y = 2 }
|
|
38
|
-
* - false: [1, 2, 3] and {x = 1, y = 2}
|
|
39
|
-
*/
|
|
40
|
-
bracketSpacing: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Whether the output should include a leading UTF-8 BOM marker (U+FEFF).
|
|
43
|
-
*
|
|
44
|
-
* This is auto-detected from the source TOML and preserved during patching.
|
|
45
|
-
*/
|
|
46
|
-
leadingBom: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* The nesting depth at which new tables should start being formatted as inline tables.
|
|
49
|
-
* When adding new tables during patching or stringifying objects:
|
|
50
|
-
* - Tables at depth >= inlineTableStart will be formatted as inline tables
|
|
51
|
-
* - Tables at depth < inlineTableStart will be formatted as separate table sections
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* - 0: All tables are inline tables including top-level tables (root level)
|
|
55
|
-
* - 1: Top-level tables as sections, nested tables as inline (default)
|
|
56
|
-
* - 2: Two levels as sections, deeper nesting as inline
|
|
57
|
-
*/
|
|
58
|
-
inlineTableStart?: number;
|
|
59
|
-
/**
|
|
60
|
-
* Whether to truncate time components in UTC date fields when they are zero.
|
|
61
|
-
* This setting affects only the stringification process.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* - true: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15
|
|
65
|
-
* - false: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15T00:00:00.000Z
|
|
66
|
-
*
|
|
67
|
-
*/
|
|
68
|
-
truncateZeroTimeInDates?: boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Whether to use tabs instead of spaces for indentation/padding.
|
|
71
|
-
* When enabled, lines that need to be indented will use tabs.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* - true: Uses tabs for indentation
|
|
75
|
-
* - false: Uses spaces for indentation (default)
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
useTabsForIndentation?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* The number of columns used for one indentation level in generated multiline values.
|
|
81
|
-
* This is auto-detected when patching and defaults to two columns.
|
|
82
|
-
*/
|
|
83
|
-
indentWidth: number;
|
|
84
|
-
/**
|
|
85
|
-
* The minimum number of decimal places to use when serializing JS numbers as TOML floats.
|
|
86
|
-
* When greater than 0, plain JS integer values are serialized as TOML floats padded with
|
|
87
|
-
* zeros to reach the specified decimal count. BigInt values are always serialized as integers
|
|
88
|
-
* regardless of this setting.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* - 0: stringify({ x: 1, y: 1.5 }) → x = 1 / y = 1.5 (default)
|
|
92
|
-
* - 1: stringify({ x: 1, y: 1.5 }) → x = 1.0 / y = 1.5
|
|
93
|
-
* - 2: stringify({ x: 1, y: 1.5 }) → x = 1.00 / y = 1.50
|
|
94
|
-
*/
|
|
95
|
-
minimumDecimals?: number;
|
|
96
|
-
/**
|
|
97
|
-
* The minimum number of fractional-second digits to write for date/time values.
|
|
98
|
-
*
|
|
99
|
-
* When greater than 0, a time or datetime is padded with zeros to reach the specified digit
|
|
100
|
-
* count, and a time written as `HH:MM` gains `:00` before its fraction. Digits already written
|
|
101
|
-
* are never removed, so a value with more digits keeps them, and a date-only value is
|
|
102
|
-
* unaffected because it carries no time. This is separate from `minimumDecimals`, which
|
|
103
|
-
* applies to numbers, so the two can be set independently.
|
|
104
|
-
*
|
|
105
|
-
* Not auto-detectable — caller must set explicitly.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* - 0: t = 07:32:00 (default)
|
|
109
|
-
* - 3: t = 07:32:00.000
|
|
110
|
-
*/
|
|
111
|
-
minimumTimeDecimals?: number;
|
|
112
|
-
/**
|
|
113
|
-
* Whether `patch()` should reorder root key-values, `[table]`/`[[array]]` section blocks,
|
|
114
|
-
* and rows inside table bodies to match the key order of the JS object passed to `patch()`,
|
|
115
|
-
* carrying each entry's owned comments along with it (see docs/CommentOwnership.md).
|
|
116
|
-
*
|
|
117
|
-
* Off by default: with the option unset or `false`, `patch()` only ever changes values that
|
|
118
|
-
* actually differ between the existing document and the updated object, preserving the
|
|
119
|
-
* existing document's order even when the JS object's key order differs.
|
|
120
|
-
*
|
|
121
|
-
* Not auto-detectable — the existing document's order says nothing about the caller's
|
|
122
|
-
* intent, so `autoDetectFormatWithCst` always resolves this to `false`.
|
|
123
|
-
*
|
|
124
|
-
* See docs/PLAN-Update-Order.md for the full behavior and current scope limitations.
|
|
125
|
-
*/
|
|
126
|
-
updateOrder?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Whether newly generated inline tables should use multiline layout.
|
|
129
|
-
*
|
|
130
|
-
* `true` and `false` select a layout directly. A non-negative integer selects
|
|
131
|
-
* multiline layout at that structural container depth or deeper. `'auto'`
|
|
132
|
-
* keeps new containers compact and `'parent'` follows the immediate parent.
|
|
133
|
-
*/
|
|
134
|
-
multilineTable: MultilineContainerMode;
|
|
135
|
-
/**
|
|
136
|
-
* Whether newly generated inline arrays should use multiline layout.
|
|
137
|
-
*
|
|
138
|
-
* `true` and `false` select a layout directly. A non-negative integer selects
|
|
139
|
-
* multiline layout at that structural container depth or deeper. `'auto'`
|
|
140
|
-
* keeps new containers compact and `'parent'` follows the immediate parent.
|
|
141
|
-
*/
|
|
142
|
-
multilineArray: MultilineContainerMode;
|
|
143
|
-
/**
|
|
144
|
-
* Whether to write `\uXXXX` / `\UXXXXXXXX` / `\xHH` escape sequences with
|
|
145
|
-
* uppercase hex digits. Auto-detected from the first hex escape sequence in
|
|
146
|
-
* the document during patching; defaults to `true` (uppercase hex).
|
|
147
|
-
*/
|
|
148
|
-
escapeSequenceUpperCase: boolean;
|
|
149
|
-
constructor(newLine?: string, trailingNewline?: number, trailingComma?: boolean, bracketSpacing?: boolean, inlineTableStart?: number, truncateZeroTimeInDates?: boolean, useTabsForIndentation?: boolean, minimumDecimals?: number, leadingBom?: boolean, updateOrder?: boolean, indentWidth?: number, multilineTable?: MultilineContainerMode | null, multilineArray?: MultilineContainerMode | null, escapeSequenceUpperCase?: boolean, minimumTimeDecimals?: number);
|
|
150
|
-
/**
|
|
151
|
-
* Creates a new TomlFormat instance with default formatting preferences.
|
|
152
|
-
*
|
|
153
|
-
* @returns A new TomlFormat instance with default values:
|
|
154
|
-
* - newLine: '\n'
|
|
155
|
-
* - trailingNewline: 1
|
|
156
|
-
* - trailingComma: false
|
|
157
|
-
* - bracketSpacing: true
|
|
158
|
-
* - leadingBom: false
|
|
159
|
-
* - inlineTableStart: 1
|
|
160
|
-
* - truncateZeroTimeInDates: false
|
|
161
|
-
* - useTabsForIndentation: false
|
|
162
|
-
* - minimumDecimals: 0
|
|
163
|
-
* - minimumTimeDecimals: 0
|
|
164
|
-
* - updateOrder: false
|
|
165
|
-
*/
|
|
166
|
-
static default(): TomlFormat;
|
|
167
|
-
/**
|
|
168
|
-
* Auto-detects formatting preferences from an existing TOML string.
|
|
169
|
-
*
|
|
170
|
-
* This method analyzes the provided TOML string to determine formatting
|
|
171
|
-
* preferences such as line endings, trailing newlines, and comma usage.
|
|
172
|
-
*
|
|
173
|
-
* @param tomlString - The TOML string to analyze for formatting patterns
|
|
174
|
-
* @returns A new TomlFormat instance with detected formatting preferences
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* const toml = 'array = ["a", "b", "c",]\ntable = { x = 1, y = 2, }';
|
|
179
|
-
* const format = TomlFormat.autoDetectFormat(toml);
|
|
180
|
-
* // format.trailingComma will be true
|
|
181
|
-
* // format.newLine will be '\n'
|
|
182
|
-
* // format.trailingNewline will be 0 (no trailing newline)
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
static autoDetectFormat(tomlString: string): TomlFormat;
|
|
186
|
-
/**
|
|
187
|
-
* Internal method: Auto-detects formatting preferences from a TOML string with optional pre-parsed CST.
|
|
188
|
-
*
|
|
189
|
-
* This is used internally to avoid redundant parsing when the CST is already available.
|
|
190
|
-
* External callers should use `autoDetectFormat(tomlString)` instead.
|
|
191
|
-
*
|
|
192
|
-
* @internal
|
|
193
|
-
* @param tomlString - The TOML string to analyze for formatting patterns
|
|
194
|
-
* @param syntaxTree - Optional pre-parsed CST to avoid redundant parsing
|
|
195
|
-
* @returns A new TomlFormat instance with detected formatting preferences
|
|
196
|
-
*/
|
|
197
|
-
static autoDetectFormatWithCst(tomlString: string, syntaxTree?: Iterable<any>): TomlFormat;
|
|
198
|
-
/** @deprecated Use autoDetectFormatWithCst instead. */
|
|
199
|
-
static autoDetectFormatWithAst(tomlString: string, syntaxTree?: Iterable<any>): TomlFormat;
|
|
200
|
-
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/parse-options.d.ts
|
|
203
|
-
type IntegersAsBigInt = boolean | 'asNeeded';
|
|
204
|
-
interface ParseOptions {
|
|
205
|
-
/**
|
|
206
|
-
* Controls how TOML integers are returned in the parsed JavaScript object.
|
|
207
|
-
* - `true`: All integers are returned as `bigint`.
|
|
208
|
-
* - `false`: All integers are returned as `number` (may lose precision for large integers).
|
|
209
|
-
* - `'asNeeded'` (default): Integers that fit within the JavaScript safe-integer range are returned as `number`; larger integers are returned as `bigint`.
|
|
210
|
-
*/
|
|
211
|
-
integersAsBigInt?: IntegersAsBigInt;
|
|
212
|
-
/**
|
|
213
|
-
* When true, TOML date/time values are parsed into Temporal objects
|
|
214
|
-
* (Temporal.PlainDate, Temporal.PlainTime, Temporal.PlainDateTime,
|
|
215
|
-
* Temporal.ZonedDateTime) instead of custom Date subclasses.
|
|
216
|
-
*
|
|
217
|
-
* The Temporal API must be available in the runtime.
|
|
218
|
-
* - Node.js >= v26: full native support.
|
|
219
|
-
* - Node.js < v26: enable with the `--harmony-temporal` flag.
|
|
220
|
-
* - Modern browsers: native support.
|
|
221
|
-
* - Other runtimes: use @js-temporal/polyfill.
|
|
222
|
-
*
|
|
223
|
-
* Default: false (returns custom Date subclasses for backward compatibility).
|
|
224
|
-
*/
|
|
225
|
-
temporal?: boolean;
|
|
226
|
-
}
|
|
227
|
-
//#endregion
|
|
228
|
-
//#region src/location.d.ts
|
|
229
|
-
interface Location {
|
|
230
|
-
start: Position;
|
|
231
|
-
end: Position;
|
|
232
|
-
}
|
|
233
|
-
interface Position {
|
|
234
|
-
line: number;
|
|
235
|
-
column: number;
|
|
236
|
-
}
|
|
237
|
-
//#endregion
|
|
238
|
-
//#region src/cst.d.ts
|
|
239
|
-
declare enum NodeType {
|
|
240
|
-
Document = "Document",
|
|
241
|
-
Table = "Table",
|
|
242
|
-
TableKey = "TableKey",
|
|
243
|
-
/**
|
|
244
|
-
* Array of Tables node
|
|
245
|
-
* More info: https://toml.io/en/latest#array-of-tables
|
|
246
|
-
*/
|
|
247
|
-
TableArray = "TableArray",
|
|
248
|
-
TableArrayKey = "TableArrayKey",
|
|
249
|
-
KeyValue = "KeyValue",
|
|
250
|
-
Key = "Key",
|
|
251
|
-
String = "String",
|
|
252
|
-
Integer = "Integer",
|
|
253
|
-
Float = "Float",
|
|
254
|
-
Boolean = "Boolean",
|
|
255
|
-
DateTime = "DateTime",
|
|
256
|
-
InlineArray = "InlineArray",
|
|
257
|
-
InlineItem = "InlineItem",
|
|
258
|
-
InlineTable = "InlineTable",
|
|
259
|
-
/**
|
|
260
|
-
* Comment node
|
|
261
|
-
* More info: https://toml.io/en/latest#comment
|
|
262
|
-
*/
|
|
263
|
-
Comment = "Comment"
|
|
264
|
-
}
|
|
265
|
-
interface Table extends TreeNode {
|
|
266
|
-
type: NodeType.Table;
|
|
267
|
-
key: TableKey;
|
|
268
|
-
items: RowItem[];
|
|
269
|
-
}
|
|
270
|
-
interface TableKey extends TreeNode {
|
|
271
|
-
type: NodeType.TableKey;
|
|
272
|
-
item: Key;
|
|
273
|
-
}
|
|
274
|
-
interface TableArray extends TreeNode {
|
|
275
|
-
type: NodeType.TableArray;
|
|
276
|
-
key: TableArrayKey;
|
|
277
|
-
items: RowItem[];
|
|
278
|
-
}
|
|
279
|
-
interface TableArrayKey extends TreeNode {
|
|
280
|
-
type: NodeType.TableArrayKey;
|
|
281
|
-
item: Key;
|
|
282
|
-
}
|
|
283
|
-
interface KeyValue extends TreeNode {
|
|
284
|
-
type: NodeType.KeyValue;
|
|
285
|
-
key: Key;
|
|
286
|
-
value: Value;
|
|
287
|
-
equals: number;
|
|
288
|
-
}
|
|
289
|
-
interface Key extends TreeNode {
|
|
290
|
-
type: NodeType.Key;
|
|
291
|
-
raw: string;
|
|
292
|
-
value: string[];
|
|
293
|
-
}
|
|
294
|
-
interface String extends TreeNode {
|
|
295
|
-
type: NodeType.String;
|
|
296
|
-
raw: string;
|
|
297
|
-
value: string;
|
|
298
|
-
}
|
|
299
|
-
interface Integer extends TreeNode {
|
|
300
|
-
type: NodeType.Integer;
|
|
301
|
-
raw: string;
|
|
302
|
-
value: number | bigint;
|
|
303
|
-
}
|
|
304
|
-
interface Float extends TreeNode {
|
|
305
|
-
type: NodeType.Float;
|
|
306
|
-
raw: string;
|
|
307
|
-
value: number;
|
|
308
|
-
/** Sign prefix for NaN values: '+' for +nan, '-' for -nan, undefined for nan */
|
|
309
|
-
nanSign?: '+' | '-';
|
|
310
|
-
}
|
|
311
|
-
interface Boolean extends TreeNode {
|
|
312
|
-
type: NodeType.Boolean;
|
|
313
|
-
value: boolean;
|
|
314
|
-
}
|
|
315
|
-
interface DateTime extends TreeNode {
|
|
316
|
-
type: NodeType.DateTime;
|
|
317
|
-
raw: string;
|
|
318
|
-
value: Date;
|
|
319
|
-
}
|
|
320
|
-
interface InlineArray<TItem = TreeNode> extends TreeNode {
|
|
321
|
-
type: NodeType.InlineArray;
|
|
322
|
-
items: InlineArrayItem<TItem>[];
|
|
323
|
-
}
|
|
324
|
-
interface InlineItem<TItem = TreeNode> extends TreeNode {
|
|
325
|
-
type: NodeType.InlineItem;
|
|
326
|
-
item: TItem;
|
|
327
|
-
comma: boolean;
|
|
328
|
-
}
|
|
329
|
-
interface InlineArrayItem<TItem = TreeNode> extends InlineItem<TItem> {}
|
|
330
|
-
interface InlineTable extends TreeNode {
|
|
331
|
-
type: NodeType.InlineTable;
|
|
332
|
-
items: InlineTableItem[];
|
|
333
|
-
}
|
|
334
|
-
interface InlineTableItem extends InlineItem<KeyValue> {}
|
|
335
|
-
interface Comment extends TreeNode {
|
|
336
|
-
type: NodeType.Comment;
|
|
337
|
-
raw: string;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* RowItem represents items that can appear inside Table and TableArray sections.
|
|
341
|
-
* These are the items that form the "rows" of content within table structures.
|
|
342
|
-
*
|
|
343
|
-
* Unlike Block items (which include Table and TableArray), RowItems can only be
|
|
344
|
-
* KeyValue pairs and Comments - you cannot have nested tables within a table section.
|
|
345
|
-
*/
|
|
346
|
-
type RowItem = KeyValue | Comment;
|
|
347
|
-
/**
|
|
348
|
-
* Block represents items that can appear at the root level (Document level) in TOML.
|
|
349
|
-
*
|
|
350
|
-
* Context and Usage:
|
|
351
|
-
* - Block items are the fundamental top-level constructs in a TOML document
|
|
352
|
-
* - They appear directly in Document containers and regular Table sections
|
|
353
|
-
* - This is in contrast to InlineItems, which appear within inline containers
|
|
354
|
-
*
|
|
355
|
-
* Important Distinction:
|
|
356
|
-
* - Table and TableArray can ONLY exist as Block items (they cannot appear inside inline containers)
|
|
357
|
-
* - KeyValue and Comment can exist as BOTH Block items AND as InlineItems:
|
|
358
|
-
* * As Block: When they appear at root level or inside regular Table sections
|
|
359
|
-
* * As InlineItem: When they appear inside InlineTable or InlineArray containers
|
|
360
|
-
*
|
|
361
|
-
* Examples:
|
|
362
|
-
* ```toml
|
|
363
|
-
* # These are Block items at root level:
|
|
364
|
-
* name = "value" # KeyValue as Block
|
|
365
|
-
* # This is a comment # Comment as Block
|
|
366
|
-
* [table] # Table as Block
|
|
367
|
-
* [[array]] # TableArray as Block
|
|
368
|
-
*
|
|
369
|
-
* # These are Block items inside a Table:
|
|
370
|
-
* [config]
|
|
371
|
-
* setting = "value" # KeyValue as Block (inside Table)
|
|
372
|
-
* # comment here # Comment as Block (inside Table)
|
|
373
|
-
*
|
|
374
|
-
* # These are InlineItems (NOT Block items):
|
|
375
|
-
* array = [ "a", "b" ] # "a", "b" are InlineItems
|
|
376
|
-
* table = { key = "value" } # key="value" is InlineItem
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
* Type Safety:
|
|
380
|
-
* This distinction is crucial for the CST structure because:
|
|
381
|
-
* - Document.items: Block[]
|
|
382
|
-
* - Table.items: RowItem[] (KeyValue | Comment)
|
|
383
|
-
* - TableArray.items: RowItem[] (KeyValue | Comment)
|
|
384
|
-
* - InlineArray.items: InlineArrayItem[] (which extends InlineItem)
|
|
385
|
-
* - InlineTable.items: InlineTableItem[] (which extends InlineItem)
|
|
386
|
-
*/
|
|
387
|
-
type Block = KeyValue | Table | TableArray | Comment;
|
|
388
|
-
type Value<TInlineArrayItem = TreeNode> = String | Integer | Float | Boolean | DateTime | InlineArray<TInlineArrayItem> | InlineTable;
|
|
389
|
-
interface TreeNode {
|
|
390
|
-
type: NodeType;
|
|
391
|
-
loc: Location;
|
|
392
|
-
/** Absolute UTF-16 offsets into the source that produced this node. */
|
|
393
|
-
readonly range?: readonly [number, number];
|
|
394
|
-
/** Set on generated or mutated nodes and propagated to their ancestors. */
|
|
395
|
-
dirty?: boolean;
|
|
396
|
-
}
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region src/toml-document.d.ts
|
|
399
|
-
/**
|
|
400
|
-
* TomlDocument encapsulates a TOML CST and provides methods to interact with it.
|
|
401
|
-
*/
|
|
402
|
-
export declare class TomlDocument {
|
|
403
|
-
private _cst;
|
|
404
|
-
private _currentTomlString;
|
|
405
|
-
private _format;
|
|
406
|
-
private _integersAsBigInt;
|
|
407
|
-
private _temporal;
|
|
408
|
-
/**
|
|
409
|
-
* Initializes the TomlDocument with TOML source, parsing it into a CST.
|
|
410
|
-
*
|
|
411
|
-
* When bytes are provided, they are decoded as UTF-8 in fatal mode.
|
|
412
|
-
* This rejects invalid UTF-8 sequences before parsing.
|
|
413
|
-
*
|
|
414
|
-
* @param tomlSource - The TOML source to parse (string or raw UTF-8 bytes)
|
|
415
|
-
* @param options - Optional parse options
|
|
416
|
-
* @param options.integersAsBigInt - Controls bigint vs number for TOML integers
|
|
417
|
-
* @param options.temporal - When true, returns Temporal objects for date/time values
|
|
418
|
-
*/
|
|
419
|
-
constructor(tomlSource: string | Uint8Array, options?: ParseOptions);
|
|
420
|
-
get toTomlString(): string;
|
|
421
|
-
/**
|
|
422
|
-
* Returns the JavaScript object representation of the TOML document.
|
|
423
|
-
*/
|
|
424
|
-
get toJsObject(): any;
|
|
425
|
-
/**
|
|
426
|
-
* Returns the internal CST (for testing purposes).
|
|
427
|
-
* @internal
|
|
428
|
-
*/
|
|
429
|
-
get cst(): Block[];
|
|
430
|
-
/**
|
|
431
|
-
* Applies a patch to the current CST using a modified JS object.
|
|
432
|
-
* Updates the internal CST. Use toTomlString getter to retrieve the updated TOML string.
|
|
433
|
-
*
|
|
434
|
-
* @param updatedObject - The modified JS object to patch with
|
|
435
|
-
* @param format - Optional formatting options
|
|
436
|
-
*/
|
|
437
|
-
patch(updatedObject: any, format?: Partial<TomlFormat> | TomlFormat): void;
|
|
438
|
-
/**
|
|
439
|
-
* Updates the internal document by supplying a modified tomlString.
|
|
440
|
-
* Use toJsObject getter to retrieve the updated JS object representation.
|
|
441
|
-
* @param tomlString - The modified TOML string to update with
|
|
442
|
-
*/
|
|
443
|
-
update(tomlString: string): void;
|
|
444
|
-
/**
|
|
445
|
-
* Overwrites the internal syntax tree by fully re-parsing the supplied tomlString.
|
|
446
|
-
* This is simpler but slower than update() which uses incremental parsing.
|
|
447
|
-
* @param tomlString - The TOML string to overwrite with
|
|
448
|
-
*/
|
|
449
|
-
overwrite(tomlString: string): void;
|
|
450
|
-
}
|
|
451
|
-
//#endregion
|
|
452
|
-
//#region src/patch.d.ts
|
|
453
|
-
/**
|
|
454
|
-
* Applies modifications to a TOML document by comparing an existing TOML string with updated JavaScript data.
|
|
455
|
-
*
|
|
456
|
-
* This function preserves formatting and comments from the existing TOML document while
|
|
457
|
-
* applying changes from the updated data structure. It performs a diff between the existing
|
|
458
|
-
* and updated data, then strategically applies only the necessary changes to maintain the
|
|
459
|
-
* original document structure as much as possible.
|
|
460
|
-
*
|
|
461
|
-
* @param existing - The original TOML document as a string
|
|
462
|
-
* @param updated - The updated JavaScript object with desired changes
|
|
463
|
-
* @param format - Optional formatting options to apply to new or modified sections
|
|
464
|
-
* @returns A new TOML string with the changes applied
|
|
465
|
-
*/
|
|
466
|
-
declare function patch(existing: string, updated: any, format?: Partial<TomlFormat> | TomlFormat): string;
|
|
467
|
-
//#endregion
|
|
468
|
-
//#region src/date-format.d.ts
|
|
469
|
-
/**
|
|
470
|
-
* Custom Date class for local dates (date-only).
|
|
471
|
-
* Format: 1979-05-27
|
|
472
|
-
*/
|
|
473
|
-
export declare class LocalDate extends Date {
|
|
474
|
-
constructor(value: string);
|
|
475
|
-
toISOString(): string;
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Custom Date class for local times (time-only)
|
|
479
|
-
* Format: 07:32:00 or 07:32:00.999
|
|
480
|
-
*/
|
|
481
|
-
export declare class LocalTime extends Date {
|
|
482
|
-
originalFormat: string;
|
|
483
|
-
constructor(value: string, originalFormat?: string);
|
|
484
|
-
toISOString(): string;
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* Custom Date class for local datetime (no timezone)
|
|
488
|
-
* Format: 1979-05-27T07:32:00 or 1979-05-27 07:32:00
|
|
489
|
-
*/
|
|
490
|
-
export declare class LocalDateTime extends Date {
|
|
491
|
-
useSpaceSeparator: boolean;
|
|
492
|
-
originalFormat: string;
|
|
493
|
-
constructor(value: string, useSpaceSeparator?: boolean, originalFormat?: string);
|
|
494
|
-
toISOString(): string;
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Custom Date class for offset datetime that preserves space separator
|
|
498
|
-
* Format: 1979-05-27T07:32:00Z or 1979-05-27 07:32:00-07:00
|
|
499
|
-
*/
|
|
500
|
-
export declare class OffsetDateTime extends Date {
|
|
501
|
-
useSpaceSeparator: boolean;
|
|
502
|
-
originalOffset?: string;
|
|
503
|
-
originalFormat: string;
|
|
504
|
-
constructor(value: string, useSpaceSeparator?: boolean);
|
|
505
|
-
toISOString(): string;
|
|
506
|
-
}
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/index.d.ts
|
|
509
|
-
/**
|
|
510
|
-
* Parses a TOML string or raw UTF-8 bytes into a JavaScript object.
|
|
511
|
-
*
|
|
512
|
-
* When raw bytes (Uint8Array / Buffer) are provided, they are decoded with
|
|
513
|
-
* the WHATWG TextDecoder in fatal mode, which rejects any invalid UTF-8
|
|
514
|
-
* byte sequences before parsing begins. This matches the TOML spec requirement
|
|
515
|
-
* that "A TOML file must be a valid UTF-8 encoded Unicode document."
|
|
516
|
-
*
|
|
517
|
-
* The string path has zero overhead — the bytes path incurs one TextDecoder
|
|
518
|
-
* decode (which also produces the string needed for parsing).
|
|
519
|
-
*
|
|
520
|
-
* By default (`options.integersAsBigInt` unset or `'asNeeded'`), integers that
|
|
521
|
-
* fit within the JavaScript safe-integer range are returned as `number`; integers
|
|
522
|
-
* outside that range are returned as `bigint` to preserve precision. Set
|
|
523
|
-
* `options.integersAsBigInt` to `true` to always return `bigint` for all integers,
|
|
524
|
-
* or `false` to always return `number` (large integers will lose precision).
|
|
525
|
-
*
|
|
526
|
-
* Note: the `'asNeeded'` default is a behavioral change from prior versions (<=1.0.7). If
|
|
527
|
-
* your code serializes the result to JSON or performs arithmetic mixing `number`
|
|
528
|
-
* and `bigint`, set `integersAsBigInt: false` to restore the previous behavior.
|
|
529
|
-
*
|
|
530
|
-
* By default (`options.temporal` unset or `false`), TOML date/time values are
|
|
531
|
-
* returned as custom Date subclasses (LocalDate, LocalTime, LocalDateTime,
|
|
532
|
-
* OffsetDateTime). Set `options.temporal` to `true` to return Temporal API
|
|
533
|
-
* objects instead (Temporal.PlainDate, Temporal.PlainTime, Temporal.PlainDateTime,
|
|
534
|
-
* Temporal.ZonedDateTime). The Temporal API must be available in the runtime.
|
|
535
|
-
*
|
|
536
|
-
* @param value - TOML source as a string or raw UTF-8 bytes
|
|
537
|
-
* @param options - Optional parse options
|
|
538
|
-
* @param options.integersAsBigInt - Controls `bigint` vs `number` for integers.
|
|
539
|
-
* `'asNeeded'` (default) | `true` | `false`
|
|
540
|
-
* @param options.temporal - When true, returns Temporal objects for date/time values.
|
|
541
|
-
* Default: false.
|
|
542
|
-
* @returns The parsed JavaScript object
|
|
543
|
-
*/
|
|
544
|
-
export declare function parse(value: string | Uint8Array, options?: ParseOptions): any;
|
|
545
|
-
/**
|
|
546
|
-
* Converts a JavaScript object to a TOML string.
|
|
547
|
-
*
|
|
548
|
-
* @param value - The JavaScript object to stringify
|
|
549
|
-
* @param format - Optional formatting options for the resulting TOML
|
|
550
|
-
* @returns The stringified TOML representation
|
|
551
|
-
*/
|
|
552
|
-
export declare function stringify(value: any, format?: Partial<TomlFormat> | TomlFormat): string;
|
|
553
|
-
/**
|
|
554
|
-
* Parses a TOML string or raw UTF-8 bytes into a {@link TomlDocument}.
|
|
555
|
-
*
|
|
556
|
-
* This is a convenience alternative to `new TomlDocument(value, options)`.
|
|
557
|
-
*
|
|
558
|
-
* @param value - TOML source as a string or raw UTF-8 bytes
|
|
559
|
-
* @param options - Optional parse options
|
|
560
|
-
* @returns A {@link TomlDocument} representing the parsed TOML
|
|
561
|
-
*/
|
|
562
|
-
export declare function parseDocument(value: string | Uint8Array, options?: ParseOptions): TomlDocument;
|
|
563
|
-
//#endregion
|
|
564
|
-
export { type IntegersAsBigInt, type MultilineContainerMode, type ParseOptions, patch };
|