UNPKG

3.53 kBTypeScriptView Raw
1import {type Options as GlobbyOptions} from 'globby';
2
3export type ProgressData = {
4 /**
5 Deleted files and directories count.
6 */
7 readonly deletedCount: number;
8
9 /**
10 Total files and directories count.
11 */
12 readonly totalCount: number;
13
14 /**
15 Completed percentage. A value between `0` and `1`.
16 */
17 readonly percent: number;
18
19 /**
20 The absolute path of the deleted file or directory.
21
22 It will not be present if nothing was deleted.
23 */
24 readonly path?: string;
25};
26
27export type Options = {
28 /**
29 Allow deleting the current working directory and outside.
30
31 @default false
32 */
33 readonly force?: boolean;
34
35 /**
36 See what would be deleted.
37
38 @default false
39
40 @example
41 ```
42 import {deleteAsync} from 'del';
43
44 const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true});
45
46 console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n'));
47 ```
48 */
49 readonly dryRun?: boolean;
50
51 /**
52 Concurrency limit. Minimum: `1`.
53
54 @default Infinity
55 */
56 readonly concurrency?: number;
57
58 /**
59 Called after each file or directory is deleted.
60
61 @example
62 ```
63 import {deleteAsync} from 'del';
64
65 await deleteAsync(patterns, {
66 onProgress: progress => {
67 // …
68 }});
69 ```
70 */
71 readonly onProgress?: (progress: ProgressData) => void;
72} & GlobbyOptions;
73
74/**
75Delete files and directories using glob patterns.
76
77Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`.
78
79@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
80- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
81- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
82@param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default.
83@returns The deleted paths.
84
85@example
86```
87import {deleteAsync} from 'del';
88
89const deletedPaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']);
90
91console.log('Deleted files and directories:\n', deletedPaths.join('\n'));
92```
93*/
94export function deleteAsync(
95 patterns: string | readonly string[],
96 options?: Options
97): Promise<string[]>;
98
99/**
100Synchronously delete files and directories using glob patterns.
101
102Note that glob patterns can only contain forward-slashes, not backward-slashes. Windows file paths can use backward-slashes as long as the path does not contain any glob-like characters, otherwise use `path.posix.join()` instead of `path.join()`.
103
104@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
105- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
106- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
107@param options - You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the `del` options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default.
108@returns The deleted paths.
109*/
110export function deleteSync(
111 patterns: string | readonly string[],
112 options?: Options
113): string[];