Installations
npm install trash
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.20.2
NPM Version
10.6.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (97.29%)
TypeScript (2.71%)
Developer
sindresorhus
Download Statistics
Total Downloads
18,979,937
Last Day
4,774
Last Week
31,227
Last Month
287,231
Last Year
3,935,079
GitHub Statistics
2,585 Stars
156 Commits
79 Forks
26 Watching
1 Branches
24 Contributors
Sponsor this package
Package Meta Information
Latest Version
9.0.0
Package Id
trash@9.0.0
Unpacked Size
218.46 kB
Size
59.41 kB
File Count
11
NPM Version
10.6.0
Node Version
18.20.2
Publised On
26 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
18,979,937
Last day
-35.1%
4,774
Compared to previous day
Last week
-50.6%
31,227
Compared to previous week
Last month
-28.3%
287,231
Compared to previous month
Last year
2.5%
3,935,079
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
Move files and folders to the trash
Works on macOS (10.12+), Linux, and Windows (8+).
Note: The Linux implementation is not very good and not maintained. Help welcome. If no one steps up to help maintain it, I will eventually remove Linux support.
In contrast to fs.unlink
, del
, and rimraf
which permanently delete files, this only moves them to the trash, which is much safer and reversible.
Install
1npm install trash
Usage
1import trash from 'trash'; 2 3await trash(['*.png', '!rainbow.png']);
API
trash(input, options?)
Returns a Promise
.
input
Type: string | string[]
Accepts paths and glob patterns.
options
Type: object
glob
Type: boolean
Default: true
Enable globbing when matching file paths.
CLI
To install the trash
command, run:
1npm install --global trash-cli
Info
On macOS, macos-trash
is used.
On Linux, the XDG spec is followed.
On Windows, recycle-bin
is used.
FAQ
But I can do the same thing with mv
Not really. The mv
command isn't cross-platform and moving to trash is not just about moving the file to a "trash" directory. On all OSes you'll run into file conflicts. The user won't easily be able to restore the file. It won't work on an external drive. The trash directory location varies between Windows versions. For Linux, there's a whole spec you need to follow. On macOS, you'll lose the Put back feature.
Related
- trash-cli - CLI for this module
- empty-trash - Empty the trash
- del - Delete files and folders
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
binaries present in source code
Details
- Warn: binary detected: lib/macos-trash:1
- Warn: binary detected: lib/windows-trash.exe:1
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/trash/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/trash/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:26
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More