@socketsecurity/lib 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
package/dist/fs.d.ts CHANGED
@@ -6,128 +6,534 @@ import type { Abortable } from 'node:events';
6
6
  import type { ObjectEncodingOptions, OpenMode, PathLike } from 'node:fs';
7
7
  import type { JsonReviver } from './json';
8
8
  import { type Remap } from './objects';
9
- // Type definitions
9
+ /**
10
+ * Supported text encodings for Node.js Buffers.
11
+ * Includes ASCII, UTF-8/16, base64, binary, and hexadecimal encodings.
12
+ */
10
13
  export type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
14
+ /**
15
+ * Represents any valid JSON content type.
16
+ */
11
17
  export type JsonContent = unknown;
18
+ /**
19
+ * Options for asynchronous `findUp` operations.
20
+ */
12
21
  export interface FindUpOptions {
13
- cwd?: string;
14
- onlyDirectories?: boolean;
15
- onlyFiles?: boolean;
16
- signal?: AbortSignal;
22
+ /**
23
+ * Starting directory for the search.
24
+ * @default process.cwd()
25
+ */
26
+ cwd?: string | undefined;
27
+ /**
28
+ * Only match directories, not files.
29
+ * @default false
30
+ */
31
+ onlyDirectories?: boolean | undefined;
32
+ /**
33
+ * Only match files, not directories.
34
+ * @default true
35
+ */
36
+ onlyFiles?: boolean | undefined;
37
+ /**
38
+ * Abort signal to cancel the search operation.
39
+ */
40
+ signal?: AbortSignal | undefined;
17
41
  }
42
+ /**
43
+ * Options for synchronous `findUpSync` operations.
44
+ */
18
45
  export interface FindUpSyncOptions {
19
- cwd?: string;
20
- stopAt?: string;
21
- onlyDirectories?: boolean;
22
- onlyFiles?: boolean;
46
+ /**
47
+ * Starting directory for the search.
48
+ * @default process.cwd()
49
+ */
50
+ cwd?: string | undefined;
51
+ /**
52
+ * Directory to stop searching at (inclusive).
53
+ * When provided, search will stop at this directory even if the root hasn't been reached.
54
+ */
55
+ stopAt?: string | undefined;
56
+ /**
57
+ * Only match directories, not files.
58
+ * @default false
59
+ */
60
+ onlyDirectories?: boolean | undefined;
61
+ /**
62
+ * Only match files, not directories.
63
+ * @default true
64
+ */
65
+ onlyFiles?: boolean | undefined;
23
66
  }
67
+ /**
68
+ * Options for checking if a directory is empty.
69
+ */
24
70
  export interface IsDirEmptyOptions {
71
+ /**
72
+ * Glob patterns for files to ignore when checking emptiness.
73
+ * Files matching these patterns are not counted.
74
+ * @default defaultIgnore
75
+ */
25
76
  ignore?: string[] | readonly string[] | undefined;
26
77
  }
78
+ /**
79
+ * Options for read operations with abort support.
80
+ */
27
81
  export interface ReadOptions extends Abortable {
28
- encoding?: BufferEncoding | string;
29
- flag?: string;
82
+ /**
83
+ * Character encoding to use for reading.
84
+ * @default 'utf8'
85
+ */
86
+ encoding?: BufferEncoding | string | undefined;
87
+ /**
88
+ * File system flag for reading behavior.
89
+ * @default 'r'
90
+ */
91
+ flag?: string | undefined;
30
92
  }
93
+ /**
94
+ * Options for reading directories with filtering and sorting.
95
+ */
31
96
  export interface ReadDirOptions {
97
+ /**
98
+ * Glob patterns for directories to ignore.
99
+ * @default undefined
100
+ */
32
101
  ignore?: string[] | readonly string[] | undefined;
102
+ /**
103
+ * Include empty directories in results.
104
+ * When `false`, empty directories are filtered out.
105
+ * @default true
106
+ */
33
107
  includeEmpty?: boolean | undefined;
108
+ /**
109
+ * Sort directory names alphabetically using natural sort order.
110
+ * @default true
111
+ */
34
112
  sort?: boolean | undefined;
35
113
  }
114
+ /**
115
+ * Options for reading files with encoding and abort support.
116
+ * Can be either an options object, an encoding string, or null.
117
+ */
36
118
  export type ReadFileOptions = Remap<ObjectEncodingOptions & Abortable & {
37
119
  flag?: OpenMode | undefined;
38
120
  }> | BufferEncoding | null;
121
+ /**
122
+ * Options for reading and parsing JSON files.
123
+ */
39
124
  export type ReadJsonOptions = Remap<ReadFileOptions & {
125
+ /**
126
+ * Whether to throw errors on parse failure.
127
+ * When `false`, returns `undefined` on error instead of throwing.
128
+ * @default true
129
+ */
40
130
  throws?: boolean | undefined;
41
- reviver?: Parameters<typeof JSON.parse>[1];
131
+ /**
132
+ * JSON reviver function to transform parsed values.
133
+ * Same as the second parameter to `JSON.parse()`.
134
+ */
135
+ reviver?: Parameters<typeof JSON.parse>[1] | undefined;
42
136
  }>;
137
+ /**
138
+ * Options for file/directory removal operations.
139
+ */
43
140
  export interface RemoveOptions {
44
- force?: boolean;
45
- maxRetries?: number;
46
- recursive?: boolean;
47
- retryDelay?: number;
48
- signal?: AbortSignal;
141
+ /**
142
+ * Force deletion even outside normally safe directories.
143
+ * When `false`, prevents deletion outside temp, cacache, and ~/.socket.
144
+ * @default true for safe directories, false otherwise
145
+ */
146
+ force?: boolean | undefined;
147
+ /**
148
+ * Maximum number of retry attempts on failure.
149
+ * @default 3
150
+ */
151
+ maxRetries?: number | undefined;
152
+ /**
153
+ * Recursively delete directories and contents.
154
+ * @default true
155
+ */
156
+ recursive?: boolean | undefined;
157
+ /**
158
+ * Delay in milliseconds between retry attempts.
159
+ * @default 200
160
+ */
161
+ retryDelay?: number | undefined;
162
+ /**
163
+ * Abort signal to cancel the operation.
164
+ */
165
+ signal?: AbortSignal | undefined;
49
166
  }
167
+ /**
168
+ * Options for safe read operations that don't throw on errors.
169
+ */
50
170
  export interface SafeReadOptions extends ReadOptions {
51
- defaultValue?: unknown;
171
+ /**
172
+ * Default value to return on read failure.
173
+ * If not provided, `undefined` is returned on error.
174
+ */
175
+ defaultValue?: unknown | undefined;
52
176
  }
177
+ /**
178
+ * Options for write operations with encoding and mode control.
179
+ */
53
180
  export interface WriteOptions extends Abortable {
54
- encoding?: BufferEncoding | string;
55
- mode?: number;
56
- flag?: string;
181
+ /**
182
+ * Character encoding for writing.
183
+ * @default 'utf8'
184
+ */
185
+ encoding?: BufferEncoding | string | undefined;
186
+ /**
187
+ * File mode (permissions) to set.
188
+ * Uses standard Unix permission bits (e.g., 0o644).
189
+ * @default 0o666 (read/write for all, respecting umask)
190
+ */
191
+ mode?: number | undefined;
192
+ /**
193
+ * File system flag for write behavior.
194
+ * @default 'w' (create or truncate)
195
+ */
196
+ flag?: string | undefined;
57
197
  }
198
+ /**
199
+ * Options for writing JSON files with formatting control.
200
+ */
58
201
  export interface WriteJsonOptions extends WriteOptions {
202
+ /**
203
+ * End-of-line sequence to use.
204
+ * @default '\n'
205
+ * @example
206
+ * ```ts
207
+ * // Windows-style line endings
208
+ * writeJson('data.json', data, { EOL: '\r\n' })
209
+ * ```
210
+ */
59
211
  EOL?: string | undefined;
212
+ /**
213
+ * Whether to add a final newline at end of file.
214
+ * @default true
215
+ */
60
216
  finalEOL?: boolean | undefined;
217
+ /**
218
+ * JSON replacer function to transform values during stringification.
219
+ * Same as the second parameter to `JSON.stringify()`.
220
+ */
61
221
  replacer?: JsonReviver | undefined;
222
+ /**
223
+ * Number of spaces for indentation, or string to use for indentation.
224
+ * @default 2
225
+ * @example
226
+ * ```ts
227
+ * // Use tabs instead of spaces
228
+ * writeJson('data.json', data, { spaces: '\t' })
229
+ *
230
+ * // Use 4 spaces for indentation
231
+ * writeJson('data.json', data, { spaces: 4 })
232
+ * ```
233
+ */
62
234
  spaces?: number | string | undefined;
63
235
  }
64
236
  /**
65
237
  * Find a file or directory by traversing up parent directories.
238
+ * Searches from the starting directory upward to the filesystem root.
239
+ * Useful for finding configuration files or project roots.
240
+ *
241
+ * @param name - Filename(s) to search for
242
+ * @param options - Search options including cwd and type filters
243
+ * @returns Normalized absolute path if found, undefined otherwise
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * // Find package.json starting from current directory
248
+ * const pkgPath = await findUp('package.json')
249
+ *
250
+ * // Find any of multiple config files
251
+ * const configPath = await findUp(['.config.js', '.config.json'])
252
+ *
253
+ * // Find a directory instead of file
254
+ * const nodeModules = await findUp('node_modules', { onlyDirectories: true })
255
+ * ```
66
256
  */
67
257
  /*@__NO_SIDE_EFFECTS__*/
68
258
  export declare function findUp(name: string | string[] | readonly string[], options?: FindUpOptions | undefined): Promise<string | undefined>;
69
259
  /**
70
260
  * Synchronously find a file or directory by traversing up parent directories.
261
+ * Searches from the starting directory upward to the filesystem root or `stopAt` directory.
262
+ * Useful for finding configuration files or project roots in synchronous contexts.
263
+ *
264
+ * @param name - Filename(s) to search for
265
+ * @param options - Search options including cwd, stopAt, and type filters
266
+ * @returns Normalized absolute path if found, undefined otherwise
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * // Find package.json starting from current directory
271
+ * const pkgPath = findUpSync('package.json')
272
+ *
273
+ * // Find .git directory but stop at home directory
274
+ * const gitPath = findUpSync('.git', {
275
+ * onlyDirectories: true,
276
+ * stopAt: process.env.HOME
277
+ * })
278
+ *
279
+ * // Find any of multiple config files
280
+ * const configPath = findUpSync(['.eslintrc.js', '.eslintrc.json'])
281
+ * ```
71
282
  */
72
283
  /*@__NO_SIDE_EFFECTS__*/
73
284
  export declare function findUpSync(name: string | string[] | readonly string[], options?: FindUpSyncOptions | undefined): string;
74
285
  /**
75
286
  * Check if a path is a directory asynchronously.
287
+ * Returns `true` for directories, `false` for files or non-existent paths.
288
+ *
289
+ * @param filepath - Path to check
290
+ * @returns `true` if path is a directory, `false` otherwise
291
+ *
292
+ * @example
293
+ * ```ts
294
+ * if (await isDir('./src')) {
295
+ * console.log('src is a directory')
296
+ * }
297
+ * ```
76
298
  */
77
299
  /*@__NO_SIDE_EFFECTS__*/
78
300
  export declare function isDir(filepath: PathLike): Promise<boolean>;
79
301
  /**
80
302
  * Check if a path is a directory synchronously.
303
+ * Returns `true` for directories, `false` for files or non-existent paths.
304
+ *
305
+ * @param filepath - Path to check
306
+ * @returns `true` if path is a directory, `false` otherwise
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * if (isDirSync('./src')) {
311
+ * console.log('src is a directory')
312
+ * }
313
+ * ```
81
314
  */
82
315
  /*@__NO_SIDE_EFFECTS__*/
83
316
  export declare function isDirSync(filepath: PathLike): boolean;
84
317
  /**
85
318
  * Check if a directory is empty synchronously.
319
+ * A directory is considered empty if it contains no files after applying ignore patterns.
320
+ * Uses glob patterns to filter ignored files.
321
+ *
322
+ * @param dirname - Directory path to check
323
+ * @param options - Options including ignore patterns
324
+ * @returns `true` if directory is empty (or doesn't exist), `false` otherwise
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * // Check if directory is completely empty
329
+ * isDirEmptySync('./build')
330
+ *
331
+ * // Check if directory is empty, ignoring .DS_Store files
332
+ * isDirEmptySync('./cache', { ignore: ['.DS_Store'] })
333
+ * ```
86
334
  */
87
335
  /*@__NO_SIDE_EFFECTS__*/
88
336
  export declare function isDirEmptySync(dirname: PathLike, options?: IsDirEmptyOptions | undefined): boolean;
89
337
  /**
90
338
  * Check if a path is a symbolic link synchronously.
339
+ * Uses `lstat` to check the link itself, not the target.
340
+ *
341
+ * @param filepath - Path to check
342
+ * @returns `true` if path is a symbolic link, `false` otherwise
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * if (isSymLinkSync('./my-link')) {
347
+ * console.log('Path is a symbolic link')
348
+ * }
349
+ * ```
91
350
  */
92
351
  /*@__NO_SIDE_EFFECTS__*/
93
352
  export declare function isSymLinkSync(filepath: PathLike): boolean;
94
353
  /**
95
354
  * Read directory names asynchronously with filtering and sorting.
355
+ * Returns only directory names (not files), with optional filtering for empty directories
356
+ * and glob-based ignore patterns. Results are naturally sorted by default.
357
+ *
358
+ * @param dirname - Directory path to read
359
+ * @param options - Options for filtering and sorting
360
+ * @returns Array of directory names, empty array on error
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * // Get all subdirectories, sorted naturally
365
+ * const dirs = await readDirNames('./packages')
366
+ *
367
+ * // Get non-empty directories only
368
+ * const nonEmpty = await readDirNames('./cache', { includeEmpty: false })
369
+ *
370
+ * // Get directories without sorting
371
+ * const unsorted = await readDirNames('./src', { sort: false })
372
+ * ```
96
373
  */
97
374
  /*@__NO_SIDE_EFFECTS__*/
98
375
  export declare function readDirNames(dirname: PathLike, options?: ReadDirOptions | undefined): Promise<string[]>;
99
376
  /**
100
377
  * Read directory names synchronously with filtering and sorting.
378
+ * Returns only directory names (not files), with optional filtering for empty directories
379
+ * and glob-based ignore patterns. Results are naturally sorted by default.
380
+ *
381
+ * @param dirname - Directory path to read
382
+ * @param options - Options for filtering and sorting
383
+ * @returns Array of directory names, empty array on error
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * // Get all subdirectories, sorted naturally
388
+ * const dirs = readDirNamesSync('./packages')
389
+ *
390
+ * // Get non-empty directories only, ignoring node_modules
391
+ * const nonEmpty = readDirNamesSync('./src', {
392
+ * includeEmpty: false,
393
+ * ignore: ['node_modules']
394
+ * })
395
+ * ```
101
396
  */
102
397
  /*@__NO_SIDE_EFFECTS__*/
103
398
  export declare function readDirNamesSync(dirname: PathLike, options?: ReadDirOptions): string[];
104
399
  /**
105
400
  * Read a file as binary data asynchronously.
401
+ * Returns a Buffer without encoding the contents.
402
+ * Useful for reading images, archives, or other binary formats.
403
+ *
404
+ * @param filepath - Path to file
405
+ * @param options - Read options (encoding is forced to null for binary)
406
+ * @returns Promise resolving to Buffer containing file contents
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * // Read an image file
411
+ * const imageBuffer = await readFileBinary('./image.png')
412
+ *
413
+ * // Read with abort signal
414
+ * const buffer = await readFileBinary('./data.bin', { signal: abortSignal })
415
+ * ```
106
416
  */
107
417
  /*@__NO_SIDE_EFFECTS__*/
108
418
  export declare function readFileBinary(filepath: PathLike, options?: ReadFileOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
109
419
  /**
110
420
  * Read a file as UTF-8 text asynchronously.
421
+ * Returns a string with the file contents decoded as UTF-8.
422
+ * This is the most common way to read text files.
423
+ *
424
+ * @param filepath - Path to file
425
+ * @param options - Read options including encoding and abort signal
426
+ * @returns Promise resolving to string containing file contents
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * // Read a text file
431
+ * const content = await readFileUtf8('./README.md')
432
+ *
433
+ * // Read with custom encoding
434
+ * const content = await readFileUtf8('./data.txt', { encoding: 'utf-8' })
435
+ * ```
111
436
  */
112
437
  /*@__NO_SIDE_EFFECTS__*/
113
438
  export declare function readFileUtf8(filepath: PathLike, options?: ReadFileOptions | undefined): Promise<string>;
114
439
  /**
115
440
  * Read a file as binary data synchronously.
441
+ * Returns a Buffer without encoding the contents.
442
+ * Useful for reading images, archives, or other binary formats.
443
+ *
444
+ * @param filepath - Path to file
445
+ * @param options - Read options (encoding is forced to null for binary)
446
+ * @returns Buffer containing file contents
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * // Read an image file
451
+ * const imageBuffer = readFileBinarySync('./logo.png')
452
+ *
453
+ * // Read a compressed file
454
+ * const gzipData = readFileBinarySync('./archive.gz')
455
+ * ```
116
456
  */
117
457
  /*@__NO_SIDE_EFFECTS__*/
118
458
  export declare function readFileBinarySync(filepath: PathLike, options?: ReadFileOptions | undefined): string | NonSharedBuffer;
119
459
  /**
120
460
  * Read a file as UTF-8 text synchronously.
461
+ * Returns a string with the file contents decoded as UTF-8.
462
+ * This is the most common way to read text files synchronously.
463
+ *
464
+ * @param filepath - Path to file
465
+ * @param options - Read options including encoding
466
+ * @returns String containing file contents
467
+ *
468
+ * @example
469
+ * ```ts
470
+ * // Read a configuration file
471
+ * const config = readFileUtf8Sync('./config.txt')
472
+ *
473
+ * // Read with custom options
474
+ * const data = readFileUtf8Sync('./data.txt', { encoding: 'utf8' })
475
+ * ```
121
476
  */
122
477
  /*@__NO_SIDE_EFFECTS__*/
123
478
  export declare function readFileUtf8Sync(filepath: PathLike, options?: ReadFileOptions | undefined): string | NonSharedBuffer;
124
479
  /**
125
480
  * Read and parse a JSON file asynchronously.
481
+ * Reads the file as UTF-8 text and parses it as JSON.
482
+ * Optionally accepts a reviver function to transform parsed values.
483
+ *
484
+ * @param filepath - Path to JSON file
485
+ * @param options - Read and parse options
486
+ * @returns Promise resolving to parsed JSON value, or undefined if throws is false and an error occurs
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * // Read and parse package.json
491
+ * const pkg = await readJson('./package.json')
492
+ *
493
+ * // Read JSON with custom reviver
494
+ * const data = await readJson('./data.json', {
495
+ * reviver: (key, value) => {
496
+ * if (key === 'date') return new Date(value)
497
+ * return value
498
+ * }
499
+ * })
500
+ *
501
+ * // Don't throw on parse errors
502
+ * const config = await readJson('./config.json', { throws: false })
503
+ * if (config === undefined) {
504
+ * console.log('Failed to parse config')
505
+ * }
506
+ * ```
126
507
  */
127
508
  /*@__NO_SIDE_EFFECTS__*/
128
509
  export declare function readJson(filepath: PathLike, options?: ReadJsonOptions | string | undefined): Promise<import("./json").JsonValue>;
129
510
  /**
130
511
  * Read and parse a JSON file synchronously.
512
+ * Reads the file as UTF-8 text and parses it as JSON.
513
+ * Optionally accepts a reviver function to transform parsed values.
514
+ *
515
+ * @param filepath - Path to JSON file
516
+ * @param options - Read and parse options
517
+ * @returns Parsed JSON value, or undefined if throws is false and an error occurs
518
+ *
519
+ * @example
520
+ * ```ts
521
+ * // Read and parse tsconfig.json
522
+ * const tsconfig = readJsonSync('./tsconfig.json')
523
+ *
524
+ * // Read JSON with custom reviver
525
+ * const data = readJsonSync('./data.json', {
526
+ * reviver: (key, value) => {
527
+ * if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
528
+ * return new Date(value)
529
+ * }
530
+ * return value
531
+ * }
532
+ * })
533
+ *
534
+ * // Don't throw on parse errors
535
+ * const config = readJsonSync('./config.json', { throws: false })
536
+ * ```
131
537
  */
132
538
  /*@__NO_SIDE_EFFECTS__*/
133
539
  export declare function readJsonSync(filepath: PathLike, options?: ReadJsonOptions | string | undefined): import("./json").JsonValue;
@@ -135,7 +541,25 @@ export declare function readJsonSync(filepath: PathLike, options?: ReadJsonOptio
135
541
  * Safely delete a file or directory asynchronously with built-in protections.
136
542
  * Uses `del` for safer deletion that prevents removing cwd and above by default.
137
543
  * Automatically uses force: true for temp directory, cacache, and ~/.socket subdirectories.
138
- * @throws {Error} When attempting to delete protected paths without force option.
544
+ *
545
+ * @param filepath - Path or array of paths to delete (supports glob patterns)
546
+ * @param options - Deletion options including force, retries, and recursion
547
+ * @throws {Error} When attempting to delete protected paths without force option
548
+ *
549
+ * @example
550
+ * ```ts
551
+ * // Delete a single file
552
+ * await safeDelete('./temp-file.txt')
553
+ *
554
+ * // Delete a directory recursively
555
+ * await safeDelete('./build', { recursive: true })
556
+ *
557
+ * // Delete multiple paths
558
+ * await safeDelete(['./dist', './coverage'])
559
+ *
560
+ * // Delete with custom retry settings
561
+ * await safeDelete('./flaky-dir', { maxRetries: 5, retryDelay: 500 })
562
+ * ```
139
563
  */
140
564
  /*@__NO_SIDE_EFFECTS__*/
141
565
  export declare function safeDelete(filepath: PathLike | PathLike[], options?: RemoveOptions | undefined): Promise<void>;
@@ -143,42 +567,190 @@ export declare function safeDelete(filepath: PathLike | PathLike[], options?: Re
143
567
  * Safely delete a file or directory synchronously with built-in protections.
144
568
  * Uses `del` for safer deletion that prevents removing cwd and above by default.
145
569
  * Automatically uses force: true for temp directory, cacache, and ~/.socket subdirectories.
146
- * @throws {Error} When attempting to delete protected paths without force option.
570
+ *
571
+ * @param filepath - Path or array of paths to delete (supports glob patterns)
572
+ * @param options - Deletion options including force, retries, and recursion
573
+ * @throws {Error} When attempting to delete protected paths without force option
574
+ *
575
+ * @example
576
+ * ```ts
577
+ * // Delete a single file
578
+ * safeDeleteSync('./temp-file.txt')
579
+ *
580
+ * // Delete a directory recursively
581
+ * safeDeleteSync('./build', { recursive: true })
582
+ *
583
+ * // Delete multiple paths with globs
584
+ * safeDeleteSync(['./dist/**', './coverage/**'])
585
+ *
586
+ * // Force delete a protected path (use with caution)
587
+ * safeDeleteSync('./important', { force: true })
588
+ * ```
147
589
  */
148
590
  /*@__NO_SIDE_EFFECTS__*/
149
591
  export declare function safeDeleteSync(filepath: PathLike | PathLike[], options?: RemoveOptions | undefined): void;
150
592
  /**
151
593
  * Safely read a file asynchronously, returning undefined on error.
594
+ * Useful when you want to attempt reading a file without handling errors explicitly.
595
+ * Returns undefined for any error (file not found, permission denied, etc.).
596
+ *
597
+ * @param filepath - Path to file
598
+ * @param options - Read options including encoding and default value
599
+ * @returns Promise resolving to file contents, or undefined on error
600
+ *
601
+ * @example
602
+ * ```ts
603
+ * // Try to read a file, get undefined if it doesn't exist
604
+ * const content = await safeReadFile('./optional-config.txt')
605
+ * if (content) {
606
+ * console.log('Config found:', content)
607
+ * }
608
+ *
609
+ * // Read with specific encoding
610
+ * const data = await safeReadFile('./data.txt', { encoding: 'utf8' })
611
+ * ```
152
612
  */
153
613
  /*@__NO_SIDE_EFFECTS__*/
154
614
  export declare function safeReadFile(filepath: PathLike, options?: SafeReadOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
155
615
  /**
156
616
  * Safely get file stats asynchronously, returning undefined on error.
617
+ * Useful for checking file existence and properties without error handling.
618
+ * Returns undefined for any error (file not found, permission denied, etc.).
619
+ *
620
+ * @param filepath - Path to check
621
+ * @returns Promise resolving to Stats object, or undefined on error
622
+ *
623
+ * @example
624
+ * ```ts
625
+ * // Check if file exists and get its stats
626
+ * const stats = await safeStats('./file.txt')
627
+ * if (stats) {
628
+ * console.log('File size:', stats.size)
629
+ * console.log('Modified:', stats.mtime)
630
+ * }
631
+ * ```
157
632
  */
158
633
  /*@__NO_SIDE_EFFECTS__*/
159
634
  export declare function safeStats(filepath: PathLike): Promise<import("fs").Stats>;
160
635
  /**
161
636
  * Safely get file stats synchronously, returning undefined on error.
637
+ * Useful for checking file existence and properties without error handling.
638
+ * Returns undefined for any error (file not found, permission denied, etc.).
639
+ *
640
+ * @param filepath - Path to check
641
+ * @param options - Read options (currently unused but kept for API consistency)
642
+ * @returns Stats object, or undefined on error
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * // Check if file exists and get its size
647
+ * const stats = safeStatsSync('./file.txt')
648
+ * if (stats) {
649
+ * console.log('File size:', stats.size)
650
+ * console.log('Is directory:', stats.isDirectory())
651
+ * }
652
+ * ```
162
653
  */
163
654
  /*@__NO_SIDE_EFFECTS__*/
164
655
  export declare function safeStatsSync(filepath: PathLike, options?: ReadFileOptions | undefined): import("fs").BigIntStats | import("fs").Stats;
165
656
  /**
166
657
  * Safely read a file synchronously, returning undefined on error.
658
+ * Useful when you want to attempt reading a file without handling errors explicitly.
659
+ * Returns undefined for any error (file not found, permission denied, etc.).
660
+ *
661
+ * @param filepath - Path to file
662
+ * @param options - Read options including encoding and default value
663
+ * @returns File contents, or undefined on error
664
+ *
665
+ * @example
666
+ * ```ts
667
+ * // Try to read a config file
668
+ * const config = safeReadFileSync('./config.txt')
669
+ * if (config) {
670
+ * console.log('Config loaded successfully')
671
+ * }
672
+ *
673
+ * // Read binary file safely
674
+ * const buffer = safeReadFileSync('./image.png', { encoding: null })
675
+ * ```
167
676
  */
168
677
  /*@__NO_SIDE_EFFECTS__*/
169
678
  export declare function safeReadFileSync(filepath: PathLike, options?: SafeReadOptions | undefined): string | NonSharedBuffer;
170
679
  /**
171
680
  * Generate a unique filepath by adding number suffix if the path exists.
681
+ * Appends `-1`, `-2`, etc. before the file extension until a non-existent path is found.
682
+ * Useful for creating files without overwriting existing ones.
683
+ *
684
+ * @param filepath - Desired file path
685
+ * @returns Normalized unique filepath (original if it doesn't exist, or with number suffix)
686
+ *
687
+ * @example
688
+ * ```ts
689
+ * // If 'report.pdf' exists, returns 'report-1.pdf'
690
+ * const uniquePath = uniqueSync('./report.pdf')
691
+ *
692
+ * // If 'data.json' and 'data-1.json' exist, returns 'data-2.json'
693
+ * const path = uniqueSync('./data.json')
694
+ *
695
+ * // If 'backup' doesn't exist, returns 'backup' unchanged
696
+ * const backupPath = uniqueSync('./backup')
697
+ * ```
172
698
  */
173
699
  /*@__NO_SIDE_EFFECTS__*/
174
700
  export declare function uniqueSync(filepath: PathLike): string;
175
701
  /**
176
702
  * Write JSON content to a file asynchronously with formatting.
703
+ * Stringifies the value with configurable indentation and line endings.
704
+ * Automatically adds a final newline by default for POSIX compliance.
705
+ *
706
+ * @param filepath - Path to write to
707
+ * @param jsonContent - Value to stringify and write
708
+ * @param options - Write options including formatting and encoding
709
+ * @returns Promise that resolves when write completes
710
+ *
711
+ * @example
712
+ * ```ts
713
+ * // Write formatted JSON with default 2-space indentation
714
+ * await writeJson('./data.json', { name: 'example', version: '1.0.0' })
715
+ *
716
+ * // Write with custom indentation
717
+ * await writeJson('./config.json', config, { spaces: 4 })
718
+ *
719
+ * // Write with tabs instead of spaces
720
+ * await writeJson('./data.json', data, { spaces: '\t' })
721
+ *
722
+ * // Write without final newline
723
+ * await writeJson('./inline.json', obj, { finalEOL: false })
724
+ *
725
+ * // Write with Windows line endings
726
+ * await writeJson('./win.json', data, { EOL: '\r\n' })
727
+ * ```
177
728
  */
178
729
  /*@__NO_SIDE_EFFECTS__*/
179
730
  export declare function writeJson(filepath: PathLike, jsonContent: unknown, options?: WriteJsonOptions | string): Promise<void>;
180
731
  /**
181
732
  * Write JSON content to a file synchronously with formatting.
733
+ * Stringifies the value with configurable indentation and line endings.
734
+ * Automatically adds a final newline by default for POSIX compliance.
735
+ *
736
+ * @param filepath - Path to write to
737
+ * @param jsonContent - Value to stringify and write
738
+ * @param options - Write options including formatting and encoding
739
+ *
740
+ * @example
741
+ * ```ts
742
+ * // Write formatted JSON with default 2-space indentation
743
+ * writeJsonSync('./package.json', pkg)
744
+ *
745
+ * // Write with custom indentation
746
+ * writeJsonSync('./tsconfig.json', tsconfig, { spaces: 4 })
747
+ *
748
+ * // Write with tabs for indentation
749
+ * writeJsonSync('./data.json', data, { spaces: '\t' })
750
+ *
751
+ * // Write compacted (no indentation)
752
+ * writeJsonSync('./compact.json', data, { spaces: 0 })
753
+ * ```
182
754
  */
183
755
  /*@__NO_SIDE_EFFECTS__*/
184
756
  export declare function writeJsonSync(filepath: PathLike, jsonContent: unknown, options?: WriteJsonOptions | string | undefined): void;