Big update!Introducing GitHub Bot Commands. Learn more
Socket
BlogLoveLog in
Book a demo

del

Package Overview
Dependencies
8
Maintainers
1
Versions
26
Issues
File Explorer

Advanced tools

del

Delete files and directories

    7.0.0latest

Version published
Maintainers
1
Weekly downloads
15,357,039
increased by1.6%

Weekly downloads

Changelog

Source

Breaking

  • Require Node.js 14 (#143) 106d7d8
  • This package is now pure ESM. Please read this.
  • Moved from a default export to named exports:
    • require('del')import {deleteAsync} from 'del'
    • require('del').syncimport {deleteSync} from 'del'

https://github.com/sindresorhus/del/compare/v6.1.1...v7.0.0

Readme

Source

del

Delete files and directories using globs

Similar to rimraf, but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above.

Install

npm install del

Usage

import {deleteAsync} from 'del'; const deletedFilePaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']); const deletedDirectoryPaths = await deleteAsync(['temp', 'public']); console.log('Deleted files:\n', deletedFilePaths.join('\n')); console.log('\n\n'); console.log('Deleted directories:\n', deletedDirectoryPaths.join('\n'));

Beware

The glob pattern ** matches all children and the parent.

So this won't work:

deleteSync(['public/assets/**', '!public/assets/goat.png']);

You have to explicitly ignore the parent directories too:

deleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);

To delete all subdirectories inside public/, you can do:

deleteSync(['public/*/']);

Suggestions on how to improve this welcome!

API

Note 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().

deleteAsync(patterns, options?)

Returns Promise<string[]> with the deleted paths.

deleteSync(patterns, options?)

Returns string[] with the deleted paths.

patterns

Type: string | string[]

See the supported glob patterns.

options

Type: object

You can specify any of the globby options in addition to the below options. In contrast to the globby defaults, expandDirectories, onlyFiles, and followSymbolicLinks are false by default.

force

Type: boolean
Default: false

Allow deleting the current working directory and outside.

dryRun

Type: boolean
Default: false

See what would be deleted.

import {deleteAsync} from 'del'; const deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true}); console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n'));
concurrency

Type: number
Default: Infinity
Minimum: 1

Concurrency limit.

onProgress

Type: (progress: ProgressData) => void

Called after each file or directory is deleted.

import {deleteAsync} from 'del'; await deleteAsync(patterns, { onProgress: progress => { // … }});
ProgressData
{ totalCount: number, deletedCount: number, percent: number }
  • percent is a value between 0 and 1

CLI

See del-cli for a CLI for this module and trash-cli for a safe version that is suitable for running by hand.

del for enterprise

Available as part of the Tidelift Subscription.

The maintainers of del and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

  • make-dir - Make a directory and its parents if needed
  • globby - User-friendly glob matching

Keywords

FAQs

What is del?

Delete files and directories

Is del popular?

The npm package del receives a total of 14,758,126 weekly downloads. As such, del popularity was classified as popular.

Is del well maintained?

We found that del demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 19 Jul 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc