{"id":13396764,"url":"https://github.com/sindresorhus/del","last_synced_at":"2025-05-13T21:07:33.338Z","repository":{"id":18036423,"uuid":"21078071","full_name":"sindresorhus/del","owner":"sindresorhus","description":"Delete files and directories","archived":false,"fork":false,"pushed_at":"2024-10-07T04:55:37.000Z","size":84,"stargazers_count":1331,"open_issues_count":17,"forks_count":62,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-04-24T05:26:33.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-06-21T20:24:49.000Z","updated_at":"2025-04-17T16:24:11.000Z","dependencies_parsed_at":"2022-06-26T03:43:53.829Z","dependency_job_id":"94197ad4-b68c-4a1a-b810-468d20d8aaab","html_url":"https://github.com/sindresorhus/del","commit_stats":{"total_commits":118,"total_committers":24,"mean_commits":4.916666666666667,"dds":0.288135593220339,"last_synced_commit":"51344d2ec4efece380768c44f3cc74f2b2c06590"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/del/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250968874,"owners_count":21515680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:02.441Z","updated_at":"2025-04-28T12:10:50.073Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["文件","JavaScript","Packages","Repository","包","Filesystem","目录","Uncategorized","Plugins","插件","[Node.js](http://nodejs.org/) feature module and bundler"],"sub_categories":["Filesystem","文件系统","Uncategorized","Miscellaneous Plugins","其他插件"],"readme":"# del\n\n\u003e Delete files and directories using [globs](https://github.com/sindresorhus/globby#globbing-patterns)\n\nSimilar 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.\n\n## Install\n\n```sh\nnpm install del\n```\n\n## Usage\n\n```js\nimport {deleteAsync} from 'del';\n\nconst deletedFilePaths = await deleteAsync(['temp/*.js', '!temp/unicorn.js']);\nconst deletedDirectoryPaths = await deleteAsync(['temp', 'public']);\n\nconsole.log('Deleted files:\\n', deletedFilePaths.join('\\n'));\nconsole.log('\\n\\n');\nconsole.log('Deleted directories:\\n', deletedDirectoryPaths.join('\\n'));\n```\n\n## Beware\n\nThe glob pattern `**` matches all children and *the parent*.\n\nSo this won't work:\n\n```js\ndeleteSync(['public/assets/**', '!public/assets/goat.png']);\n```\n\nYou have to explicitly ignore the parent directories too:\n\n```js\ndeleteSync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);\n```\n\nTo delete all subdirectories inside `public/`, you can do:\n\n```js\ndeleteSync(['public/*/']);\n```\n\nSuggestions on how to improve this welcome!\n\n## API\n\nNote 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()`.\n\n### deleteAsync(patterns, options?)\n\nReturns `Promise\u003cstring[]\u003e` with the deleted paths.\n\n### deleteSync(patterns, options?)\n\nReturns `string[]` with the deleted paths.\n\n#### patterns\n\nType: `string | string[]`\n\nSee the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).\n\n- [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)\n- [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns)\n\n#### options\n\nType: `object`\n\nYou 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.\n\n##### force\n\nType: `boolean`\\\nDefault: `false`\n\nAllow deleting the current working directory and outside.\n\n##### dryRun\n\nType: `boolean`\\\nDefault: `false`\n\nSee what would be deleted.\n\n```js\nimport {deleteAsync} from 'del';\n\nconst deletedPaths = await deleteAsync(['temp/*.js'], {dryRun: true});\n\nconsole.log('Files and directories that would be deleted:\\n', deletedPaths.join('\\n'));\n```\n\n##### dot\n\nType: `boolean`\\\nDefault: `false`\n\nAllow patterns to match files/folders that start with a period (`.`).\n\nThis option is passed through to [`fast-glob`](https://github.com/mrmlnc/fast-glob#dot).\n\nNote that an explicit dot in a portion of the pattern will always match dot files.\n\n**Example**\n\n```\ndirectory/\n├── .editorconfig\n└── package.json\n```\n\n```js\nimport {deleteSync} from 'del';\n\ndeleteSync('*', {dot: false});\n//=\u003e ['package.json']\ndeleteSync('*', {dot: true});\n//=\u003e ['.editorconfig', 'package.json']\n```\n\n##### concurrency\n\nType: `number`\\\nDefault: `Infinity`\\\nMinimum: `1`\n\nConcurrency limit.\n\n##### onProgress\n\nType: `(progress: ProgressData) =\u003e void`\n\nCalled after each file or directory is deleted.\n\n```js\nimport {deleteAsync} from 'del';\n\nawait deleteAsync(patterns, {\n\tonProgress: progress =\u003e {\n\t// …\n}});\n```\n\n###### ProgressData\n\n```js\n{\n\ttotalCount: number,\n\tdeletedCount: number,\n\tpercent: number,\n\tpath?: string\n}\n```\n\n- `percent` is a value between `0` and `1`\n- `path` is the absolute path of the deleted file or directory. It will not be present if nothing was deleted.\n\n## CLI\n\nSee [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.\n\n## Related\n\n- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed\n- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fdel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fdel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fdel/lists"}