Skip to content

Commit

Permalink
filter out non-existing paths
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 14, 2015
1 parent 1b045d2 commit 34e4d71
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var path = require('path');
var pathExists = require('path-exists');

module.exports = function (paths) {
if (!Array.isArray(paths)) {
Expand All @@ -10,8 +11,10 @@ module.exports = function (paths) {
return Promise.resolve();
}

paths = paths.map(function (el) {
return path.resolve(String(el));
paths = paths.map(function (x) {
return path.resolve(String(x));
}).filter(function (x) {
return pathExists.sync(x);
});

if (process.platform === 'darwin') {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "trash",
"version": "3.0.0",
"description": "Move files and directories to the trash",
"description": "Move files and folders to the trash",
"license": "MIT",
"repository": "sindresorhus/trash",
"author": {
Expand Down Expand Up @@ -34,11 +34,14 @@
"dir",
"directory",
"directories",
"folder",
"folders",
"xdg"
],
"dependencies": {
"escape-string-applescript": "^1.0.0",
"fs-extra": "^0.24.0",
"path-exists": "^2.0.0",
"pify": "^2.2.0",
"pinkie-promise": "^1.0.0",
"run-applescript": "^2.0.0",
Expand All @@ -47,7 +50,6 @@
},
"devDependencies": {
"ava": "*",
"path-exists": "^2.0.0",
"tempfile": "^1.1.1",
"xo": "*"
},
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ![trash](https://cdn.rawgit.com/sindresorhus/trash/1cdbd660976d739eeb45447bb6b62c41ac4a3ecf/media/logo.svg)

> Move files and directories to the trash
> Move files and folders to the trash
[![Build Status](https://travis-ci.org/sindresorhus/trash.svg?branch=master)](https://travis-ci.org/sindresorhus/trash)

Expand Down Expand Up @@ -45,7 +45,7 @@ Not really. The `mv` command isn't cross-platform and moving to trash is not jus

- [trash-cli](https://github.com/sindresorhus/trash-cli) - CLI for this module
- [empty-trash](https://github.com/sindresorhus/empty-trash) - Empty the trash
- [del](https://github.com/sindresorhus/del) - Delete files/folders using globs
- [del](https://github.com/sindresorhus/del) - Delete files and folders using globs


## License
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('files', async t => {
fs.writeFileSync('fixture', '');
fs.writeFileSync('fixture2', '');
fs.writeFileSync(weirdName, '');
fs.writeFileSync('123');
fs.writeFileSync('123', '');
t.true(pathExists.sync('fixture'));
t.true(pathExists.sync('fixture2'));
t.true(pathExists.sync(weirdName));
Expand Down

0 comments on commit 34e4d71

Please sign in to comment.