Comparing version 3.4.2 to 4.0.0
24
index.js
'use strict'; | ||
var path = require('path'); | ||
var pathExists = require('path-exists'); | ||
var globby = require('globby'); | ||
var macos = require('./lib/macos'); | ||
var linux = require('./lib/linux'); | ||
var win = require('./lib/win'); | ||
const path = require('path'); | ||
const pathExists = require('path-exists'); | ||
const globby = require('globby'); | ||
const macos = require('./lib/macos'); | ||
const linux = require('./lib/linux'); | ||
const win = require('./lib/win'); | ||
module.exports = function (paths) { | ||
if (!Array.isArray(paths)) { | ||
return Promise.reject(new TypeError('Expected an array')); | ||
} | ||
paths = globby.sync(paths.map(String), {nonull: true}) | ||
.map(function (x) { | ||
return path.resolve(x); | ||
}) | ||
module.exports = iterable => { | ||
const paths = globby.sync(Array.from(iterable).map(String), {nonull: true}) | ||
.map(x => path.resolve(x)) | ||
.filter(pathExists.sync); | ||
@@ -19,0 +13,0 @@ |
'use strict'; | ||
var path = require('path'); | ||
var fsExtra = require('fs-extra'); | ||
var pify = require('pify'); | ||
var Promise = require('pinkie-promise'); | ||
var uuid = require('uuid'); | ||
var xdgTrashdir = require('xdg-trashdir'); | ||
const path = require('path'); | ||
const fsExtra = require('fs-extra'); | ||
const pify = require('pify'); | ||
const uuid = require('uuid'); | ||
const xdgTrashdir = require('xdg-trashdir'); | ||
var fs = pify(fsExtra, Promise); | ||
const fs = pify(fsExtra); | ||
function trash(src) { | ||
return xdgTrashdir(src).then(function (dir) { | ||
var name = uuid.v4(); | ||
var dest = path.join(dir, 'files', name); | ||
var info = path.join(dir, 'info', name + '.trashinfo'); | ||
var msg = [ | ||
'[Trash Info]', | ||
'Path=' + src.replace(/\s/g, '%20'), | ||
'DeletionDate=' + new Date().toISOString() | ||
].join('\n'); | ||
return xdgTrashdir(src).then(dir => { | ||
const name = uuid.v4(); | ||
const dest = path.join(dir, 'files', name); | ||
const info = path.join(dir, 'info', `${name}.trashinfo`); | ||
const msg = ` | ||
[Trash Info] | ||
Path=${src.replace(/\s/g, '%20')} | ||
DeletionDate=${(new Date()).toISOString()} | ||
`.trim(); | ||
@@ -25,13 +24,9 @@ return Promise.all([ | ||
fs.outputFile(info, msg) | ||
]).then(function () { | ||
return { | ||
path: dest, | ||
info: info | ||
}; | ||
}); | ||
]).then(() => ({ | ||
path: dest, | ||
info | ||
})); | ||
}); | ||
} | ||
module.exports = function (paths) { | ||
return Promise.all(paths.map(trash)); | ||
}; | ||
module.exports = paths => Promise.all(paths.map(trash)); |
'use strict'; | ||
var os = require('os'); | ||
var path = require('path'); | ||
var execFile = require('child_process').execFile; | ||
var escapeStringApplescript = require('escape-string-applescript'); | ||
var runApplescript = require('run-applescript'); | ||
var pify = require('pify'); | ||
var Promise = require('pinkie-promise'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const execFile = require('child_process').execFile; | ||
const escapeStringApplescript = require('escape-string-applescript'); | ||
const runApplescript = require('run-applescript'); | ||
const pify = require('pify'); | ||
var olderThanMountainLion = Number(os.release().split('.')[0]) < 12; | ||
var bin = path.join(__dirname, 'macos-trash'); | ||
const olderThanMountainLion = Number(os.release().split('.')[0]) < 12; | ||
// binary source: https://github.com/sindresorhus/macos-trash | ||
const bin = path.join(__dirname, 'macos-trash'); | ||
function legacy(paths) { | ||
var script = | ||
'set deleteList to {}\n' + | ||
'repeat with currentPath in {' + paths.map(function (el) { | ||
return '"' + escapeStringApplescript(el) + '"'; | ||
}).join(',') + '}\n' + | ||
'set end of deleteList to POSIX file currentPath\n' + | ||
'end repeat\n' + | ||
'tell app "Finder" to delete deleteList'; | ||
const pathStr = paths.map(x => `"${escapeStringApplescript(x)}"`).join(','); | ||
const script = ` | ||
set deleteList to {} | ||
repeat with currentPath in {${pathStr}} | ||
set end of deleteList to POSIX file currentPath | ||
end repeat | ||
tell app "Finder" to delete deleteList | ||
`.trim(); | ||
return runApplescript(script) | ||
.catch(function (err) { | ||
if (/10010/.test(err.message)) { | ||
throw new Error('Item doesn\'t exist'); | ||
} | ||
return runApplescript(script).catch(err => { | ||
if (/10010/.test(err.message)) { | ||
err = new Error('Item doesn\'t exist'); | ||
} | ||
throw err; | ||
}); | ||
throw err; | ||
}); | ||
} | ||
module.exports = function (paths) { | ||
module.exports = paths => { | ||
if (olderThanMountainLion) { | ||
@@ -38,3 +38,3 @@ return legacy(paths); | ||
return pify(execFile, Promise)(bin, paths); | ||
return pify(execFile)(bin, paths); | ||
}; |
'use strict'; | ||
var path = require('path'); | ||
var execFile = require('child_process').execFile; | ||
var Promise = require('pinkie-promise'); | ||
var pify = require('pify'); | ||
const path = require('path'); | ||
const execFile = require('child_process').execFile; | ||
const pify = require('pify'); | ||
var bin = path.join(__dirname, 'win-trash.exe'); | ||
// binary source: https://github.com/sindresorhus/recycle-bin | ||
const bin = path.join(__dirname, 'win-trash.exe'); | ||
module.exports = function (paths) { | ||
return pify(execFile, Promise)(bin, paths); | ||
}; | ||
module.exports = paths => pify(execFile)(bin, paths); |
{ | ||
"name": "trash", | ||
"version": "3.4.2", | ||
"version": "4.0.0", | ||
"description": "Move files and folders to the trash", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
@@ -44,8 +44,7 @@ "scripts": { | ||
"escape-string-applescript": "^1.0.0", | ||
"fs-extra": "^0.26.2", | ||
"globby": "^4.0.0", | ||
"path-exists": "^2.0.0", | ||
"fs-extra": "^0.30.0", | ||
"globby": "^6.0.0", | ||
"path-exists": "^3.0.0", | ||
"pify": "^2.3.0", | ||
"pinkie-promise": "^2.0.0", | ||
"run-applescript": "^2.0.0", | ||
"run-applescript": "^3.0.0", | ||
"uuid": "^2.0.1", | ||
@@ -58,3 +57,6 @@ "xdg-trashdir": "^2.0.0" | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
@@ -29,5 +29,15 @@ # ![trash](https://cdn.rawgit.com/sindresorhus/trash/1cdbd660976d739eeb45447bb6b62c41ac4a3ecf/media/logo.svg) | ||
*You can use [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).* | ||
## API | ||
### trash(input) | ||
Returns a `Promise`. | ||
#### input | ||
Type: `Iterable<string>` | ||
Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). | ||
## CLI | ||
@@ -34,0 +44,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
75
33793
86
+ Addedcross-spawn@6.0.5(transitive)
+ Addedexeca@0.10.0(transitive)
+ Addedfs-extra@0.30.0(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedglobby@6.1.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedrun-applescript@3.2.0(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
- Removedpinkie-promise@^2.0.0
- Removedarrify@1.0.1(transitive)
- Removedfs-extra@0.26.7(transitive)
- Removedglob@6.0.4(transitive)
- Removedglobby@4.1.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedrun-applescript@2.1.0(transitive)
Updatedfs-extra@^0.30.0
Updatedglobby@^6.0.0
Updatedpath-exists@^3.0.0
Updatedrun-applescript@^3.0.0