Socket
Socket
Sign inDemoInstall

trash

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trash - npm Package Compare versions

Comparing version 4.3.0 to 5.0.0

index.d.ts

51

index.js

@@ -8,23 +8,32 @@ 'use strict';

const linux = require('./lib/linux');
const win = require('./lib/win');
const windows = require('./lib/windows');
module.exports = (iterable, opts) => pTry(() => {
iterable = Array.from(typeof iterable === 'string' ? [iterable] : iterable).map(String);
opts = Object.assign({glob: true}, opts);
const trash = (paths, options) => pTry(() => {
paths = (typeof paths === 'string' ? [paths] : paths).map(String);
const paths = (opts.glob === false ? iterable : globby.sync(iterable, {
expandDirectories: false,
nodir: false,
nonull: true
}))
.map(x => path.resolve(x))
.filter(x => {
options = {
glob: true,
...options
};
// TOOD: Upgrading to latest `globby` version is blocked by https://github.com/mrmlnc/fast-glob/issues/110
if (options.glob) {
paths = globby.sync(paths, {
expandDirectories: false,
nodir: false,
nonull: true
});
}
paths = paths
.map(filePath => path.resolve(filePath))
.filter(filePath => {
try {
return fs.lstatSync(x);
} catch (err) {
if (err.code === 'ENOENT') {
return fs.lstatSync(filePath);
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw err;
throw error;
}

@@ -38,6 +47,12 @@ });

switch (process.platform) {
case 'darwin': return macos(paths);
case 'win32': return win(paths);
default: return linux(paths);
case 'darwin':
return macos(paths);
case 'win32':
return windows(paths);
default:
return linux(paths);
}
});
module.exports = trash;
module.exports.default = trash;
'use strict';
const {promisify} = require('util');
const os = require('os');
const path = require('path');
const fsExtra = require('fs-extra');
const pify = require('pify');
const fs = require('fs');
const uuid = require('uuid');
const xdgTrashdir = require('xdg-trashdir');
const pMap = require('p-map');
const makeDir = require('make-dir');
const moveFile = require('move-file');
const fs = pify(fsExtra);
const pWriteFile = promisify(fs.writeFile);
function trash(src) {
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 = `
const trash = async filePath => {
const trashDirectory = await xdgTrashdir(filePath);
const name = uuid.v4();
const destination = path.join(trashDirectory, 'files', name);
const trashInfoPath = path.join(trashDirectory, 'info', `${name}.trashinfo`);
const trashInfoData = `
[Trash Info]
Path=${src.replace(/\s/g, '%20')}
Path=${filePath.replace(/\s/g, '%20')}
DeletionDate=${(new Date()).toISOString()}
`.trim();
return Promise.all([
fs.move(src, dest, {mkdirp: true}),
fs.outputFile(info, msg)
]).then(() => ({
path: dest,
info
}));
});
}
await Promise.all([
moveFile(filePath, destination),
(async () => {
// TODO: Use the `fs.mkdir` with `recursive` option when targeting Node.js 12.
await makeDir(path.dirname(trashInfoPath));
await pWriteFile(trashInfoPath, trashInfoData);
})()
]);
return {
path: destination,
info: trashInfoPath
};
};
module.exports = paths => pMap(paths, trash, {concurrency: os.cpus().length});
'use strict';
const {promisify} = require('util');
const os = require('os');
const path = require('path');
const execFile = require('child_process').execFile;
const {execFile} = require('child_process');
const escapeStringApplescript = require('escape-string-applescript');
const runApplescript = require('run-applescript');
const pify = require('pify');
const olderThanMountainLion = Number(os.release().split('.')[0]) < 12;
const isOlderThanMountainLion = Number(os.release().split('.')[0]) < 12;
const pExecFile = promisify(execFile);
// Binary source: https://github.com/sindresorhus/macos-trash
const bin = path.join(__dirname, 'macos-trash');
const binary = path.join(__dirname, 'macos-trash');
function legacy(paths) {
const pathStr = paths.map(x => `"${escapeStringApplescript(x)}"`).join(',');
const legacy = async paths => {
const pathString = paths.map(x => `"${escapeStringApplescript(x)}"`).join(',');
const script = `
set deleteList to {}
repeat with currentPath in {${pathStr}}
repeat with currentPath in {${pathString}}
set end of deleteList to POSIX file currentPath
end repeat
tell app "Finder" to delete deleteList
`.trim();
`.trim();
return runApplescript(script).catch(err => {
if (/10010/.test(err.message)) {
err = new Error('Item doesn\'t exist');
try {
await runApplescript(script);
} catch (error) {
let newError = error;
if (/10010/.test(newError.message)) {
newError = new Error('Item doesn\'t exist');
}
throw err;
});
}
throw newError;
}
};
module.exports = paths => {
if (olderThanMountainLion) {
return legacy(paths);
module.exports = async paths => {
if (isOlderThanMountainLion) {
await legacy(paths);
return;
}
return pify(execFile)(bin, paths);
await pExecFile(binary, paths);
};
{
"name": "trash",
"version": "4.3.0",
"description": "Move files and folders to the trash",
"license": "MIT",
"repository": "sindresorhus/trash",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"lib"
],
"keywords": [
"trash",
"recycle",
"bin",
"rm",
"rmrf",
"rimraf",
"remove",
"delete",
"del",
"file",
"files",
"dir",
"directory",
"directories",
"folder",
"folders",
"xdg"
],
"dependencies": {
"escape-string-applescript": "^2.0.0",
"fs-extra": "^0.30.0",
"globby": "^7.1.1",
"p-map": "^1.2.0",
"p-try": "^1.0.0",
"pify": "^3.0.0",
"run-applescript": "^3.0.0",
"uuid": "^3.1.0",
"xdg-trashdir": "^2.1.1"
},
"devDependencies": {
"ava": "*",
"tempfile": "^2.0.0",
"xo": "*"
}
"name": "trash",
"version": "5.0.0",
"description": "Move files and folders to the trash",
"license": "MIT",
"repository": "sindresorhus/trash",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts",
"lib"
],
"keywords": [
"trash",
"recycle",
"bin",
"rm",
"rmrf",
"rimraf",
"remove",
"delete",
"del",
"file",
"files",
"dir",
"directory",
"directories",
"folder",
"folders",
"xdg"
],
"dependencies": {
"escape-string-applescript": "^2.0.0",
"globby": "^7.1.1",
"make-dir": "^1.3.0",
"move-file": "^1.0.0",
"p-map": "^2.0.0",
"p-try": "^2.0.0",
"run-applescript": "^3.0.0",
"uuid": "^3.1.0",
"xdg-trashdir": "^2.1.1"
},
"devDependencies": {
"ava": "^1.0.0-rc.1",
"tempfile": "^2.0.0",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}

@@ -1,2 +0,2 @@

# ![trash](https://cdn.rawgit.com/sindresorhus/trash/1cdbd660976d739eeb45447bb6b62c41ac4a3ecf/media/logo.svg)
# ![trash](media/logo.svg)

@@ -24,5 +24,5 @@ > Move files and folders to the trash

trash(['*.png', '!rainbow.png']).then(() => {
console.log('done');
});
(async () => {
await trash(['*.png', '!rainbow.png']);
})();
```

@@ -39,3 +39,3 @@

Type: `Iterable<string>`
Type: `string` `string[]`

@@ -42,0 +42,0 @@ Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc