@visulima/fs 5.1.0 → 6.0.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.
@@ -1,1753 +0,0 @@
1
- import { PathLike, Dirent } from 'node:fs';
2
- import { FSLike } from 'fdir';
3
- //#region src/types.d.ts
4
- type FileSystemAdapter = Partial<FSLike>;
5
- interface GlobOptions$1 {
6
- /**
7
- * Whether to return absolute paths. Disable to have relative paths.
8
- * @default false
9
- */
10
- absolute?: boolean;
11
- /**
12
- * Enables support for brace expansion syntax, like `{a,b}` or `{1..9}`.
13
- * @default true
14
- */
15
- braceExpansion?: boolean;
16
- /**
17
- * Whether to match in case-sensitive mode.
18
- * @default true
19
- */
20
- caseSensitiveMatch?: boolean;
21
- /**
22
- * The working directory in which to search. Results will be returned relative to this directory, unless
23
- * {@link absolute} is set.
24
- *
25
- * It is important to avoid globbing outside this directory when possible, even with absolute paths enabled,
26
- * as doing so can harm performance due to having to recalculate relative paths.
27
- * @default process.cwd()
28
- */
29
- cwd?: string | URL;
30
- /**
31
- * Logs useful debug information. Meant for development purposes. Logs can change at any time.
32
- * @default false
33
- */
34
- debug?: boolean;
35
- /**
36
- * Maximum directory depth to crawl.
37
- * @default Infinity
38
- */
39
- deep?: number;
40
- /**
41
- * Whether to return entries that start with a dot, like `.gitignore` or `.prettierrc`.
42
- * @default false
43
- */
44
- dot?: boolean;
45
- /**
46
- * Whether to automatically expand directory patterns.
47
- *
48
- * Important to disable if migrating from [`fast-glob`](https://github.com/mrmlnc/fast-glob).
49
- * @default true
50
- */
51
- expandDirectories?: boolean;
52
- /**
53
- * Enables support for extglobs, like `+(pattern)`.
54
- * @default true
55
- */
56
- extglob?: boolean;
57
- /**
58
- * Whether to traverse and include symbolic links. Can slightly affect performance.
59
- * @default true
60
- */
61
- followSymbolicLinks?: boolean;
62
- /**
63
- * An object that overrides `node:fs` functions.
64
- * @default import('node:fs')
65
- */
66
- fs?: FileSystemAdapter;
67
- /**
68
- * Enables support for matching nested directories with globstars (`**`).
69
- * If `false`, `**` behaves exactly like `*`.
70
- * @default true
71
- */
72
- globstar?: boolean;
73
- /**
74
- * Glob patterns to exclude from the results.
75
- * @default []
76
- */
77
- ignore?: string | readonly string[];
78
- /**
79
- * Enable to only return directories.
80
- * If `true`, disables {@link onlyFiles}.
81
- * @default false
82
- */
83
- onlyDirectories?: boolean;
84
- /**
85
- * Enable to only return files.
86
- * @default true
87
- */
88
- onlyFiles?: boolean;
89
- /**
90
- * @deprecated Provide patterns as the first argument instead.
91
- */
92
- patterns?: string | readonly string[];
93
- /**
94
- * An `AbortSignal` to abort crawling the file system.
95
- * @default undefined
96
- */
97
- signal?: AbortSignal;
98
- }
99
- /**
100
- * Tracks newlines during parsing in order to provide an efficient API for
101
- * determining the one-indexed `{ line, col }` position for any offset
102
- * within the input.
103
- */
104
- declare class LineCounter {
105
- lineStarts: number[];
106
- /**
107
- * Should be called in ascending order. Otherwise, call
108
- * `lineCounter.lineStarts.sort()` before calling `linePos()`.
109
- */
110
- addNewLine: (offset: number) => number;
111
- /**
112
- * Performs a binary search and returns the 1-indexed { line, col }
113
- * position of `offset`. If `line === 0`, `addNewLine` has never been
114
- * called or `offset` is before the first known newline.
115
- */
116
- linePos: (offset: number) => {
117
- line: number;
118
- col: number;
119
- };
120
- }
121
- type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'NON_STRING_KEY' | 'RESOURCE_EXHAUSTION' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
122
- type LinePos = {
123
- line: number;
124
- col: number;
125
- };
126
- declare class YAMLError extends Error {
127
- name: 'YAMLParseError' | 'YAMLWarning';
128
- code: ErrorCode;
129
- message: string;
130
- pos: [number, number];
131
- linePos?: [LinePos] | [LinePos, LinePos];
132
- constructor(name: YAMLError['name'], pos: [number, number], code: ErrorCode, message: string);
133
- }
134
- declare class YAMLWarning extends YAMLError {
135
- constructor(pos: [number, number], code: ErrorCode, message: string);
136
- }
137
- type Reviver = (key: unknown, value: unknown) => unknown;
138
- type LogLevelId = 'silent' | 'error' | 'warn' | 'debug';
139
- interface AnchorData {
140
- aliasCount: number;
141
- count: number;
142
- res: unknown;
143
- }
144
- interface ToJSContext {
145
- anchors: Map<Node, AnchorData>;
146
- /** Cached anchor and alias nodes in the order they occur in the document */
147
- aliasResolveCache?: Node[];
148
- doc: Document<Node, boolean>;
149
- keep: boolean;
150
- mapAsMap: boolean;
151
- mapKeyWarned: boolean;
152
- maxAliasCount: number;
153
- onCreate?: (res: unknown) => void;
154
- }
155
- declare namespace Scalar {
156
- interface Parsed extends Scalar {
157
- range: Range;
158
- source: string;
159
- srcToken?: FlowScalar | BlockScalar;
160
- }
161
- type BLOCK_FOLDED = 'BLOCK_FOLDED';
162
- type BLOCK_LITERAL = 'BLOCK_LITERAL';
163
- type PLAIN = 'PLAIN';
164
- type QUOTE_DOUBLE = 'QUOTE_DOUBLE';
165
- type QUOTE_SINGLE = 'QUOTE_SINGLE';
166
- type Type = BLOCK_FOLDED | BLOCK_LITERAL | PLAIN | QUOTE_DOUBLE | QUOTE_SINGLE;
167
- }
168
- declare class Scalar<T = unknown> extends NodeBase {
169
- static readonly BLOCK_FOLDED = "BLOCK_FOLDED";
170
- static readonly BLOCK_LITERAL = "BLOCK_LITERAL";
171
- static readonly PLAIN = "PLAIN";
172
- static readonly QUOTE_DOUBLE = "QUOTE_DOUBLE";
173
- static readonly QUOTE_SINGLE = "QUOTE_SINGLE";
174
- value: T;
175
- /** An optional anchor on this node. Used by alias nodes. */
176
- anchor?: string;
177
- /**
178
- * By default (undefined), numbers use decimal notation.
179
- * The YAML 1.2 core schema only supports 'HEX' and 'OCT'.
180
- * The YAML 1.1 schema also supports 'BIN' and 'TIME'
181
- */
182
- format?: string;
183
- /**
184
- * If `value` is a number that is serialized as a decimal string
185
- * (i.e. not using exponential notation),
186
- * use this value when stringifying this node.
187
- */
188
- minFractionDigits?: number;
189
- /** Set during parsing to the source string value */
190
- source?: string;
191
- /** The scalar style used for the node's string representation */
192
- type?: Scalar.Type;
193
- constructor(value: T);
194
- toJSON(arg?: any, ctx?: ToJSContext): any;
195
- toString(): string;
196
- }
197
- type StringifyContext = {
198
- actualString?: boolean;
199
- allNullValues?: boolean;
200
- anchors: Set<string>;
201
- doc: Document;
202
- forceBlockIndent?: boolean;
203
- implicitKey?: boolean;
204
- indent: string;
205
- indentStep: string;
206
- indentAtStart?: number;
207
- inFlow: boolean | null;
208
- inStringifyKey?: boolean;
209
- flowCollectionPadding: string;
210
- options: Readonly<Required<Omit<ToStringOptions, 'collectionStyle' | 'indent'>>>;
211
- resolvedAliases?: Set<Alias>;
212
- };
213
- declare abstract class Collection extends NodeBase {
214
- schema: Schema | undefined;
215
- [NODE_TYPE]: symbol;
216
- items: unknown[];
217
- /** An optional anchor on this node. Used by alias nodes. */
218
- anchor?: string;
219
- /**
220
- * If true, stringify this and all child nodes using flow rather than
221
- * block styles.
222
- */
223
- flow?: boolean;
224
- constructor(type: symbol, schema?: Schema);
225
- /**
226
- * Create a copy of this collection.
227
- *
228
- * @param schema - If defined, overwrites the original's schema
229
- */
230
- clone(schema?: Schema): Collection;
231
- /** Adds a value to the collection. */
232
- abstract add(value: unknown): void;
233
- /**
234
- * Removes a value from the collection.
235
- * @returns `true` if the item was found and removed.
236
- */
237
- abstract delete(key: unknown): boolean;
238
- /**
239
- * Returns item at `key`, or `undefined` if not found. By default unwraps
240
- * scalar values from their surrounding node; to disable set `keepScalar` to
241
- * `true` (collections are always returned intact).
242
- */
243
- abstract get(key: unknown, keepScalar?: boolean): unknown;
244
- /**
245
- * Checks if the collection includes a value with the key `key`.
246
- */
247
- abstract has(key: unknown): boolean;
248
- /**
249
- * Sets a value in this collection. For `!!set`, `value` needs to be a
250
- * boolean to add/remove the item from the set.
251
- */
252
- abstract set(key: unknown, value: unknown): void;
253
- /**
254
- * Adds a value to the collection. For `!!map` and `!!omap` the value must
255
- * be a Pair instance or a `{ key, value }` object, which may not have a key
256
- * that already exists in the map.
257
- */
258
- addIn(path: Iterable<unknown>, value: unknown): void;
259
- /**
260
- * Removes a value from the collection.
261
- * @returns `true` if the item was found and removed.
262
- */
263
- deleteIn(path: Iterable<unknown>): boolean;
264
- /**
265
- * Returns item at `key`, or `undefined` if not found. By default unwraps
266
- * scalar values from their surrounding node; to disable set `keepScalar` to
267
- * `true` (collections are always returned intact).
268
- */
269
- getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
270
- hasAllNullValues(allowScalar?: boolean): boolean;
271
- /**
272
- * Checks if the collection includes a value with the key `key`.
273
- */
274
- hasIn(path: Iterable<unknown>): boolean;
275
- /**
276
- * Sets a value in this collection. For `!!set`, `value` needs to be a
277
- * boolean to add/remove the item from the set.
278
- */
279
- setIn(path: Iterable<unknown>, value: unknown): void;
280
- }
281
- declare namespace YAMLSeq {
282
- interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
283
- items: T[];
284
- range: Range;
285
- srcToken?: BlockSequence | FlowCollection;
286
- }
287
- }
288
- declare class YAMLSeq<T = unknown> extends Collection {
289
- static get tagName(): 'tag:yaml.org,2002:seq';
290
- items: T[];
291
- constructor(schema?: Schema);
292
- add(value: T): void;
293
- /**
294
- * Removes a value from the collection.
295
- *
296
- * `key` must contain a representation of an integer for this to succeed.
297
- * It may be wrapped in a `Scalar`.
298
- *
299
- * @returns `true` if the item was found and removed.
300
- */
301
- delete(key: unknown): boolean;
302
- /**
303
- * Returns item at `key`, or `undefined` if not found. By default unwraps
304
- * scalar values from their surrounding node; to disable set `keepScalar` to
305
- * `true` (collections are always returned intact).
306
- *
307
- * `key` must contain a representation of an integer for this to succeed.
308
- * It may be wrapped in a `Scalar`.
309
- */
310
- get(key: unknown, keepScalar: true): Scalar<T> | undefined;
311
- get(key: unknown, keepScalar?: false): T | undefined;
312
- get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
313
- /**
314
- * Checks if the collection includes a value with the key `key`.
315
- *
316
- * `key` must contain a representation of an integer for this to succeed.
317
- * It may be wrapped in a `Scalar`.
318
- */
319
- has(key: unknown): boolean;
320
- /**
321
- * Sets a value in this collection. For `!!set`, `value` needs to be a
322
- * boolean to add/remove the item from the set.
323
- *
324
- * If `key` does not contain a representation of an integer, this will throw.
325
- * It may be wrapped in a `Scalar`.
326
- */
327
- set(key: unknown, value: T): void;
328
- toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
329
- toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
330
- static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLSeq;
331
- }
332
- interface TagBase {
333
- /**
334
- * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
335
- */
336
- createNode?: (schema: Schema, value: unknown, ctx: CreateNodeContext) => Node;
337
- /**
338
- * If `true`, allows for values to be stringified without
339
- * an explicit tag together with `test`.
340
- * If `'key'`, this only applies if the value is used as a mapping key.
341
- * For most cases, it's unlikely that you'll actually want to use this,
342
- * even if you first think you do.
343
- */
344
- default?: boolean | 'key';
345
- /**
346
- * If a tag has multiple forms that should be parsed and/or stringified
347
- * differently, use `format` to identify them.
348
- */
349
- format?: string;
350
- /**
351
- * Used by `YAML.createNode` to detect your data type, e.g. using `typeof` or
352
- * `instanceof`.
353
- */
354
- identify?: (value: unknown) => boolean;
355
- /**
356
- * The identifier for your data type, with which its stringified form will be
357
- * prefixed. Should either be a !-prefixed local `!tag`, or a fully qualified
358
- * `tag:domain,date:foo`.
359
- */
360
- tag: string;
361
- }
362
- interface ScalarTag extends TagBase {
363
- collection?: never;
364
- nodeClass?: never;
365
- /**
366
- * Turns a value into an AST node.
367
- * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
368
- */
369
- resolve(value: string, onError: (message: string) => void, options: ParseOptions): unknown;
370
- /**
371
- * Optional function stringifying a Scalar node. If your data includes a
372
- * suitable `.toString()` method, you can probably leave this undefined and
373
- * use the default stringifier.
374
- *
375
- * @param item The node being stringified.
376
- * @param ctx Contains the stringifying context variables.
377
- * @param onComment Callback to signal that the stringifier includes the
378
- * item's comment in its output.
379
- * @param onChompKeep Callback to signal that the output uses a block scalar
380
- * type with the `+` chomping indicator.
381
- */
382
- stringify?: (item: Scalar, ctx: StringifyContext, onComment?: () => void, onChompKeep?: () => void) => string;
383
- /**
384
- * Together with `default` allows for values to be stringified without an
385
- * explicit tag and detected using a regular expression. For most cases, it's
386
- * unlikely that you'll actually want to use these, even if you first think
387
- * you do.
388
- */
389
- test?: RegExp;
390
- }
391
- interface CollectionTag extends TagBase {
392
- stringify?: never;
393
- test?: never;
394
- /** The source collection type supported by this tag. */
395
- collection: 'map' | 'seq';
396
- /**
397
- * The `Node` child class that implements this tag.
398
- * If set, used to select this tag when stringifying.
399
- *
400
- * If the class provides a static `from` method, then that
401
- * will be used if the tag object doesn't have a `createNode` method.
402
- */
403
- nodeClass?: {
404
- new (schema?: Schema): Node;
405
- from?: (schema: Schema, obj: unknown, ctx: CreateNodeContext) => Node;
406
- };
407
- /**
408
- * Turns a value into an AST node.
409
- * If returning a non-`Node` value, the output will be wrapped as a `Scalar`.
410
- *
411
- * Note: this is required if nodeClass is not provided.
412
- */
413
- resolve?: (value: YAMLMap.Parsed | YAMLSeq.Parsed, onError: (message: string) => void, options: ParseOptions) => unknown;
414
- }
415
- type MapLike = Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
416
- declare namespace YAMLMap {
417
- interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
418
- items: Pair<K, V>[];
419
- range: Range;
420
- srcToken?: BlockMap | FlowCollection;
421
- }
422
- }
423
- declare class YAMLMap<K = unknown, V = unknown> extends Collection {
424
- static get tagName(): 'tag:yaml.org,2002:map';
425
- items: Pair<K, V>[];
426
- constructor(schema?: Schema);
427
- /**
428
- * A generic collection parsing method that can be extended
429
- * to other node classes that inherit from YAMLMap
430
- */
431
- static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLMap;
432
- /**
433
- * Adds a value to the collection.
434
- *
435
- * @param overwrite - If not set `true`, using a key that is already in the
436
- * collection will throw. Otherwise, overwrites the previous value.
437
- */
438
- add(pair: Pair<K, V> | {
439
- key: K;
440
- value: V;
441
- }, overwrite?: boolean): void;
442
- delete(key: unknown): boolean;
443
- get(key: unknown, keepScalar: true): Scalar<V> | undefined;
444
- get(key: unknown, keepScalar?: false): V | undefined;
445
- get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
446
- has(key: unknown): boolean;
447
- set(key: K, value: V): void;
448
- /**
449
- * @param ctx - Conversion context, originally set in Document#toJS()
450
- * @param {Class} Type - If set, forces the returned collection type
451
- * @returns Instance of Type, Map, or Object
452
- */
453
- toJSON<T extends MapLike = Map<unknown, unknown>>(_?: unknown, ctx?: ToJSContext, Type?: {
454
- new (): T;
455
- }): any;
456
- toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
457
- }
458
- declare const MAP: unique symbol;
459
- declare const SCALAR: unique symbol;
460
- declare const SEQ: unique symbol;
461
- declare const NODE_TYPE: unique symbol;
462
- declare class Schema {
463
- compat: Array<CollectionTag | ScalarTag> | null;
464
- knownTags: Record<string, CollectionTag | ScalarTag>;
465
- name: string;
466
- sortMapEntries: ((a: Pair, b: Pair) => number) | null;
467
- tags: Array<CollectionTag | ScalarTag>;
468
- toStringOptions: Readonly<ToStringOptions> | null;
469
- readonly [MAP]: CollectionTag;
470
- readonly [SCALAR]: ScalarTag;
471
- readonly [SEQ]: CollectionTag;
472
- constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }: SchemaOptions);
473
- clone(): Schema;
474
- }
475
- interface CreateNodeContext {
476
- aliasDuplicateObjects: boolean;
477
- keepUndefined: boolean;
478
- onAnchor: (source: unknown) => string;
479
- onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
480
- sourceObjects: Map<unknown, {
481
- anchor: string | null;
482
- node: Node | null;
483
- }>;
484
- replacer?: Replacer;
485
- schema: Schema;
486
- }
487
- declare function addPairToJSMap(ctx: ToJSContext | undefined, map: MapLike, { key, value }: Pair): MapLike;
488
- declare class Pair<K = unknown, V = unknown> {
489
- readonly [NODE_TYPE]: symbol;
490
- /** Always Node or null when parsed, but can be set to anything. */
491
- key: K;
492
- /** Always Node or null when parsed, but can be set to anything. */
493
- value: V | null;
494
- /** The CST token that was composed into this pair. */
495
- srcToken?: CollectionItem;
496
- constructor(key: K, value?: V | null);
497
- clone(schema?: Schema): Pair<K, V>;
498
- toJSON(_?: unknown, ctx?: ToJSContext): ReturnType<typeof addPairToJSMap>;
499
- toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
500
- }
501
- declare const tagsByName: {
502
- binary: ScalarTag;
503
- bool: ScalarTag & {
504
- test: RegExp;
505
- };
506
- float: ScalarTag;
507
- floatExp: ScalarTag;
508
- floatNaN: ScalarTag;
509
- floatTime: ScalarTag;
510
- int: ScalarTag;
511
- intHex: ScalarTag;
512
- intOct: ScalarTag;
513
- intTime: ScalarTag;
514
- map: CollectionTag;
515
- merge: ScalarTag & {
516
- identify(value: unknown): boolean;
517
- test: RegExp;
518
- };
519
- null: ScalarTag & {
520
- test: RegExp;
521
- };
522
- omap: CollectionTag;
523
- pairs: CollectionTag;
524
- seq: CollectionTag;
525
- set: CollectionTag;
526
- timestamp: ScalarTag & {
527
- test: RegExp;
528
- };
529
- };
530
- type TagId = keyof typeof tagsByName;
531
- type Tags = Array<ScalarTag | CollectionTag | TagId>;
532
- type ParseOptions = {
533
- /**
534
- * Whether integers should be parsed into BigInt rather than number values.
535
- *
536
- * Default: `false`
537
- *
538
- * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
539
- */
540
- intAsBigInt?: boolean;
541
- /**
542
- * Include a `srcToken` value on each parsed `Node`, containing the CST token
543
- * that was composed into this node.
544
- *
545
- * Default: `false`
546
- */
547
- keepSourceTokens?: boolean;
548
- /**
549
- * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
550
- * to provide the `{ line, col }` positions within the input.
551
- */
552
- lineCounter?: LineCounter;
553
- /**
554
- * Include line/col position & node type directly in parse errors.
555
- *
556
- * Default: `true`
557
- */
558
- prettyErrors?: boolean;
559
- /**
560
- * Detect and report errors that are required by the YAML 1.2 spec,
561
- * but are caused by unambiguous content.
562
- *
563
- * Default: `true`
564
- */
565
- strict?: boolean;
566
- /**
567
- * Parse all mapping keys as strings. Treat all non-scalar keys as errors.
568
- *
569
- * Default: `false`
570
- */
571
- stringKeys?: boolean;
572
- /**
573
- * YAML requires map keys to be unique. By default, this is checked by
574
- * comparing scalar values with `===`; deep equality is not checked for
575
- * aliases or collections. If merge keys are enabled by the schema,
576
- * multiple `<<` keys are allowed.
577
- *
578
- * Set `false` to disable, or provide your own comparator function to
579
- * customise. The comparator will be passed two `ParsedNode` values, and
580
- * is expected to return a `boolean` indicating their equality.
581
- *
582
- * Default: `true`
583
- */
584
- uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
585
- };
586
- type DocumentOptions = {
587
-
588
- /**
589
- * Control the logging level during parsing
590
- *
591
- * Default: `'warn'`
592
- */
593
- logLevel?: LogLevelId;
594
- /**
595
- * The YAML version used by documents without a `%YAML` directive.
596
- *
597
- * Default: `"1.2"`
598
- */
599
- version?: '1.1' | '1.2' | 'next';
600
- };
601
- type SchemaOptions = {
602
- /**
603
- * When parsing, warn about compatibility issues with the given schema.
604
- * When stringifying, use scalar styles that are parsed correctly
605
- * by the `compat` schema as well as the actual schema.
606
- *
607
- * Default: `null`
608
- */
609
- compat?: string | Tags | null;
610
- /**
611
- * Array of additional tags to include in the schema, or a function that may
612
- * modify the schema's base tag array.
613
- */
614
- customTags?: Tags | ((tags: Tags) => Tags) | null;
615
- /**
616
- * Enable support for `<<` merge keys.
617
- *
618
- * Default: `false` for YAML 1.2, `true` for earlier versions
619
- */
620
- merge?: boolean;
621
- /**
622
- * When using the `'core'` schema, support parsing values with these
623
- * explicit YAML 1.1 tags:
624
- *
625
- * `!!binary`, `!!omap`, `!!pairs`, `!!set`, `!!timestamp`.
626
- *
627
- * Default `true`
628
- */
629
- resolveKnownTags?: boolean;
630
- /**
631
- * The base schema to use.
632
- *
633
- * The core library has built-in support for the following:
634
- * - `'failsafe'`: A minimal schema that parses all scalars as strings
635
- * - `'core'`: The YAML 1.2 core schema
636
- * - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
637
- * - `'yaml-1.1'`: The YAML 1.1 schema
638
- *
639
- * If using another (custom) schema, the `customTags` array needs to
640
- * fully define the schema's tags.
641
- *
642
- * Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
643
- */
644
- schema?: string | Schema;
645
- /**
646
- * When adding to or stringifying a map, sort the entries.
647
- * If `true`, sort by comparing key values with `<`.
648
- * Does not affect item order when parsing.
649
- *
650
- * Default: `false`
651
- */
652
- sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
653
- /**
654
- * Override default values for `toString()` options.
655
- */
656
- toStringDefaults?: ToStringOptions;
657
- };
658
- type CreateNodeOptions = {
659
- /**
660
- * During node construction, use anchors and aliases to keep strictly equal
661
- * non-null objects as equivalent in YAML.
662
- *
663
- * Default: `true`
664
- */
665
- aliasDuplicateObjects?: boolean;
666
- /**
667
- * Default prefix for anchors.
668
- *
669
- * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
670
- */
671
- anchorPrefix?: string;
672
- /** Force the top-level collection node to use flow style. */
673
- flow?: boolean;
674
- /**
675
- * Keep `undefined` object values when creating mappings, rather than
676
- * discarding them.
677
- *
678
- * Default: `false`
679
- */
680
- keepUndefined?: boolean | null;
681
- onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
682
- /**
683
- * Specify the top-level collection type, e.g. `"!!omap"`. Note that this
684
- * requires the corresponding tag to be available in this document's schema.
685
- */
686
- tag?: string;
687
- };
688
- type ToJSOptions = {
689
- /**
690
- * Use Map rather than Object to represent mappings.
691
- *
692
- * Default: `false`
693
- */
694
- mapAsMap?: boolean;
695
- /**
696
- * Prevent exponential entity expansion attacks by limiting data aliasing count;
697
- * set to `-1` to disable checks; `0` disallows all alias nodes.
698
- *
699
- * Default: `100`
700
- */
701
- maxAliasCount?: number;
702
- /**
703
- * If defined, called with the resolved `value` and reference `count` for
704
- * each anchor in the document.
705
- */
706
- onAnchor?: (value: unknown, count: number) => void;
707
- /**
708
- * Optional function that may filter or modify the output JS value
709
- *
710
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter
711
- */
712
- reviver?: Reviver;
713
- };
714
- type ToStringOptions = {
715
- /**
716
- * Use block quote styles for scalar values where applicable.
717
- * Set to `false` to disable block quotes completely.
718
- *
719
- * Default: `true`
720
- */
721
- blockQuote?: boolean | 'folded' | 'literal';
722
- /**
723
- * Enforce `'block'` or `'flow'` style on maps and sequences.
724
- * Empty collections will always be stringified as `{}` or `[]`.
725
- *
726
- * Default: `'any'`, allowing each node to set its style separately
727
- * with its `flow: boolean` (default `false`) property.
728
- */
729
- collectionStyle?: 'any' | 'block' | 'flow';
730
- /**
731
- * Comment stringifier.
732
- * Output should be valid for the current schema.
733
- *
734
- * By default, empty comment lines are left empty,
735
- * lines consisting of a single space are replaced by `#`,
736
- * and all other lines are prefixed with a `#`.
737
- */
738
- commentString?: (comment: string) => string;
739
- /**
740
- * The default type of string literal used to stringify implicit key values.
741
- * Output may use other types if required to fully represent the value.
742
- *
743
- * If `null`, the value of `defaultStringType` is used.
744
- *
745
- * Default: `null`
746
- */
747
- defaultKeyType?: Scalar.Type | null;
748
- /**
749
- * The default type of string literal used to stringify values in general.
750
- * Output may use other types if required to fully represent the value.
751
- *
752
- * Default: `'PLAIN'`
753
- */
754
- defaultStringType?: Scalar.Type;
755
- /**
756
- * Include directives in the output.
757
- *
758
- * - If `true`, at least the document-start marker `---` is always included.
759
- * This does not force the `%YAML` directive to be included. To do that,
760
- * set `doc.directives.yaml.explicit = true`.
761
- * - If `false`, no directives or marker is ever included. If using the `%TAG`
762
- * directive, you are expected to include it manually in the stream before
763
- * its use.
764
- * - If `null`, directives and marker may be included if required.
765
- *
766
- * Default: `null`
767
- */
768
- directives?: boolean | null;
769
- /**
770
- * Restrict double-quoted strings to use JSON-compatible syntax.
771
- *
772
- * Default: `false`
773
- */
774
- doubleQuotedAsJSON?: boolean;
775
- /**
776
- * Minimum length for double-quoted strings to use multiple lines to
777
- * represent the value. Ignored if `doubleQuotedAsJSON` is set.
778
- *
779
- * Default: `40`
780
- */
781
- doubleQuotedMinMultiLineLength?: number;
782
- /**
783
- * String representation for `false`.
784
- * With the core schema, use `'false'`, `'False'`, or `'FALSE'`.
785
- *
786
- * Default: `'false'`
787
- */
788
- falseStr?: string;
789
- /**
790
- * When true, a single space of padding will be added inside the delimiters
791
- * of non-empty single-line flow collections.
792
- *
793
- * Default: `true`
794
- */
795
- flowCollectionPadding?: boolean;
796
- /**
797
- * The number of spaces to use when indenting code.
798
- *
799
- * Default: `2`
800
- */
801
- indent?: number;
802
- /**
803
- * Whether block sequences should be indented.
804
- *
805
- * Default: `true`
806
- */
807
- indentSeq?: boolean;
808
- /**
809
- * Maximum line width (set to `0` to disable folding).
810
- *
811
- * This is a soft limit, as only double-quoted semantics allow for inserting
812
- * a line break in the middle of a word, as well as being influenced by the
813
- * `minContentWidth` option.
814
- *
815
- * Default: `80`
816
- */
817
- lineWidth?: number;
818
- /**
819
- * Minimum line width for highly-indented content (set to `0` to disable).
820
- *
821
- * Default: `20`
822
- */
823
- minContentWidth?: number;
824
- /**
825
- * String representation for `null`.
826
- * With the core schema, use `'null'`, `'Null'`, `'NULL'`, `'~'`, or an empty
827
- * string `''`.
828
- *
829
- * Default: `'null'`
830
- */
831
- nullStr?: string;
832
- /**
833
- * Require keys to be scalars and to use implicit rather than explicit notation.
834
- *
835
- * Default: `false`
836
- */
837
- simpleKeys?: boolean;
838
- /**
839
- * Use 'single quote' rather than "double quote" where applicable.
840
- * Set to `false` to disable single quotes completely.
841
- *
842
- * Default: `null`
843
- */
844
- singleQuote?: boolean | null;
845
- /**
846
- * Add a trailing comma after the last entry in a flow map or flow sequence that's split across multiple lines.
847
- *
848
- * Default: `'false'`
849
- */
850
- trailingComma?: boolean;
851
- /**
852
- * String representation for `true`.
853
- * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
854
- *
855
- * Default: `'true'`
856
- */
857
- trueStr?: string;
858
- /**
859
- * The anchor used by an alias must be defined before the alias node. As it's
860
- * possible for the document to be modified manually, the order may be
861
- * verified during stringification.
862
- *
863
- * Default: `'true'`
864
- */
865
- verifyAliasOrder?: boolean;
866
- };
867
- type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
868
- /** Utility type mapper */
869
- type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
870
- [key: string]: any;
871
- } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
872
- [key: number]: any;
873
- } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
874
- type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
875
- /** `[start, value-end, node-end]` */
876
- type Range = [number, number, number];
877
- declare abstract class NodeBase {
878
- readonly [NODE_TYPE]: symbol;
879
- /** A comment on or immediately after this */
880
- comment?: string | null;
881
- /** A comment before this */
882
- commentBefore?: string | null;
883
- /**
884
- * The `[start, value-end, node-end]` character offsets for the part of the
885
- * source parsed into this node (undefined if not parsed). The `value-end`
886
- * and `node-end` positions are themselves not included in their respective
887
- * ranges.
888
- */
889
- range?: Range | null;
890
- /** A blank line before this node and its commentBefore */
891
- spaceBefore?: boolean;
892
- /** The CST token that was composed into this node. */
893
- srcToken?: Token;
894
- /** A fully qualified tag, if required */
895
- tag?: string;
896
- /**
897
- * Customize the way that a key-value pair is resolved.
898
- * Used for YAML 1.1 !!merge << handling.
899
- */
900
- addToJSMap?: (ctx: ToJSContext | undefined, map: MapLike, value: unknown) => void;
901
- /** A plain JS representation of this node */
902
- abstract toJSON(): any;
903
- abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
904
- constructor(type: symbol);
905
- /** Create a copy of this node. */
906
- clone(): NodeBase;
907
- /** A plain JavaScript representation of this node. */
908
- toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any;
909
- }
910
- interface SourceToken {
911
- type: 'byte-order-mark' | 'doc-mode' | 'doc-start' | 'space' | 'comment' | 'newline' | 'directive-line' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'block-scalar-header';
912
- offset: number;
913
- indent: number;
914
- source: string;
915
- }
916
- interface ErrorToken {
917
- type: 'error';
918
- offset: number;
919
- source: string;
920
- message: string;
921
- }
922
- interface Directive {
923
- type: 'directive';
924
- offset: number;
925
- source: string;
926
- }
927
- interface Document$1 {
928
- type: 'document';
929
- offset: number;
930
- start: SourceToken[];
931
- value?: Token;
932
- end?: SourceToken[];
933
- }
934
- interface DocumentEnd {
935
- type: 'doc-end';
936
- offset: number;
937
- source: string;
938
- end?: SourceToken[];
939
- }
940
- interface FlowScalar {
941
- type: 'alias' | 'scalar' | 'single-quoted-scalar' | 'double-quoted-scalar';
942
- offset: number;
943
- indent: number;
944
- source: string;
945
- end?: SourceToken[];
946
- }
947
- interface BlockScalar {
948
- type: 'block-scalar';
949
- offset: number;
950
- indent: number;
951
- props: Token[];
952
- source: string;
953
- }
954
- interface BlockMap {
955
- type: 'block-map';
956
- offset: number;
957
- indent: number;
958
- items: Array<{
959
- start: SourceToken[];
960
- explicitKey?: true;
961
- key?: never;
962
- sep?: never;
963
- value?: never;
964
- } | {
965
- start: SourceToken[];
966
- explicitKey?: true;
967
- key: Token | null;
968
- sep: SourceToken[];
969
- value?: Token;
970
- }>;
971
- }
972
- interface BlockSequence {
973
- type: 'block-seq';
974
- offset: number;
975
- indent: number;
976
- items: Array<{
977
- start: SourceToken[];
978
- key?: never;
979
- sep?: never;
980
- value?: Token;
981
- }>;
982
- }
983
- type CollectionItem = {
984
- start: SourceToken[];
985
- key?: Token | null;
986
- sep?: SourceToken[];
987
- value?: Token;
988
- };
989
- interface FlowCollection {
990
- type: 'flow-collection';
991
- offset: number;
992
- indent: number;
993
- start: SourceToken;
994
- items: CollectionItem[];
995
- end: SourceToken[];
996
- }
997
- type Token = SourceToken | ErrorToken | Directive | Document$1 | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
998
- declare namespace Alias {
999
- interface Parsed extends Alias {
1000
- range: Range;
1001
- srcToken?: FlowScalar & {
1002
- type: 'alias';
1003
- };
1004
- }
1005
- }
1006
- declare class Alias extends NodeBase {
1007
- source: string;
1008
- anchor?: never;
1009
- constructor(source: string);
1010
- /**
1011
- * Resolve the value of this alias within `doc`, finding the last
1012
- * instance of the `source` anchor before this node.
1013
- */
1014
- resolve(doc: Document, ctx?: ToJSContext): Scalar | YAMLMap | YAMLSeq | undefined;
1015
- toJSON(_arg?: unknown, ctx?: ToJSContext): unknown;
1016
- toString(ctx?: StringifyContext, _onComment?: () => void, _onChompKeep?: () => void): string;
1017
- }
1018
- type Replacer = any[] | ((key: any, value: any) => unknown);
1019
- declare namespace Document {
1020
- /** @ts-ignore The typing of directives fails in TS <= 4.2 */
1021
- interface Parsed<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> extends Document<Contents, Strict> {
1022
- directives: Directives;
1023
- range: Range;
1024
- }
1025
- }
1026
- declare class Document<Contents extends Node = Node, Strict extends boolean = true> {
1027
- readonly [NODE_TYPE]: symbol;
1028
- /** A comment before this Document */
1029
- commentBefore: string | null;
1030
- /** A comment immediately after this Document */
1031
- comment: string | null;
1032
- /** The document contents. */
1033
- contents: Strict extends true ? Contents | null : Contents;
1034
- directives: Strict extends true ? Directives | undefined : Directives;
1035
- /** Errors encountered during parsing. */
1036
- errors: YAMLError[];
1037
- options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
1038
- /**
1039
- * The `[start, value-end, node-end]` character offsets for the part of the
1040
- * source parsed into this document (undefined if not parsed). The `value-end`
1041
- * and `node-end` positions are themselves not included in their respective
1042
- * ranges.
1043
- */
1044
- range?: Range;
1045
- /** The schema used with the document. Use `setSchema()` to change. */
1046
- schema: Schema;
1047
- /** Warnings encountered during parsing. */
1048
- warnings: YAMLWarning[];
1049
- /**
1050
- * @param value - The initial value for the document, which will be wrapped
1051
- * in a Node container.
1052
- */
1053
- constructor(value?: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
1054
- constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
1055
- /**
1056
- * Create a deep copy of this Document and its contents.
1057
- *
1058
- * Custom Node values that inherit from `Object` still refer to their original instances.
1059
- */
1060
- clone(): Document<Contents, Strict>;
1061
- /** Adds a value to the document. */
1062
- add(value: any): void;
1063
- /** Adds a value to the document. */
1064
- addIn(path: Iterable<unknown>, value: unknown): void;
1065
- /**
1066
- * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
1067
- *
1068
- * If `node` already has an anchor, `name` is ignored.
1069
- * Otherwise, the `node.anchor` value will be set to `name`,
1070
- * or if an anchor with that name is already present in the document,
1071
- * `name` will be used as a prefix for a new unique anchor.
1072
- * If `name` is undefined, the generated anchor will use 'a' as a prefix.
1073
- */
1074
- createAlias(node: Strict extends true ? Scalar | YAMLMap | YAMLSeq : Node, name?: string): Alias;
1075
- /**
1076
- * Convert any value into a `Node` using the current schema, recursively
1077
- * turning objects into collections.
1078
- */
1079
- createNode<T = unknown>(value: T, options?: CreateNodeOptions): NodeType<T>;
1080
- createNode<T = unknown>(value: T, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): NodeType<T>;
1081
- /**
1082
- * Convert a key and a value into a `Pair` using the current schema,
1083
- * recursively wrapping all values as `Scalar` or `Collection` nodes.
1084
- */
1085
- createPair<K extends Node = Node, V extends Node = Node>(key: unknown, value: unknown, options?: CreateNodeOptions): Pair<K, V>;
1086
- /**
1087
- * Removes a value from the document.
1088
- * @returns `true` if the item was found and removed.
1089
- */
1090
- delete(key: unknown): boolean;
1091
- /**
1092
- * Removes a value from the document.
1093
- * @returns `true` if the item was found and removed.
1094
- */
1095
- deleteIn(path: Iterable<unknown> | null): boolean;
1096
- /**
1097
- * Returns item at `key`, or `undefined` if not found. By default unwraps
1098
- * scalar values from their surrounding node; to disable set `keepScalar` to
1099
- * `true` (collections are always returned intact).
1100
- */
1101
- get(key: unknown, keepScalar?: boolean): Strict extends true ? unknown : any;
1102
- /**
1103
- * Returns item at `path`, or `undefined` if not found. By default unwraps
1104
- * scalar values from their surrounding node; to disable set `keepScalar` to
1105
- * `true` (collections are always returned intact).
1106
- */
1107
- getIn(path: Iterable<unknown> | null, keepScalar?: boolean): Strict extends true ? unknown : any;
1108
- /**
1109
- * Checks if the document includes a value with the key `key`.
1110
- */
1111
- has(key: unknown): boolean;
1112
- /**
1113
- * Checks if the document includes a value at `path`.
1114
- */
1115
- hasIn(path: Iterable<unknown> | null): boolean;
1116
- /**
1117
- * Sets a value in this document. For `!!set`, `value` needs to be a
1118
- * boolean to add/remove the item from the set.
1119
- */
1120
- set(key: any, value: unknown): void;
1121
- /**
1122
- * Sets a value in this document. For `!!set`, `value` needs to be a
1123
- * boolean to add/remove the item from the set.
1124
- */
1125
- setIn(path: Iterable<unknown> | null, value: unknown): void;
1126
- /**
1127
- * Change the YAML version and schema used by the document.
1128
- * A `null` version disables support for directives, explicit tags, anchors, and aliases.
1129
- * It also requires the `schema` option to be given as a `Schema` instance value.
1130
- *
1131
- * Overrides all previously set schema options.
1132
- */
1133
- setSchema(version: '1.1' | '1.2' | 'next' | null, options?: SchemaOptions): void;
1134
- /** A plain JavaScript representation of the document `contents`. */
1135
- toJS(opt?: ToJSOptions & {
1136
- [ignored: string]: unknown;
1137
- }): any;
1138
- /**
1139
- * A JSON representation of the document `contents`.
1140
- *
1141
- * @param jsonArg Used by `JSON.stringify` to indicate the array index or
1142
- * property name.
1143
- */
1144
- toJSON(jsonArg?: string | null, onAnchor?: ToJSOptions['onAnchor']): any;
1145
- /** A YAML representation of the document. */
1146
- toString(options?: ToStringOptions): string;
1147
- }
1148
- declare class Directives {
1149
- static defaultYaml: Directives['yaml'];
1150
- static defaultTags: Directives['tags'];
1151
- yaml: {
1152
- version: '1.1' | '1.2' | 'next';
1153
- explicit?: boolean;
1154
- };
1155
- tags: Record<string, string>;
1156
- /**
1157
- * The directives-end/doc-start marker `---`. If `null`, a marker may still be
1158
- * included in the document's stringified representation.
1159
- */
1160
- docStart: true | null;
1161
- /** The doc-end marker `...`. */
1162
- docEnd: boolean;
1163
- /**
1164
- * Used when parsing YAML 1.1, where:
1165
- * > If the document specifies no directives, it is parsed using the same
1166
- * > settings as the previous document. If the document does specify any
1167
- * > directives, all directives of previous documents, if any, are ignored.
1168
- */
1169
- private atNextDocument?;
1170
- constructor(yaml?: Directives['yaml'], tags?: Directives['tags']);
1171
- clone(): Directives;
1172
- /**
1173
- * During parsing, get a Directives instance for the current document and
1174
- * update the stream state according to the current version's spec.
1175
- */
1176
- atDocument(): Directives;
1177
- /**
1178
- * @param onError - May be called even if the action was successful
1179
- * @returns `true` on success
1180
- */
1181
- add(line: string, onError: (offset: number, message: string, warning?: boolean) => void): boolean;
1182
- /**
1183
- * Resolves a tag, matching handles to those defined in %TAG directives.
1184
- *
1185
- * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
1186
- * `'!local'` tag, or `null` if unresolvable.
1187
- */
1188
- tagName(source: string, onError: (message: string) => void): string | null;
1189
- /**
1190
- * Given a fully resolved tag, returns its printable string form,
1191
- * taking into account current tag prefixes and defaults.
1192
- */
1193
- tagString(tag: string): string;
1194
- toString(doc?: Document): string;
1195
- }
1196
- /**
1197
- * Constant to check if the path is visible to the calling process.
1198
- * Corresponds to `node:fs.constants.F_OK`.
1199
- */
1200
- declare const F_OK: number;
1201
- /**
1202
- * Constant to check if the path is readable to the calling process.
1203
- * Corresponds to `node:fs.constants.R_OK`.
1204
- */
1205
- declare const R_OK: number;
1206
- /**
1207
- * Constant to check if the path is writable to the calling process.
1208
- * Corresponds to `node:fs.constants.W_OK`.
1209
- */
1210
- declare const W_OK: number;
1211
- /**
1212
- * Constant to check if the path is executable by the calling process.
1213
- * Corresponds to `node:fs.constants.X_OK`.
1214
- */
1215
- declare const X_OK: number;
1216
- /**
1217
- * A special symbol that can be returned by the matcher function in `findUp` or `findUpSync`
1218
- * to stop the search process prematurely.
1219
- */
1220
- declare const FIND_UP_STOP: symbol;
1221
- type ColorizeMethod = (value: string) => string;
1222
- /**
1223
- * Options accepted by `jsonc-parser`'s `parse` function.
1224
- */
1225
- type JsoncParseOptions = {
1226
- /**
1227
- * Allow empty content as a valid input. Defaults to `false`.
1228
- */
1229
- allowEmptyContent?: boolean;
1230
- /**
1231
- * Allow trailing commas in arrays and objects. Defaults to `false`.
1232
- */
1233
- allowTrailingComma?: boolean;
1234
- /**
1235
- * Disallow JavaScript-style comments in the input. Defaults to `false` (comments allowed).
1236
- */
1237
- disallowComments?: boolean;
1238
- };
1239
- /**
1240
- * Formatting options for `jsonc-parser` edits.
1241
- */
1242
- type JsoncFormattingOptions = {
1243
- /**
1244
- * The line ending to use in the output.
1245
- */
1246
- eol?: string;
1247
- /**
1248
- * When `true`, insert a final newline when the output does not end with one.
1249
- */
1250
- insertFinalNewline?: boolean;
1251
- /**
1252
- * Indent with spaces (`true`) or tabs (`false`). Defaults to `true`.
1253
- */
1254
- insertSpaces?: boolean;
1255
- /**
1256
- * When `true`, attempt to keep the original line structure when applying edits.
1257
- */
1258
- keepLines?: boolean;
1259
- /**
1260
- * Indent size when {@link JsoncFormattingOptions.insertSpaces | insertSpaces} is `true`.
1261
- */
1262
- tabSize?: number;
1263
- };
1264
- /**
1265
- * Options accepted by the `ini` library's `stringify` / `encode` functions.
1266
- * Kept as a local definition so the types compile without the optional peer installed.
1267
- */
1268
- type IniEncodeOptions = {
1269
- /**
1270
- * Align `=` signs across the output.
1271
- */
1272
- align?: boolean;
1273
- /**
1274
- * Serialize array values using the `key[]` convention. Defaults to `true`.
1275
- */
1276
- bracketedArray?: boolean;
1277
- /**
1278
- * Append a trailing newline to every section.
1279
- */
1280
- newline?: boolean;
1281
- /**
1282
- * Target platform for section/key escaping. Defaults to the current platform.
1283
- */
1284
- platform?: string;
1285
- /**
1286
- * Name of the top-level section.
1287
- */
1288
- section?: string;
1289
- /**
1290
- * Sort keys alphabetically within sections.
1291
- */
1292
- sort?: boolean;
1293
- /**
1294
- * Write `key = value` with spaces around `=`. Defaults to `false`.
1295
- */
1296
- whitespace?: boolean;
1297
- };
1298
- /**
1299
- * Replacer accepted by `JSON5.stringify()`.
1300
- */
1301
- type Json5Replacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
1302
- /**
1303
- * Options for the `glob` and `globSync` functions.
1304
- *
1305
- * Re-exported from [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) (which is bundled into the built
1306
- * output, with a local patch adding negated-ignore support). The `ignore` option accepts leading-`!` patterns to
1307
- * _un-ignore_ entries — for example `ignore: ["dist/**", "!dist/index.d.ts"]` drops the `dist/` tree except for
1308
- * its type entry point.
1309
- */
1310
- type GlobOptions = Omit<GlobOptions$1, "patterns">;
1311
- /**
1312
- * Options for the `walk` and `walkSync` functions.
1313
- */
1314
- interface WalkOptions {
1315
- /**
1316
- * List of file extensions used to filter entries.
1317
- * If specified, entries without the file extension specified by this option are excluded.
1318
- * @default {undefined}
1319
- */
1320
- extensions?: string[];
1321
- /**
1322
- * Indicates whether symlinks should be resolved or not.
1323
- * @default {false}
1324
- */
1325
- followSymlinks?: boolean;
1326
- /**
1327
- * Indicates whether directory entries should be included or not.
1328
- * @default {true}
1329
- */
1330
- includeDirs?: boolean;
1331
- /**
1332
- * Indicates whether file entries should be included or not.
1333
- * @default {true}
1334
- */
1335
- includeFiles?: boolean;
1336
- /**
1337
- * Indicates whether symlink entries should be included or not.
1338
- * This option is meaningful only if `followSymlinks` is set to `false`.
1339
- * @default {true}
1340
- */
1341
- includeSymlinks?: boolean;
1342
- /**
1343
- * List of regular expression or glob patterns used to filter entries.
1344
- * If specified, entries that do not match the patterns specified by this option are excluded.
1345
- * @default {undefined}
1346
- */
1347
- match?: (RegExp | string)[];
1348
- /**
1349
- * The maximum depth of the file tree to be walked recursively.
1350
- * @default {Infinity}
1351
- */
1352
- maxDepth?: number;
1353
- /**
1354
- * List of regular expression or glob patterns used to filter entries.
1355
- * If specified, entries matching the patterns specified by this option are excluded.
1356
- * @default {undefined}
1357
- */
1358
- skip?: (RegExp | string)[];
1359
- }
1360
- /**
1361
- * Represents an entry found by `walk` or `walkSync`.
1362
- */
1363
- interface WalkEntry extends Pick<Dirent, "isDirectory" | "isFile" | "isSymbolicLink" | "name"> {
1364
- /** The full path to the entry. */
1365
- path: string;
1366
- }
1367
- /**
1368
- * Supported compression types for file operations.
1369
- */
1370
- type CompressionType = "brotli" | "gzip" | "none";
1371
- /**
1372
- * Supported file encodings for reading files.
1373
- */
1374
- type ReadFileEncoding = "ascii" | "base64" | "base64url" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf-8" | "utf-16le" | "utf8" | "utf16le";
1375
- /**
1376
- * Options for reading files.
1377
- */
1378
- type ReadFileOptions<C> = {
1379
- /**
1380
- * Return content as a Buffer. Default: `false`
1381
- */
1382
- buffer?: boolean;
1383
- /**
1384
- * Compression method to decompress the file against. Default: `none`
1385
- */
1386
- compression?: C;
1387
- /**
1388
- * The encoding to use. Default: `utf8`
1389
- * @see https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
1390
- */
1391
- encoding?: ReadFileEncoding;
1392
- /**
1393
- * The flag used to open the file. Default: `r`
1394
- */
1395
- flag?: number | string;
1396
- };
1397
- /**
1398
- * Represents the content type of a read file, which can be a Buffer or a string based on options.
1399
- * @template O - The ReadFileOptions type.
1400
- */
1401
- type ContentType<O = undefined> = O extends {
1402
- buffer: true;
1403
- } ? Buffer : string;
1404
- /**
1405
- * Type for the `reviver` parameter of `JSON.parse()`.
1406
- * A function that transforms the results. This function is called for each member of the object.
1407
- * If a member contains nested objects, the nested objects are transformed before the parent object is.
1408
- */
1409
- type JsonReviver = Parameters<(typeof JSON)["parse"]>["1"];
1410
- /**
1411
- * Specifies a location (line and column) in a file for code frame generation.
1412
- */
1413
- type CodeFrameLocation = {
1414
- /** The column number. */
1415
- column?: number;
1416
- /** The line number. */
1417
- line: number;
1418
- };
1419
- /**
1420
- * Options for customizing the appearance of code frames.
1421
- */
1422
- type CodeFrameOptions = {
1423
- /** Colorization methods for different parts of the code frame. */
1424
- color?: {
1425
- /** Color for the gutter (line numbers). */
1426
- gutter?: ColorizeMethod;
1427
- /** Color for the marker (pointing to the error). */
1428
- marker?: ColorizeMethod;
1429
- /** Color for the message. */
1430
- message?: ColorizeMethod;
1431
- };
1432
- };
1433
- /**
1434
- * Options for reading and parsing JSON files.
1435
- * Extends {@link CodeFrameOptions}.
1436
- */
1437
- type ReadJsonOptions = CodeFrameOptions & {
1438
- /**
1439
- * A function to transform the string content before parsing.
1440
- * @param source The raw string content of the file.
1441
- * @returns The transformed string content.
1442
- */
1443
- beforeParse?: (source: string) => string;
1444
- };
1445
- /**
1446
- * Options for writing files.
1447
- */
1448
- type WriteFileOptions = {
1449
- /**
1450
- * When `true` and the target file already exists, the previous contents are
1451
- * preserved by renaming the existing file to `${path}.bak` before the new
1452
- * contents are written. This is independent of {@link WriteFileOptions.overwrite}.
1453
- *
1454
- * Default: `false`
1455
- */
1456
- backup?: boolean;
1457
- /**
1458
- * The group and user ID used to set the file ownership. Default: `undefined`
1459
- */
1460
- chown?: {
1461
- gid: number;
1462
- uid: number;
1463
- };
1464
- /**
1465
- * The encoding to use. Default: `utf8`
1466
- */
1467
- encoding?: BufferEncoding | null;
1468
- /**
1469
- * The flag used to write the file. Append flags (containing `a`) concatenate
1470
- * the new contents onto the existing file; exclusive flags (containing `x`)
1471
- * throw an `AlreadyExistsError` when the file already exists. Default: `w`
1472
- */
1473
- flag?: string;
1474
- /**
1475
- * The file mode (permission and sticky bits). Default: `0o666`
1476
- */
1477
- mode?: number;
1478
- /**
1479
- * Indicates whether the file should be overwritten if it already exists.
1480
- * When `false` and the target already exists, an `AlreadyExistsError` is thrown.
1481
- *
1482
- * Default: `true`
1483
- */
1484
- overwrite?: boolean;
1485
- /**
1486
- * Recursively create parent directories if needed. Default: `true`
1487
- */
1488
- recursive?: boolean;
1489
- };
1490
- /**
1491
- * Type for the `replacer` parameter of `JSON.stringify()`.
1492
- * Can be a function that alters the behavior of the stringification process,
1493
- * or an array of strings and numbers that acts as a whitelist for selecting
1494
- * the properties of the value object to be included in the JSON string.
1495
- * If this value is null or not provided, all properties of the object are included in the resulting JSON string.
1496
- */
1497
- type JsonReplacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null;
1498
- /**
1499
- * Type for the `replacer` parameter used in YAML serialization, similar to `JSON.stringify`'s replacer.
1500
- * @deprecated Use {@link JsonReplacer} directly instead.
1501
- */
1502
- type YamlReplacer = JsonReplacer;
1503
- /**
1504
- * Options for writing JSON files.
1505
- * Extends {@link WriteFileOptions}.
1506
- */
1507
- type WriteJsonOptions = WriteFileOptions & {
1508
- /**
1509
- * Detect indentation automatically if the file exists. Default: `false`
1510
- */
1511
- detectIndent?: boolean;
1512
- /**
1513
- * The space used for pretty-printing.
1514
- *
1515
- * Pass in `undefined` for no formatting.
1516
- */
1517
- indent?: number | string;
1518
- /**
1519
- * Passed into `JSON.stringify`.
1520
- */
1521
- replacer?: JsonReplacer;
1522
- /**
1523
- * Override the default `JSON.stringify` method.
1524
- */
1525
- stringify?: (data: unknown, replacer: JsonReplacer, space: number | string | undefined) => string;
1526
- };
1527
- /**
1528
- * Options for the `findUp` and `findUpSync` functions.
1529
- */
1530
- type FindUpOptions = {
1531
- /**
1532
- * Whether to follow symbolic links.
1533
- * @default undefined (behaves like `true` for `findUp`, `false` for `findUpSync` due to `fs.stat` vs `fs.lstat`)
1534
- */
1535
- allowSymlinks?: boolean;
1536
- /**
1537
- * The current working directory.
1538
- * @default process.cwd()
1539
- */
1540
- cwd?: URL | string;
1541
- /**
1542
- * The directory to stop searching at.
1543
- * @default path.parse(cwd).root
1544
- */
1545
- stopAt?: URL | string;
1546
- /**
1547
- * The type of path to find.
1548
- * @default "file"
1549
- */
1550
- type?: "directory" | "file";
1551
- };
1552
- /**
1553
- * The result type for the name matcher function used in `findUp`.
1554
- * It can be a `PathLike` (string, Buffer, or URL), a Promise resolving to `PathLike` or `FIND_UP_STOP`,
1555
- * `FIND_UP_STOP` to stop the search, or `undefined` to continue.
1556
- */
1557
- type FindUpNameFnResult = PathLike | Promise<PathLike | typeof FIND_UP_STOP> | typeof FIND_UP_STOP | undefined;
1558
- /**
1559
- * Specifies the name(s) of the file or directory to search for in `findUp`.
1560
- * Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
1561
- */
1562
- type FindUpName = string[] | string | ((directory: string) => FindUpNameFnResult);
1563
- /**
1564
- * The result type for the name matcher function used in `findUpSync`.
1565
- * It can be a `PathLike` (string, Buffer, or URL), `FIND_UP_STOP` to stop the search,
1566
- * or `undefined` to continue.
1567
- */
1568
- type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined;
1569
- /**
1570
- * Specifies the name(s) of the file or directory to search for in `findUpSync`.
1571
- * Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
1572
- */
1573
- type FindUpNameSync = string[] | string | ((directory: string) => FindUpNameSyncFnResult);
1574
- /**
1575
- * Options for operations that might require retries, like `emptyDir` or `remove`.
1576
- */
1577
- type RetryOptions = {
1578
- /**
1579
- * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1580
- * `EPERM` error is encountered, Node.js will retry the operation with a linear
1581
- * backoff wait of `retryDelay` ms longer on each try. This option represents the
1582
- * number of retries. This option is ignored if the `recursive` option is not
1583
- * `true` for operations that support it (like `rm`).
1584
- * @default 0
1585
- */
1586
- maxRetries?: number;
1587
- /**
1588
- * The amount of time in milliseconds to wait between retries.
1589
- * This option is ignored if the `recursive` option is not `true` for operations that support it.
1590
- * @default 100
1591
- */
1592
- retryDelay?: number;
1593
- };
1594
- /**
1595
- * Options for reading YAML files.
1596
- * Combines options from `yaml` library (DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions)
1597
- * and custom {@link ReadFileOptions}.
1598
- */
1599
- type ReadYamlOptions<C> = DocumentOptions & ParseOptions & ReadFileOptions<C> & SchemaOptions & ToJSOptions;
1600
- /**
1601
- * Type for the `reviver` parameter used in YAML deserialization, similar to `JSON.parse`'s reviver.
1602
- * A function that transforms the results. This function is called for each member of the object.
1603
- * If a member contains nested objects, the nested objects are transformed before the parent object is.
1604
- */
1605
- type YamlReviver = (key: unknown, value: unknown) => unknown;
1606
- /**
1607
- * Options for writing YAML files.
1608
- * Extends {@link WriteFileOptions} and includes options from the `yaml` library for stringification.
1609
- */
1610
- type WriteYamlExtras = {
1611
- /**
1612
- * Passed into `yaml.stringify` as the replacer argument.
1613
- */
1614
- replacer?: JsonReplacer;
1615
- /**
1616
- * Passed into `yaml.stringify` as the space argument for indentation.
1617
- * Can be a number of spaces or a string (e.g., a tab character).
1618
- */
1619
- space?: number | string;
1620
- };
1621
- type WriteYamlOptions = CreateNodeOptions & DocumentOptions & ParseOptions & SchemaOptions & ToStringOptions & WriteFileOptions & WriteYamlExtras;
1622
- /**
1623
- * Options for reading TOML files.
1624
- * Uses `smol-toml`, which does not expose additional parse options.
1625
- */
1626
- type ReadTomlOptions<C> = ReadFileOptions<C>;
1627
- /**
1628
- * Options for writing TOML files.
1629
- * Extends {@link WriteFileOptions}. `smol-toml` does not expose additional stringify options.
1630
- */
1631
- type WriteTomlOptions = WriteFileOptions;
1632
- /**
1633
- * Extra options for JSONC parsing on top of file-reading and code-frame options.
1634
- */
1635
- type ReadJsoncExtras = {
1636
- /**
1637
- * A function to transform the string content before parsing.
1638
- * @param source The raw string content of the file.
1639
- * @returns The transformed string content.
1640
- */
1641
- beforeParse?: (source: string) => string;
1642
- };
1643
- /**
1644
- * Options for reading JSONC (JSON with comments) files.
1645
- * Combines options from `jsonc-parser` and custom {@link ReadFileOptions} and {@link CodeFrameOptions}.
1646
- */
1647
- type ReadJsoncOptions<C> = CodeFrameOptions & JsoncParseOptions & ReadFileOptions<C> & ReadJsoncExtras;
1648
- /**
1649
- * Options for writing JSONC files with optional comment preservation.
1650
- * Extends {@link WriteFileOptions}.
1651
- */
1652
- type WriteJsoncOptions = WriteFileOptions & {
1653
- /**
1654
- * Detect indentation automatically if the file exists. Default: `false`.
1655
- */
1656
- detectIndent?: boolean;
1657
- /**
1658
- * Formatting options forwarded to `jsonc-parser` when modifying existing files.
1659
- */
1660
- formattingOptions?: JsoncFormattingOptions;
1661
- /**
1662
- * Indentation used when writing a fresh file (no existing file to preserve).
1663
- * Default: `"\t"`.
1664
- */
1665
- indent?: number | string;
1666
- /**
1667
- * When `true` and the file already exists, preserve existing comments and formatting
1668
- * by computing a minimal diff against the new data via `jsonc-parser`'s `modify` API. Default: `true`.
1669
- */
1670
- preserveComments?: boolean;
1671
- /**
1672
- * Passed into `JSON.stringify` when writing a fresh file.
1673
- */
1674
- replacer?: JsonReplacer;
1675
- };
1676
- /**
1677
- * Type for the `reviver` parameter of `JSON5.parse()`.
1678
- */
1679
- type Json5Reviver = (this: unknown, key: string, value: unknown) => unknown;
1680
- /**
1681
- * Extra options for JSON5 parsing on top of file-reading and code-frame options.
1682
- */
1683
- type ReadJson5Extras = {
1684
- /**
1685
- * A function to transform the string content before parsing.
1686
- */
1687
- beforeParse?: (source: string) => string;
1688
- };
1689
- /**
1690
- * Options for reading JSON5 files.
1691
- */
1692
- type ReadJson5Options<C> = CodeFrameOptions & ReadFileOptions<C> & ReadJson5Extras;
1693
- /**
1694
- * Options for writing JSON5 files.
1695
- * Extends {@link WriteFileOptions}.
1696
- */
1697
- type WriteJson5Options = WriteFileOptions & {
1698
- /**
1699
- * Detect indentation automatically if the file exists. Default: `false`.
1700
- */
1701
- detectIndent?: boolean;
1702
- /**
1703
- * Indentation for pretty-printing.
1704
- */
1705
- indent?: number | string;
1706
- /**
1707
- * Override the quote character used for strings. See `JSON5.stringify`.
1708
- */
1709
- quote?: string;
1710
- /**
1711
- * Passed into `JSON5.stringify`.
1712
- */
1713
- replacer?: Json5Replacer;
1714
- };
1715
- /**
1716
- * Options for reading INI files.
1717
- */
1718
- type ReadIniOptions<C> = ReadFileOptions<C> & {
1719
- /**
1720
- * Parse array values (keys ending with `[]`) into native arrays. Default: `true`.
1721
- */
1722
- bracketedArray?: boolean;
1723
- };
1724
- /**
1725
- * Supported INI line-ending values.
1726
- */
1727
- type IniLineEnding = "\n" | "\r\n";
1728
- /**
1729
- * Extra options for INI writing on top of the `ini` encoder options and file-writing options.
1730
- */
1731
- type WriteIniExtras = {
1732
- /**
1733
- * Line ending to write. When omitted and {@link WriteIniOptions.preserveStyle | preserveStyle} is `true`,
1734
- * the line ending is auto-detected from the existing file. Falls back to `"\n"` otherwise.
1735
- */
1736
- eol?: IniLineEnding;
1737
- /**
1738
- * When `true` and the file already exists, auto-detect and preserve styling described on this type.
1739
- * Defaults to `true`. Explicit `whitespace` / `eol` values always win over detection.
1740
- */
1741
- preserveStyle?: boolean;
1742
- };
1743
- /**
1744
- * Options for writing INI files.
1745
- *
1746
- * Extends {@link WriteFileOptions} and `ini`'s {@link IniEncodeOptions}. When an existing file is present and
1747
- * {@link WriteIniOptions.preserveStyle | preserveStyle} is `true` (the default), the following styling is
1748
- * detected from that file and applied unless overridden: space around `=` (via {@link IniEncodeOptions.whitespace | whitespace}),
1749
- * line ending (via {@link WriteIniOptions.eol | eol}), and per-key original lines (including trailing
1750
- * whitespace and inline `;` / `#` comments) for unchanged values.
1751
- */
1752
- type WriteIniOptions = IniEncodeOptions & WriteFileOptions & WriteIniExtras;
1753
- export { CodeFrameLocation as A, FIND_UP_STOP as B, CompressionType as C, F_OK as D, FindUpNameFnResult as E, FindUpName as F, GlobOptions as G, FindUpNameSyncFnResult as H, IniEncodeOptions as I, Json5Reviver as J, R_OK as K, ReadFileEncoding as L, W_OK as M, ReadIniOptions as R, WriteIniOptions as W, X_OK as X, YamlReviver as Y, IniLineEnding as a, ReadJson5Options as b, WriteJson5Options as c, Json5Replacer as d, ReadJsoncOptions as e, WriteJsoncOptions as f, JsoncFormattingOptions as g, JsoncParseOptions as h, ReadTomlOptions as i, WriteTomlOptions as j, CodeFrameOptions as k, JsonReviver as l, ReadYamlOptions as m, WriteYamlOptions as n, JsonReplacer as o, YamlReplacer as p, WalkOptions as q, FindUpOptions as r, FindUpNameSync as s, WalkEntry as t, ReadFileOptions as u, ContentType as v, ReadJsonOptions as w, RetryOptions as x, WriteFileOptions as y, WriteJsonOptions as z };