Code Monkey home page Code Monkey logo

delete's Introduction

delete NPM version NPM monthly downloads NPM total downloads Linux Build Status

Delete files and folders and any intermediate directories if they exist (sync and async).

Install

Install with npm:

$ npm install --save delete

Usage

var del = require('delete');

// async
del(['foo/*.js'], function(err, deleted) {
  if (err) throw err;
  // deleted files
  console.log(deleted);
});

// sync
del.sync(['foo/*.js']);

// promise
del.promise(['foo/*.js'])
  .then(function(deleted) {
    // deleted files
    console.log(deleted)
  });

Options

All methods take an options object as the second argument.

options.force

Type: boolean

Default: undefined

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

Examples

del.sync('../foo.md', {force: true});

del('.', {force: true}, function(err, files) {
  // do stuff with err
  console.log(files);
});

del.promise('./', {force: true})
  .then(function(files) {
    console.log(files);
  })

(This option was inspired by settings in grunt.)

About

Related projects

  • copy: Copy files or directories using globs. | homepage
  • export-files: node.js utility for exporting a directory of files as modules. | homepage
  • micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | homepage
  • write: Write files to disk, creating intermediate directories if they don't exist. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

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:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 02, 2017.

delete's People

Contributors

jonschlinkert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

delete's Issues

drop the `.promise` method

Or use some promise lib or do some workaround. Currently it calls the glob.sync method which not make any sense - so, something like async response/method sync operation. With that .promise method you just return a promise, but actually behind the scenes everything is sync, nothing is async. Does make users think they really do some async operation, because they got promise, but in real it's not async.

Hope you got correctly my state. Just noticed some things and share thoughts. Dropping it make more sense instead as it is currently. Or at least, make a not on readme, imho.

Cheers.

Version incompatibility

In v0.3.0 it was possible to call the async del method without a callback, in v0.3.1 this throws an error due to the callback being undefined.

I can provide a pull request if desired.

Deletion failed in other directories

build/deletePm2Logs.js

let del = require('delete')

console.log('start delete logs')

del(['../logs/*.log'], {force: true}, function(err, deleted) {
  if (err) {
    console.log('fail')
  } else {
    console.log('success');
  }
});

command:
node build/deletePm2Logs.js

It prompt success, but it's not deleted

other info:
parameter delete is empty array

Singular

The description is a bit misleading:

Delete files and folders and any intermediate directories if they exist (sync and async).

Since it only delete's one file/folder at the time, so should be (especially in package.json):

Delete a file or folder and any intermediate directories if they exist (sync and async).

Got a comment that it's confusing people on http://gulpjs.com/plugins/ since both says the same:

screen shot 2014-09-22 at 16 30 25

Would you consider removing the gulpfriendly keyword? When used with gulp you don't really care about the extra deps and want the flexibility of globs. So having two very similar things is a bit confusing to people it seems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.