prebundle 1.1.0 → 1.2.1

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 +1,1063 @@
1
- export = any;
1
+ /// <reference types="node" />
2
+ import * as fs from 'fs';
3
+ import { readFile as readFile$2, readFileSync as readFileSync$1, writeFile as writeFile$2, writeFileSync as writeFileSync$1, PathLike } from 'fs';
4
+ export * from 'fs';
5
+ import { Url } from 'url';
6
+
7
+ type Path = PathLike | Url;
8
+
9
+ interface FS {
10
+ readFile: typeof readFile$2;
11
+ readFileSync: typeof readFileSync$1;
12
+ writeFile: typeof writeFile$2;
13
+ writeFileSync: typeof writeFileSync$1;
14
+ }
15
+
16
+ type JFReadOptions =
17
+ | {
18
+ encoding?: string | null | undefined;
19
+ flag?: string | undefined;
20
+ throws?: boolean | undefined;
21
+ fs?: FS | undefined;
22
+ reviver?: ((key: any, value: any) => any) | undefined;
23
+ }
24
+ | string
25
+ | null
26
+ | undefined;
27
+
28
+ type JFWriteOptions =
29
+ | {
30
+ encoding?: string | null | undefined;
31
+ mode?: string | number | undefined;
32
+ flag?: string | undefined;
33
+ fs?: FS | undefined;
34
+ EOL?: string | undefined;
35
+ spaces?: string | number | undefined;
36
+ replacer?: ((key: string, value: any) => any) | undefined;
37
+ }
38
+ | string
39
+ | null;
40
+
41
+ type ReadCallback = (err: NodeJS.ErrnoException | null, data: any) => void;
42
+ type WriteCallback = (err: NodeJS.ErrnoException | null) => void;
43
+
44
+ /**
45
+ * @see {@link https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback}
46
+ */
47
+ declare function readFile$1(file: Path, options: JFReadOptions, callback: ReadCallback): void;
48
+ declare function readFile$1(file: Path, callback: ReadCallback): void;
49
+ declare function readFile$1(file: Path, options?: JFReadOptions): Promise<any>;
50
+
51
+ /**
52
+ * @see {@link https://github.com/jprichardson/node-jsonfile#readfilesyncfilename-options}
53
+ */
54
+ declare function readFileSync(file: Path, options?: JFReadOptions): any;
55
+
56
+ /**
57
+ * @see {@link https://github.com/jprichardson/node-jsonfile#writefilefilename-obj-options-callback}
58
+ */
59
+ declare function writeFile$1(file: Path, obj: any, options: JFWriteOptions, callback: WriteCallback): void;
60
+ declare function writeFile$1(file: Path, obj: any, callback: WriteCallback): void;
61
+ declare function writeFile$1(file: Path, obj: any, options?: JFWriteOptions): Promise<void>;
62
+
63
+ /**
64
+ * @see {@link https://github.com/jprichardson/node-jsonfile#writefilesyncfilename-obj-options}
65
+ */
66
+ declare function writeFileSync(file: Path, obj: any, options?: JFWriteOptions): void;
67
+
68
+ interface StringifyOptions {
69
+ EOL?: string | undefined;
70
+ finalEOL?: boolean | undefined;
71
+ replacer?: ((key: string, value: any) => any) | undefined;
72
+ spaces?: string | number | undefined;
73
+ }
74
+
75
+ /**
76
+ * Copy a file or directory. The directory can have contents.
77
+ *
78
+ * @param src Note that if `src` is a directory it will copy everything inside of this directory,
79
+ * not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
80
+ * @param dest Note that if `src` is a file, `dest` cannot be a directory
81
+ * (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).
82
+ *
83
+ * @example
84
+ * import * as fs from 'fs-extra'
85
+ *
86
+ * // With a callback:
87
+ * fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
88
+ * if (err) return console.error(err)
89
+ * console.log('success!')
90
+ * }) // copies file
91
+ *
92
+ * fs.copy('/tmp/mydir', '/tmp/mynewdir', err => {
93
+ * if (err) return console.error(err)
94
+ * console.log('success!')
95
+ * }) // copies directory, even if it has subdirectories or files
96
+ *
97
+ * // With Promises:
98
+ * fs.copy('/tmp/myfile', '/tmp/mynewfile')
99
+ * .then(() => {
100
+ * console.log('success!')
101
+ * })
102
+ * .catch(err => {
103
+ * console.error(err)
104
+ * })
105
+ *
106
+ * // With async/await:
107
+ * async function asyncAwait () {
108
+ * try {
109
+ * await fs.copy('/tmp/myfile', '/tmp/mynewfile')
110
+ * console.log('success!')
111
+ * } catch (err) {
112
+ * console.error(err)
113
+ * }
114
+ * }
115
+ *
116
+ * asyncAwait()
117
+ *
118
+ * // Using filter function
119
+ * fs.copy(
120
+ * '/tmp/mydir',
121
+ * '/tmp/mynewdir',
122
+ * {
123
+ * filter(src, dest) {
124
+ * // your logic here
125
+ * // it will be copied if return true
126
+ * }
127
+ * },
128
+ * err => {
129
+ * if (err) return console.error(err)
130
+ * console.log('success!')
131
+ * }
132
+ * )
133
+ */
134
+ declare function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
135
+ declare function copy(src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
136
+ declare function copy(src: string, dest: string, options: CopyOptions, callback: NoParamCallbackWithUndefined): void;
137
+ /**
138
+ * Copy a file or directory. The directory can have contents.
139
+ *
140
+ * @param src Note that if `src` is a directory it will copy everything inside of this directory,
141
+ * not the entire directory itself (see [issue #537](https://github.com/jprichardson/node-fs-extra/issues/537)).
142
+ * @param dest Note that if `src` is a file, `dest` cannot be a directory
143
+ * (see [issue #323](https://github.com/jprichardson/node-fs-extra/issues/323)).
144
+ *
145
+ * @example
146
+ * import * as fs from 'fs-extra'
147
+ *
148
+ * // copy file
149
+ * fs.copySync('/tmp/myfile', '/tmp/mynewfile')
150
+ *
151
+ * // copy directory, even if it has subdirectories or files
152
+ * fs.copySync('/tmp/mydir', '/tmp/mynewdir')
153
+ *
154
+ * // Using filter function
155
+ * fs.copySync('/tmp/mydir', '/tmp/mynewdir', {
156
+ * filter(src, dest) {
157
+ * // your logic here
158
+ * // it will be copied if return true
159
+ * }
160
+ * })
161
+ */
162
+ declare function copySync(src: string, dest: string, options?: CopyOptionsSync): void;
163
+
164
+ /**
165
+ * Moves a file or directory, even across devices.
166
+ *
167
+ * @param dest Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.
168
+ *
169
+ * @example
170
+ * import * as fs from 'fs-extra'
171
+ *
172
+ * const src = '/tmp/file.txt'
173
+ * const dest = '/tmp/this/path/does/not/exist/file.txt'
174
+ *
175
+ * // With a callback:
176
+ * fs.move(src, dest, err => {
177
+ * if (err) return console.error(err)
178
+ * console.log('success!')
179
+ * })
180
+ *
181
+ * // With Promises:
182
+ * fs.move(src, dest)
183
+ * .then(() => {
184
+ * console.log('success!')
185
+ * })
186
+ * .catch(err => {
187
+ * console.error(err)
188
+ * })
189
+ *
190
+ * // With async/await:
191
+ * async function asyncAwait () {
192
+ * try {
193
+ * await fs.move(src, dest)
194
+ * console.log('success!')
195
+ * } catch (err) {
196
+ * console.error(err)
197
+ * }
198
+ * }
199
+ *
200
+ * asyncAwait()
201
+ *
202
+ * // Using `overwrite` option
203
+ * fs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => {
204
+ * if (err) return console.error(err)
205
+ * console.log('success!')
206
+ * })
207
+ */
208
+ declare function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
209
+ declare function move(src: string, dest: string, callback: NoParamCallbackWithUndefined): void;
210
+ declare function move(src: string, dest: string, options: MoveOptions, callback: NoParamCallbackWithUndefined): void;
211
+ /**
212
+ * Moves a file or directory, even across devices.
213
+ *
214
+ * @param dest Note: When `src` is a file, `dest` must be a file and when `src` is a directory, `dest` must be a directory.
215
+ *
216
+ * @example
217
+ * import * as fs from 'fs-extra'
218
+ *
219
+ * fs.moveSync('/tmp/somefile', '/tmp/does/not/exist/yet/somefile')
220
+ *
221
+ * // Using `overwrite` option
222
+ * fs.moveSync('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true })
223
+ */
224
+ declare function moveSync(src: string, dest: string, options?: MoveOptions): void;
225
+
226
+ /**
227
+ * Ensures that the file exists. If the file that is requested to be created is in
228
+ * directories that do not exist, these directories are created. If the file already
229
+ * exists, it is **NOT MODIFIED**.
230
+ *
231
+ * @example
232
+ * import * as fs from 'fs-extra'
233
+ *
234
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
235
+ *
236
+ * // With a callback:
237
+ * fs.ensureFile(file, err => {
238
+ * console.log(err) // => null
239
+ * // file has now been created, including the directory it is to be placed in
240
+ * })
241
+ *
242
+ * // With Promises:
243
+ * fs.ensureFile(file)
244
+ * .then(() => {
245
+ * console.log('success!')
246
+ * })
247
+ * .catch(err => {
248
+ * console.error(err)
249
+ * })
250
+ *
251
+ * // With async/await:
252
+ * async function asyncAwait () {
253
+ * try {
254
+ * await fs.ensureFile(file)
255
+ * console.log('success!')
256
+ * } catch (err) {
257
+ * console.error(err)
258
+ * }
259
+ * }
260
+ *
261
+ * asyncAwait()
262
+ */
263
+ declare function ensureFile(file: string): Promise<void>;
264
+ declare function ensureFile(file: string, callback: NoParamCallbackWithUndefined): void;
265
+ /**
266
+ * @see ensureFile
267
+ */
268
+ declare const createFile: typeof ensureFile;
269
+ /**
270
+ * Ensures that the file exists. If the file that is requested to be created is in
271
+ * directories that do not exist, these directories are created. If the file already
272
+ * exists, it is **NOT MODIFIED**.
273
+ *
274
+ * @example
275
+ * import * as fs from 'fs-extra'
276
+ *
277
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
278
+ * fs.ensureFileSync(file)
279
+ * // file has now been created, including the directory it is to be placed in
280
+ */
281
+ declare function ensureFileSync(file: string): void;
282
+ /**
283
+ * @see ensureFileSync
284
+ */
285
+ declare const createFileSync: typeof ensureFileSync;
286
+
287
+ /**
288
+ * Ensures that the link exists. If the directory structure does not exist, it is created.
289
+ *
290
+ * @example
291
+ * import * as fs from 'fs-extra'
292
+ *
293
+ * const srcPath = '/tmp/file.txt'
294
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
295
+ *
296
+ * // With a callback:
297
+ * fs.ensureLink(srcPath, destPath, err => {
298
+ * console.log(err) // => null
299
+ * // link has now been created, including the directory it is to be placed in
300
+ * })
301
+ *
302
+ * // With Promises:
303
+ * fs.ensureLink(srcPath, destPath)
304
+ * .then(() => {
305
+ * console.log('success!')
306
+ * })
307
+ * .catch(err => {
308
+ * console.error(err)
309
+ * })
310
+ *
311
+ * // With async/await:
312
+ * async function asyncAwait () {
313
+ * try {
314
+ * await fs.ensureLink(srcPath, destPath)
315
+ * console.log('success!')
316
+ * } catch (err) {
317
+ * console.error(err)
318
+ * }
319
+ * }
320
+ *
321
+ * asyncAwait()
322
+ */
323
+ declare function ensureLink(src: string, dest: string): Promise<void>;
324
+ declare function ensureLink(src: string, dest: string, callback: fs.NoParamCallback): void;
325
+ /**
326
+ * @see ensureLink
327
+ */
328
+ declare const createLink: typeof ensureLink;
329
+ /**
330
+ * Ensures that the link exists. If the directory structure does not exist, it is created.
331
+ *
332
+ * @example
333
+ * import * as fs from 'fs-extra'
334
+ *
335
+ * const srcPath = '/tmp/file.txt'
336
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
337
+ * fs.ensureLinkSync(srcPath, destPath)
338
+ * // link has now been created, including the directory it is to be placed in
339
+ */
340
+ declare function ensureLinkSync(src: string, dest: string): void;
341
+ /**
342
+ * @see ensureLinkSync
343
+ */
344
+ declare const createLinkSync: typeof ensureLinkSync;
345
+
346
+ /**
347
+ * Ensures that the symlink exists. If the directory structure does not exist, it is created.
348
+ *
349
+ * @param type It is only available on Windows and ignored on other platforms.
350
+ *
351
+ * @example
352
+ * import * as fs from 'fs-extra'
353
+ *
354
+ * const srcPath = '/tmp/file.txt'
355
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
356
+ *
357
+ * // With a callback:
358
+ * fs.ensureSymlink(srcPath, destPath, err => {
359
+ * console.log(err) // => null
360
+ * // symlink has now been created, including the directory it is to be placed in
361
+ * })
362
+ *
363
+ * // With Promises:
364
+ * fs.ensureSymlink(srcPath, destPath)
365
+ * .then(() => {
366
+ * console.log('success!')
367
+ * })
368
+ * .catch(err => {
369
+ * console.error(err)
370
+ * })
371
+ *
372
+ * // With async/await:
373
+ * async function asyncAwait () {
374
+ * try {
375
+ * await fs.ensureSymlink(srcPath, destPath)
376
+ * console.log('success!')
377
+ * } catch (err) {
378
+ * console.error(err)
379
+ * }
380
+ * }
381
+ *
382
+ * asyncAwait()
383
+ */
384
+ declare function ensureSymlink(src: string, dest: string, type?: SymlinkType): Promise<void>;
385
+ declare function ensureSymlink(src: string, dest: string, callback: fs.NoParamCallback): void;
386
+ declare function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: fs.NoParamCallback): void;
387
+ /**
388
+ * @see ensureSymlink
389
+ */
390
+ declare const createSymlink: typeof ensureSymlink;
391
+ /**
392
+ * Ensures that the symlink exists. If the directory structure does not exist, it is created.
393
+ *
394
+ * @param type It is only available on Windows and ignored on other platforms.
395
+ *
396
+ * @example
397
+ * import * as fs from 'fs-extra'
398
+ *
399
+ * const srcPath = '/tmp/file.txt'
400
+ * const destPath = '/tmp/this/path/does/not/exist/file.txt'
401
+ * fs.ensureSymlinkSync(srcPath, destPath)
402
+ * // symlink has now been created, including the directory it is to be placed in
403
+ */
404
+ declare function ensureSymlinkSync(src: string, dest: string, type?: SymlinkType): void;
405
+ /**
406
+ * @see ensureSymlinkSync
407
+ */
408
+ declare const createSymlinkSync: typeof ensureSymlinkSync;
409
+
410
+ /**
411
+ * Ensures that the directory exists. If the directory structure does not exist, it is created.
412
+ *
413
+ * @example
414
+ * import * as fs from 'fs-extra'
415
+ *
416
+ * const dir = '/tmp/this/path/does/not/exist'
417
+ * const desiredMode = 0o2775
418
+ * const options = {
419
+ * mode: 0o2775
420
+ * }
421
+ *
422
+ * // With a callback:
423
+ * fs.ensureDir(dir, err => {
424
+ * console.log(err) // => null
425
+ * // dir has now been created, including the directory it is to be placed in
426
+ * })
427
+ *
428
+ * // With a callback and a mode integer
429
+ * fs.ensureDir(dir, desiredMode, err => {
430
+ * console.log(err) // => null
431
+ * // dir has now been created with mode 0o2775, including the directory it is to be placed in
432
+ * })
433
+ *
434
+ * // With Promises:
435
+ * fs.ensureDir(dir)
436
+ * .then(() => {
437
+ * console.log('success!')
438
+ * })
439
+ * .catch(err => {
440
+ * console.error(err)
441
+ * })
442
+ *
443
+ * // With Promises and a mode integer:
444
+ * fs.ensureDir(dir, desiredMode)
445
+ * .then(() => {
446
+ * console.log('success!')
447
+ * })
448
+ * .catch(err => {
449
+ * console.error(err)
450
+ * })
451
+ *
452
+ * // With async/await:
453
+ * async function asyncAwait () {
454
+ * try {
455
+ * await fs.ensureDir(dir)
456
+ * console.log('success!')
457
+ * } catch (err) {
458
+ * console.error(err)
459
+ * }
460
+ * }
461
+ * asyncAwait()
462
+ *
463
+ * // With async/await and an options object, containing mode:
464
+ * async function asyncAwaitMode () {
465
+ * try {
466
+ * await fs.ensureDir(dir, options)
467
+ * console.log('success!')
468
+ * } catch (err) {
469
+ * console.error(err)
470
+ * }
471
+ * }
472
+ * asyncAwaitMode()
473
+ */
474
+ declare function ensureDir(path: string, options?: EnsureDirOptions | number): Promise<void>;
475
+ declare function ensureDir(path: string, callback: fs.NoParamCallback): void;
476
+ declare function ensureDir(path: string, options: EnsureDirOptions | number, callback: fs.NoParamCallback): void;
477
+ /**
478
+ * Ensures that the directory exists. If the directory structure does not exist, it is created.
479
+ * If provided, options may specify the desired mode for the directory.
480
+ *
481
+ * @example
482
+ * import * as fs from 'fs-extra'
483
+ *
484
+ * const dir = '/tmp/this/path/does/not/exist'
485
+ *
486
+ * const desiredMode = 0o2775
487
+ * const options = {
488
+ * mode: 0o2775
489
+ * }
490
+ *
491
+ * fs.ensureDirSync(dir)
492
+ * // dir has now been created, including the directory it is to be placed in
493
+ *
494
+ * fs.ensureDirSync(dir, desiredMode)
495
+ * // dir has now been created, including the directory it is to be placed in with permission 0o2775
496
+ *
497
+ * fs.ensureDirSync(dir, options)
498
+ * // dir has now been created, including the directory it is to be placed in with permission 0o2775
499
+ */
500
+ declare function ensureDirSync(path: string, options?: EnsureDirOptions | number): void;
501
+
502
+ /**
503
+ * @see ensureDir
504
+ */
505
+ declare const mkdirs: typeof ensureDir;
506
+ /**
507
+ * @see ensureDirSync
508
+ */
509
+ declare const mkdirsSync: typeof ensureDirSync;
510
+
511
+ /**
512
+ * @see ensureDir
513
+ */
514
+ declare const mkdirp: typeof ensureDir;
515
+ /**
516
+ * @see ensureDirSync
517
+ */
518
+ declare const mkdirpSync: typeof ensureDirSync;
519
+
520
+ /**
521
+ * Almost the same as `writeFile` (i.e. it overwrites), except that if the parent directory
522
+ * does not exist, it's created.
523
+ *
524
+ * @example
525
+ * import * as fs from 'fs-extra'
526
+ *
527
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
528
+ *
529
+ * // With a callback:
530
+ * fs.outputFile(file, 'hello!', err => {
531
+ * console.log(err) // => null
532
+ *
533
+ * fs.readFile(file, 'utf8', (err, data) => {
534
+ * if (err) return console.error(err)
535
+ * console.log(data) // => hello!
536
+ * })
537
+ * })
538
+ *
539
+ * // With Promises:
540
+ * fs.outputFile(file, 'hello!')
541
+ * .then(() => fs.readFile(file, 'utf8'))
542
+ * .then(data => {
543
+ * console.log(data) // => hello!
544
+ * })
545
+ * .catch(err => {
546
+ * console.error(err)
547
+ * })
548
+ *
549
+ * // With async/await:
550
+ * async function asyncAwait () {
551
+ * try {
552
+ * await fs.outputFile(file, 'hello!')
553
+ *
554
+ * const data = await fs.readFile(file, 'utf8')
555
+ *
556
+ * console.log(data) // => hello!
557
+ * } catch (err) {
558
+ * console.error(err)
559
+ * }
560
+ * }
561
+ *
562
+ * asyncAwait()
563
+ */
564
+ declare function outputFile(
565
+ file: string,
566
+ data: string | NodeJS.ArrayBufferView,
567
+ options?: fs.WriteFileOptions,
568
+ ): Promise<void>;
569
+ declare function outputFile(file: string, data: string | NodeJS.ArrayBufferView, callback: fs.NoParamCallback): void;
570
+ declare function outputFile(
571
+ file: string,
572
+ data: string | NodeJS.ArrayBufferView,
573
+ options: fs.WriteFileOptions,
574
+ callback: fs.NoParamCallback,
575
+ ): void;
576
+ /**
577
+ * Almost the same as `writeFileSync` (i.e. it overwrites), except that if the parent directory
578
+ * does not exist, it's created.
579
+ *
580
+ * @example
581
+ * import * as fs from 'fs-extra'
582
+ *
583
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
584
+ * fs.outputFileSync(file, 'hello!')
585
+ *
586
+ * const data = fs.readFileSync(file, 'utf8')
587
+ * console.log(data) // => hello!
588
+ */
589
+ declare function outputFileSync(
590
+ file: string,
591
+ data: string | NodeJS.ArrayBufferView,
592
+ options?: fs.WriteFileOptions,
593
+ ): void;
594
+
595
+ /**
596
+ * Reads a JSON file and then parses it into an object.
597
+ *
598
+ * @example
599
+ * import * as fs from 'fs-extra'
600
+ *
601
+ * // With a callback:
602
+ * fs.readJson('./package.json', (err, packageObj) => {
603
+ * if (err) console.error(err)
604
+ * console.log(packageObj.version) // => 0.1.3
605
+ * })
606
+ *
607
+ * // With Promises:
608
+ * fs.readJson('./package.json')
609
+ * .then(packageObj => {
610
+ * console.log(packageObj.version) // => 0.1.3
611
+ * })
612
+ * .catch(err => {
613
+ * console.error(err)
614
+ * })
615
+ *
616
+ * // With async/await:
617
+ * async function asyncAwait () {
618
+ * try {
619
+ * const packageObj = await fs.readJson('./package.json')
620
+ * console.log(packageObj.version) // => 0.1.3
621
+ * } catch (err) {
622
+ * console.error(err)
623
+ * }
624
+ * }
625
+ *
626
+ * asyncAwait()
627
+ *
628
+ * // `readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
629
+ * const file = '/tmp/some-invalid.json'
630
+ * const data = '{not valid JSON'
631
+ * fs.writeFileSync(file, data)
632
+ *
633
+ * // With a callback:
634
+ * fs.readJson(file, { throws: false }, (err, obj) => {
635
+ * if (err) console.error(err)
636
+ * console.log(obj) // => null
637
+ * })
638
+ *
639
+ * // With Promises:
640
+ * fs.readJson(file, { throws: false })
641
+ * .then(obj => {
642
+ * console.log(obj) // => null
643
+ * })
644
+ * .catch(err => {
645
+ * console.error(err) // Not called
646
+ * })
647
+ *
648
+ * // With async/await:
649
+ * async function asyncAwaitThrows () {
650
+ * const obj = await fs.readJson(file, { throws: false })
651
+ * console.log(obj) // => null
652
+ * }
653
+ *
654
+ * asyncAwaitThrows()
655
+ */
656
+ declare const readJson: typeof readFile$1;
657
+ /**
658
+ * @see readJson
659
+ */
660
+ declare const readJSON: typeof readFile$1;
661
+ /**
662
+ * Reads a JSON file and then parses it into an object.
663
+ *
664
+ * @example
665
+ * import * as fs from 'fs-extra'
666
+ *
667
+ * const packageObj = fs.readJsonSync('./package.json')
668
+ * console.log(packageObj.version) // => 2.0.0
669
+ *
670
+ * // `readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:
671
+ * const file = '/tmp/some-invalid.json'
672
+ * const data = '{not valid JSON'
673
+ * fs.writeFileSync(file, data)
674
+ *
675
+ * const obj = fs.readJsonSync(file, { throws: false })
676
+ * console.log(obj) // => null
677
+ */
678
+ declare const readJsonSync: typeof readFileSync;
679
+ /**
680
+ * @see readJsonSync
681
+ */
682
+ declare const readJSONSync: typeof readFileSync;
683
+
684
+ /**
685
+ * Writes an object to a JSON file.
686
+ *
687
+ * @example
688
+ * import * as fs from 'fs-extra'
689
+ *
690
+ * // With a callback:
691
+ * fs.writeJson('./package.json', {name: 'fs-extra'}, err => {
692
+ * if (err) return console.error(err)
693
+ * console.log('success!')
694
+ * })
695
+ *
696
+ * // With Promises:
697
+ * fs.writeJson('./package.json', {name: 'fs-extra'})
698
+ * .then(() => {
699
+ * console.log('success!')
700
+ * })
701
+ * .catch(err => {
702
+ * console.error(err)
703
+ * })
704
+ *
705
+ * // With async/await:
706
+ * async function asyncAwait () {
707
+ * try {
708
+ * await fs.writeJson('./package.json', {name: 'fs-extra'})
709
+ * console.log('success!')
710
+ * } catch (err) {
711
+ * console.error(err)
712
+ * }
713
+ * }
714
+ *
715
+ * asyncAwait()
716
+ */
717
+ declare const writeJson: typeof writeFile$1;
718
+ /**
719
+ * @see writeJson
720
+ */
721
+ declare const writeJSON: typeof writeFile$1;
722
+ /**
723
+ * Writes an object to a JSON file.
724
+ *
725
+ * @example
726
+ * import * as fs from 'fs-extra'
727
+ *
728
+ * fs.writeJsonSync('./package.json', {name: 'fs-extra'})
729
+ */
730
+ declare const writeJsonSync: typeof writeFileSync;
731
+ /**
732
+ * @see writeJsonSync
733
+ */
734
+ declare const writeJSONSync: typeof writeFileSync;
735
+
736
+ /**
737
+ * Almost the same as `writeJson`, except that if the directory does not exist, it's created.
738
+ *
739
+ * @example
740
+ * import * as fs from 'fs-extra'
741
+ *
742
+ * const file = '/tmp/this/path/does/not/exist/file.json'
743
+ *
744
+ * // With a callback:
745
+ * fs.outputJson(file, {name: 'JP'}, err => {
746
+ * console.log(err) // => null
747
+ *
748
+ * fs.readJson(file, (err, data) => {
749
+ * if (err) return console.error(err)
750
+ * console.log(data.name) // => JP
751
+ * })
752
+ * })
753
+ *
754
+ * // With Promises:
755
+ * fs.outputJson(file, {name: 'JP'})
756
+ * .then(() => fs.readJson(file))
757
+ * .then(data => {
758
+ * console.log(data.name) // => JP
759
+ * })
760
+ * .catch(err => {
761
+ * console.error(err)
762
+ * })
763
+ *
764
+ * // With async/await:
765
+ * async function asyncAwait () {
766
+ * try {
767
+ * await fs.outputJson(file, {name: 'JP'})
768
+ *
769
+ * const data = await fs.readJson(file)
770
+ *
771
+ * console.log(data.name) // => JP
772
+ * } catch (err) {
773
+ * console.error(err)
774
+ * }
775
+ * }
776
+ *
777
+ * asyncAwait()
778
+ */
779
+ declare function outputJson(file: string, data: any, options?: JsonOutputOptions): Promise<void>;
780
+ declare function outputJson(file: string, data: any, options: JsonOutputOptions, callback: fs.NoParamCallback): void;
781
+ declare function outputJson(file: string, data: any, callback: fs.NoParamCallback): void;
782
+ /**
783
+ * @see outputJson
784
+ */
785
+ declare const outputJSON: typeof outputJson;
786
+ /**
787
+ * Almost the same as `writeJsonSync`, except that if the directory does not exist, it's created.
788
+ *
789
+ * @example
790
+ * import * as fs from 'fs-extra'
791
+ *
792
+ * const file = '/tmp/this/path/does/not/exist/file.json'
793
+ * fs.outputJsonSync(file, {name: 'JP'})
794
+ *
795
+ * const data = fs.readJsonSync(file)
796
+ * console.log(data.name) // => JP
797
+ */
798
+ declare function outputJsonSync(file: string, data: any, options?: JsonOutputOptions): void;
799
+ /**
800
+ * @see outputJsonSync
801
+ */
802
+ declare const outputJSONSync: typeof outputJsonSync;
803
+
804
+ /**
805
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
806
+ *
807
+ * @example
808
+ * import * as fs from 'fs-extra'
809
+ *
810
+ * // remove file
811
+ * // With a callback:
812
+ * fs.remove('/tmp/myfile', err => {
813
+ * if (err) return console.error(err)
814
+ * console.log('success!')
815
+ * })
816
+ *
817
+ * fs.remove('/home/jprichardson', err => {
818
+ * if (err) return console.error(err)
819
+ * console.log('success!') // I just deleted my entire HOME directory.
820
+ * })
821
+ *
822
+ * // With Promises:
823
+ * fs.remove('/tmp/myfile')
824
+ * .then(() => {
825
+ * console.log('success!')
826
+ * })
827
+ * .catch(err => {
828
+ * console.error(err)
829
+ * })
830
+ *
831
+ * // With async/await:
832
+ * async function asyncAwait () {
833
+ * try {
834
+ * await fs.remove('/tmp/myfile')
835
+ * console.log('success!')
836
+ * } catch (err) {
837
+ * console.error(err)
838
+ * }
839
+ * }
840
+ *
841
+ * asyncAwait()
842
+ */
843
+ declare function remove(dir: string): Promise<void>;
844
+ declare function remove(dir: string, callback: fs.NoParamCallback): void;
845
+ /**
846
+ * Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.
847
+ *
848
+ * @example
849
+ * import * as fs from 'fs-extra'
850
+ *
851
+ * // remove file
852
+ * fs.removeSync('/tmp/myfile')
853
+ *
854
+ * fs.removeSync('/home/jprichardson') // I just deleted my entire HOME directory.
855
+ */
856
+ declare function removeSync(dir: string): void;
857
+
858
+ /**
859
+ * Ensures that a directory is empty. Deletes directory contents if the directory is not empty.
860
+ * If the directory does not exist, it is created. The directory itself is not deleted.
861
+ *
862
+ * @example
863
+ * import * as fs from 'fs-extra'
864
+ *
865
+ * // assume this directory has a lot of files and folders
866
+ * // With a callback:
867
+ * fs.emptyDir('/tmp/some/dir', err => {
868
+ * if (err) return console.error(err)
869
+ * console.log('success!')
870
+ * })
871
+ *
872
+ * // With Promises:
873
+ * fs.emptyDir('/tmp/some/dir')
874
+ * .then(() => {
875
+ * console.log('success!')
876
+ * })
877
+ * .catch(err => {
878
+ * console.error(err)
879
+ * })
880
+ *
881
+ * // With async/await:
882
+ * async function asyncAwait () {
883
+ * try {
884
+ * await fs.emptyDir('/tmp/some/dir')
885
+ * console.log('success!')
886
+ * } catch (err) {
887
+ * console.error(err)
888
+ * }
889
+ * }
890
+ *
891
+ * asyncAwait()
892
+ */
893
+ declare function emptyDir(path: string): Promise<void>;
894
+ declare function emptyDir(path: string, callback: fs.NoParamCallback): void;
895
+ /**
896
+ * @see emptyDir
897
+ */
898
+ declare const emptydir: typeof emptyDir;
899
+ /**
900
+ * Ensures that a directory is empty. Deletes directory contents if the directory is not empty.
901
+ * If the directory does not exist, it is created. The directory itself is not deleted.
902
+ *
903
+ * @example
904
+ * import * as fs from 'fs-extra'
905
+ *
906
+ * // assume this directory has a lot of files and folders
907
+ * fs.emptyDirSync('/tmp/some/dir')
908
+ */
909
+ declare function emptyDirSync(path: string): void;
910
+ /**
911
+ * @see emptyDirSync
912
+ */
913
+ declare const emptydirSync: typeof emptyDirSync;
914
+
915
+ /**
916
+ * Test whether or not the given path exists by checking with the file system. Like
917
+ * [`fs.exists`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback), but with a normal
918
+ * callback signature (err, exists). Uses `fs.access` under the hood.
919
+ *
920
+ * @example
921
+ * import * as fs from 'fs-extra'
922
+ *
923
+ * const file = '/tmp/this/path/does/not/exist/file.txt'
924
+ *
925
+ * // With a callback:
926
+ * fs.pathExists(file, (err, exists) => {
927
+ * console.log(err) // => null
928
+ * console.log(exists) // => false
929
+ * })
930
+ *
931
+ * // Promise usage:
932
+ * fs.pathExists(file)
933
+ * .then(exists => console.log(exists)) // => false
934
+ *
935
+ * // With async/await:
936
+ * async function asyncAwait () {
937
+ * const exists = await fs.pathExists(file)
938
+ *
939
+ * console.log(exists) // => false
940
+ * }
941
+ *
942
+ * asyncAwait()
943
+ */
944
+ declare function pathExists(path: string): Promise<boolean>;
945
+ declare function pathExists(path: string, callback: (err: NodeJS.ErrnoException | null, exists: boolean) => void): void;
946
+ /**
947
+ * An alias for [`fs.existsSync`](https://nodejs.org/api/fs.html#fs_fs_existssync_path), created for
948
+ * consistency with `pathExists`.
949
+ */
950
+ declare function pathExistsSync(path: string): boolean;
951
+
952
+ declare const access: typeof fs.access.__promisify__ & typeof fs.access;
953
+ declare const appendFile: typeof fs.appendFile.__promisify__ & typeof fs.appendFile;
954
+ declare const chmod: typeof fs.chmod.__promisify__ & typeof fs.chmod;
955
+ declare const chown: typeof fs.chown.__promisify__ & typeof fs.chown;
956
+ declare const close: typeof fs.close.__promisify__ & typeof fs.close;
957
+ declare const copyFile: typeof fs.copyFile.__promisify__ & typeof fs.copyFile;
958
+ declare const exists: typeof fs.exists.__promisify__ & typeof fs.exists;
959
+ declare const fchmod: typeof fs.fchmod.__promisify__ & typeof fs.fchmod;
960
+ declare const fchown: typeof fs.fchown.__promisify__ & typeof fs.fchown;
961
+ declare const fdatasync: typeof fs.fdatasync.__promisify__ & typeof fs.fdatasync;
962
+ declare const fstat: typeof fs.fstat.__promisify__ & typeof fs.fstat;
963
+ declare const fsync: typeof fs.fsync.__promisify__ & typeof fs.fsync;
964
+ declare const ftruncate: typeof fs.ftruncate.__promisify__ & typeof fs.ftruncate;
965
+ declare const futimes: typeof fs.futimes.__promisify__ & typeof fs.futimes;
966
+ declare const lchmod: typeof fs.lchmod.__promisify__ & typeof fs.lchmod;
967
+ declare const lchown: typeof fs.lchown.__promisify__ & typeof fs.lchown;
968
+ declare const link: typeof fs.link.__promisify__ & typeof fs.link;
969
+ declare const lstat: typeof fs.lstat.__promisify__ & typeof fs.lstat;
970
+ declare const mkdir: typeof fs.mkdir.__promisify__ & typeof fs.mkdir;
971
+ declare const mkdtemp: typeof fs.mkdtemp.__promisify__ & typeof fs.mkdtemp;
972
+ declare const open: typeof fs.open.__promisify__ & typeof fs.open;
973
+ declare const opendir: typeof fs.opendir.__promisify__ & typeof fs.opendir;
974
+ declare const read: typeof fs.read.__promisify__ & typeof fs.read;
975
+ declare const readv: typeof fs.readv.__promisify__ & typeof fs.readv;
976
+ declare const readdir: typeof fs.readdir.__promisify__ & typeof fs.readdir;
977
+ declare const readFile: typeof fs.readFile.__promisify__ & typeof fs.readFile;
978
+ declare const readlink: typeof fs.readlink.__promisify__ & typeof fs.readlink;
979
+ declare const realpath:
980
+ & typeof fs.realpath.__promisify__
981
+ & typeof fs.realpath
982
+ & {
983
+ native(path: fs.PathLike, options?: fs.EncodingOption): Promise<string>;
984
+ native(path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
985
+ };
986
+ declare const rename: typeof fs.rename.__promisify__ & typeof fs.rename;
987
+ declare const rm: typeof fs.rm.__promisify__ & typeof fs.rm;
988
+ declare const rmdir: typeof fs.rmdir.__promisify__ & typeof fs.rmdir;
989
+ declare const stat: typeof fs.stat.__promisify__ & typeof fs.stat;
990
+ declare const symlink: typeof fs.symlink.__promisify__ & typeof fs.symlink;
991
+ declare const truncate: typeof fs.truncate.__promisify__ & typeof fs.truncate;
992
+ declare const unlink: typeof fs.unlink.__promisify__ & typeof fs.unlink;
993
+ declare const utimes: typeof fs.utimes.__promisify__ & typeof fs.utimes;
994
+ declare const write: typeof fs.write.__promisify__ & typeof fs.write;
995
+ declare const writev: typeof fs.writev.__promisify__ & typeof fs.writev;
996
+ declare const writeFile: typeof fs.writeFile.__promisify__ & typeof fs.writeFile;
997
+
998
+ type NoParamCallbackWithUndefined = (err: NodeJS.ErrnoException | null | undefined) => void;
999
+
1000
+ type SymlinkType = fs.symlink.Type;
1001
+
1002
+ type CopyFilterSync = (src: string, dest: string) => boolean;
1003
+ type CopyFilterAsync = (src: string, dest: string) => Promise<boolean>;
1004
+
1005
+ interface CopyOptions {
1006
+ /**
1007
+ * Dereference symlinks.
1008
+ * @default false
1009
+ */
1010
+ dereference?: boolean | undefined;
1011
+ /**
1012
+ * Overwrite existing file or directory.
1013
+ * _Note that the copy operation will silently fail if you set this to `false` and the destination exists._
1014
+ * Use the `errorOnExist` option to change this behavior.
1015
+ * @default true
1016
+ */
1017
+ overwrite?: boolean | undefined;
1018
+ /**
1019
+ * When `true`, will set last modification and access times to the ones of the original source files.
1020
+ * When `false`, timestamp behavior is OS-dependent.
1021
+ * @default false
1022
+ */
1023
+ preserveTimestamps?: boolean | undefined;
1024
+ /**
1025
+ * When `overwrite` is `false` and the destination exists, throw an error.
1026
+ * @default false
1027
+ */
1028
+ errorOnExist?: boolean | undefined;
1029
+ /**
1030
+ * Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.
1031
+ * Can also return a `Promise` that resolves to `true` or `false` (or pass in an `async` function).
1032
+ */
1033
+ filter?: CopyFilterSync | CopyFilterAsync | undefined;
1034
+ }
1035
+
1036
+ interface CopyOptionsSync extends CopyOptions {
1037
+ /**
1038
+ * Function to filter copied files/directories. Return `true` to copy the item, `false` to ignore it.
1039
+ */
1040
+ filter?: CopyFilterSync | undefined;
1041
+ }
1042
+
1043
+ interface EnsureDirOptions {
1044
+ mode?: number | undefined;
1045
+ }
1046
+
1047
+ interface MoveOptions {
1048
+ /**
1049
+ * Overwrite existing file or directory.
1050
+ * @default false
1051
+ */
1052
+ overwrite?: boolean | undefined;
1053
+ /**
1054
+ * Dereference symlinks.
1055
+ * @default false
1056
+ */
1057
+ dereference?: boolean | undefined;
1058
+ }
1059
+
1060
+
1061
+ type JsonOutputOptions = fs.WriteFileOptions & StringifyOptions;
1062
+
1063
+ export { type CopyFilterAsync, type CopyFilterSync, type CopyOptions, type CopyOptionsSync, type EnsureDirOptions, type JsonOutputOptions, type JFReadOptions as JsonReadOptions, type JFWriteOptions as JsonWriteOptions, type MoveOptions, type NoParamCallbackWithUndefined, type SymlinkType, access, appendFile, chmod, chown, close, copy, copyFile, copySync, createFile, createFileSync, createLink, createLinkSync, createSymlink, createSymlinkSync, emptyDir, emptyDirSync, emptydir, emptydirSync, ensureDir, ensureDirSync, ensureFile, ensureFileSync, ensureLink, ensureLinkSync, ensureSymlink, ensureSymlinkSync, exists, fchmod, fchown, fdatasync, fstat, fsync, ftruncate, futimes, lchmod, lchown, link, lstat, mkdir, mkdirp, mkdirpSync, mkdirs, mkdirsSync, mkdtemp, move, moveSync, open, opendir, outputFile, outputFileSync, outputJSON, outputJSONSync, outputJson, outputJsonSync, pathExists, pathExistsSync, read, readFile, readJSON, readJSONSync, readJson, readJsonSync, readdir, readlink, readv, realpath, remove, removeSync, rename, rm, rmdir, stat, symlink, truncate, unlink, utimes, write, writeFile, writeJSON, writeJSONSync, writeJson, writeJsonSync, writev };