del
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
globby | 13.2.2 | 6.82 kB | MIT | prod | |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod | |
is-glob | 4.0.3 | 4.16 kB | MIT | prod | |
is-path-cwd | 3.0.0 | 1.71 kB | MIT | prod | |
is-path-inside | 4.0.0 | 1.95 kB | MIT | prod | |
p-map | 5.5.0 | 5.27 kB | MIT | prod | |
rimraf | 3.0.2 | 6.33 kB | ISC | prod | |
slash | 4.0.0 | 1.96 kB | MIT | prod |
Del is a powerful npm package that provides a way to delete files and directories using globbing patterns. Similar to the Rimraf package, Del offers a Promise API and support for multiple files and globbing. It also carries an essential safety feature that protects your current working directory and directories above it from accidental deletion.
To get started with Del, install the package by running npm install del
in your project directory.
Del can be used to delete specific files, exclude certain files, or delete directories. Here's a sample snippet:
import {deleteAsync} from 'del';
const deletedFilePaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']);
console.log('Deleted files:\n', deletedFilePaths.join('\n'));
The code above deletes all .js
files in the temp
directory, but it won't delete the unicorn.js
. The list of deleted files is then logged to the console.
Package also provides synchronous version of the delete method:
import {deleteSync} from 'del';
const deletedDirectoryPaths = deleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
The code above deletes all subdirectories and files within public/assets
directory but leaves intact public/assets
and goat.png
file. Resulting array of deleted paths is then assigned to deletedDirectoryPaths
.
Be aware that glob pattern **
matches all children and the parent. Therefore, if you wish to exclude any parent directories from deletion, you'll have to explicitly ignore them.
Del's documentation is available in the readme content on the project's GitHub page. The readme provides a comprehensive guide on how to use del, the API methods available, and examples for different use cases. You can check the options parameter that can be passed to the deleteAsync
and deleteSync
methods for more control over file deletion operations. For any glob related documentation, refer to the supported glob patterns.