選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

readme.md 3.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # del [![Build Status](https://travis-ci.org/sindresorhus/del.svg?branch=master)](https://travis-ci.org/sindresorhus/del) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
  2. > Delete files and folders using [globs](https://github.com/isaacs/minimatch#usage)
  3. Similar to [rimraf](https://github.com/isaacs/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.
  4. ---
  5. <p align="center">🐶</p>
  6. <p align="center"><b>Support this project and improve your JavaScript skills with this great <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos.</b><br>Try his free <a href="https://javascript30.com/friend/AWESOME">JavaScript 30 course</a> for a taste of what to expect. You might also like his <a href="https://ReactForBeginners.com/friend/AWESOME">React</a> and <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> course.</p>
  7. ---
  8. ## Install
  9. ```
  10. $ npm install --save del
  11. ```
  12. ## Usage
  13. ```js
  14. const del = require('del');
  15. del(['tmp/*.js', '!tmp/unicorn.js']).then(paths => {
  16. console.log('Deleted files and folders:\n', paths.join('\n'));
  17. });
  18. ```
  19. ## Beware
  20. The glob pattern `**` matches all children and *the parent*.
  21. So this won't work:
  22. ```js
  23. del.sync(['public/assets/**', '!public/assets/goat.png']);
  24. ```
  25. You have to explicitly ignore the parent directories too:
  26. ```js
  27. del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);
  28. ```
  29. Suggestions on how to improve this welcome!
  30. ## API
  31. ### del(patterns, [options])
  32. Returns a promise for an array of deleted paths.
  33. ### del.sync(patterns, [options])
  34. Returns an array of deleted paths.
  35. #### patterns
  36. Type: `string` `Array`
  37. See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage).
  38. - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test.js)
  39. - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
  40. #### options
  41. Type: `Object`
  42. See the [`glob` options](https://github.com/isaacs/node-glob#options).
  43. ##### force
  44. Type: `boolean`<br>
  45. Default: `false`
  46. Allow deleting the current working directory and outside.
  47. ##### dryRun
  48. Type: `boolean`<br>
  49. Default: `false`
  50. See what would be deleted.
  51. ```js
  52. const del = require('del');
  53. del(['tmp/*.js'], {dryRun: true}).then(paths => {
  54. console.log('Files and folders that would be deleted:\n', paths.join('\n'));
  55. });
  56. ```
  57. ##### concurrency
  58. Type: `number`<br>
  59. Default: `Infinity`<br>
  60. Minimum: `1`
  61. Concurrency limit.
  62. ## CLI
  63. See [del-cli](https://github.com/sindresorhus/del-cli) for a CLI for this module and [trash-cli](https://github.com/sindresorhus/trash-cli) for a safe version that is suitable for running by hand.
  64. ## Related
  65. - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
  66. - [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching
  67. ## License
  68. MIT © [Sindre Sorhus](https://sindresorhus.com)