版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1 год назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # del
  2. > Delete files and directories using [globs](https://github.com/sindresorhus/globby#globbing-patterns)
  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. ## Install
  5. ```
  6. $ npm install del
  7. ```
  8. ## Usage
  9. ```js
  10. const del = require('del');
  11. (async () => {
  12. const deletedFilePaths = await del(['temp/*.js', '!temp/unicorn.js']);
  13. const deletedDirectoryPaths = await del(['temp', 'public']);
  14. console.log('Deleted files:\n', deletedFilePaths.join('\n'));
  15. console.log('\n\n');
  16. console.log('Deleted directories:\n', deletedDirectoryPaths.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. To delete all subdirectories inside `public/`, you can do:
  30. ```js
  31. del.sync(['public/*/']);
  32. ```
  33. Suggestions on how to improve this welcome!
  34. ## API
  35. 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()`.
  36. ### del(patterns, options?)
  37. Returns `Promise<string[]>` with the deleted paths.
  38. ### del.sync(patterns, options?)
  39. Returns `string[]` with the deleted paths.
  40. #### patterns
  41. Type: `string | string[]`
  42. See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
  43. - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
  44. - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)
  45. #### options
  46. Type: `object`
  47. You can specify any of the [`globby` options](https://github.com/sindresorhus/globby#options) in addition to the below options. In contrast to the `globby` defaults, `expandDirectories`, `onlyFiles`, and `followSymbolicLinks` are `false` by default.
  48. ##### force
  49. Type: `boolean`\
  50. Default: `false`
  51. Allow deleting the current working directory and outside.
  52. ##### dryRun
  53. Type: `boolean`\
  54. Default: `false`
  55. See what would be deleted.
  56. ```js
  57. const del = require('del');
  58. (async () => {
  59. const deletedPaths = await del(['temp/*.js'], {dryRun: true});
  60. console.log('Files and directories that would be deleted:\n', deletedPaths.join('\n'));
  61. })();
  62. ```
  63. ##### concurrency
  64. Type: `number`\
  65. Default: `Infinity`\
  66. Minimum: `1`
  67. Concurrency limit.
  68. ##### onProgress
  69. Type: `(progress: ProgressData) => void`
  70. Called after each file or directory is deleted.
  71. ```js
  72. import del from 'del';
  73. await del(patterns, {
  74. onProgress: progress => {
  75. // …
  76. }});
  77. ```
  78. ###### ProgressData
  79. ```js
  80. {
  81. totalCount: number,
  82. deletedCount: number,
  83. percent: number
  84. }
  85. ```
  86. - `percent` is a value between `0` and `1`
  87. ## CLI
  88. 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.
  89. ## del for enterprise
  90. Available as part of the Tidelift Subscription.
  91. 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.](https://tidelift.com/subscription/pkg/npm-del?utm_source=npm-del&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
  92. ## Related
  93. - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
  94. - [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching