1 | # delete [![NPM version](https://img.shields.io/npm/v/delete.svg?style=flat)](https://www.npmjs.com/package/delete) [![NPM monthly downloads](https://img.shields.io/npm/dm/delete.svg?style=flat)](https://npmjs.org/package/delete) [![NPM total downloads](https://img.shields.io/npm/dt/delete.svg?style=flat)](https://npmjs.org/package/delete) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/delete.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/delete)
|
2 |
|
3 | > Delete files and folders and any intermediate directories if they exist (sync and async).
|
4 |
|
5 | ## Install
|
6 |
|
7 | Install with [npm](https://www.npmjs.com/):
|
8 |
|
9 | ```sh
|
10 | $ npm install --save delete
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | var del = require('delete');
|
17 |
|
18 | // async
|
19 | del(['foo/*.js'], function(err, deleted) {
|
20 | if (err) throw err;
|
21 | // deleted files
|
22 | console.log(deleted);
|
23 | });
|
24 |
|
25 | // sync
|
26 | del.sync(['foo/*.js']);
|
27 |
|
28 | // promise
|
29 | del.promise(['foo/*.js'])
|
30 | .then(function(deleted) {
|
31 | // deleted files
|
32 | console.log(deleted)
|
33 | });
|
34 | ```
|
35 |
|
36 | ## Options
|
37 |
|
38 | All methods take an `options` object as the second argument.
|
39 |
|
40 | ### options.force
|
41 |
|
42 | **Type**: `boolean`
|
43 |
|
44 | **Default**: `undefined`
|
45 |
|
46 | By default, error is thrown if you try to delete either the current working directory itself, or files outside of the current working directory (e.g. parent directories).
|
47 |
|
48 | **Examples**
|
49 |
|
50 | ```js
|
51 | del.sync('../foo.md', {force: true});
|
52 |
|
53 | del('.', {force: true}, function(err, files) {
|
54 | // do stuff with err
|
55 | console.log(files);
|
56 | });
|
57 |
|
58 | del.promise('./', {force: true})
|
59 | .then(function(files) {
|
60 | console.log(files);
|
61 | })
|
62 | ```
|
63 |
|
64 | _(This option was inspired by settings in [grunt](http://gruntjs.com/).)_
|
65 |
|
66 | ## About
|
67 |
|
68 | ### Related projects
|
69 |
|
70 | * [copy](https://www.npmjs.com/package/copy): Copy files or directories using globs. | [homepage](https://github.com/jonschlinkert/copy "Copy files or directories using globs.")
|
71 | * [export-files](https://www.npmjs.com/package/export-files): node.js utility for exporting a directory of files as modules. | [homepage](https://github.com/jonschlinkert/export-files "node.js utility for exporting a directory of files as modules.")
|
72 | * [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
|
73 | * [write](https://www.npmjs.com/package/write): Write files to disk, creating intermediate directories if they don't exist. | [homepage](https://github.com/jonschlinkert/write "Write files to disk, creating intermediate directories if they don't exist.")
|
74 |
|
75 | ### Contributing
|
76 |
|
77 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
78 |
|
79 | ### Building docs
|
80 |
|
81 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
82 |
|
83 | To generate the readme, run the following command:
|
84 |
|
85 | ```sh
|
86 | $ npm install -g verbose/verb#dev verb-generate-readme && verb
|
87 | ```
|
88 |
|
89 | ### Running tests
|
90 |
|
91 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
92 |
|
93 | ```sh
|
94 | $ npm install && npm test
|
95 | ```
|
96 |
|
97 | ### Author
|
98 |
|
99 | **Jon Schlinkert**
|
100 |
|
101 | * [github/jonschlinkert](https://github.com/jonschlinkert)
|
102 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
103 |
|
104 | ### License
|
105 |
|
106 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
|
107 | Released under the [MIT License](LICENSE).
|
108 |
|
109 | ***
|
110 |
|
111 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 15, 2017._ |
\ | No newline at end of file |