forked from sindresorhus/trash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (36 loc) · 937 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const fs = require('fs');
const path = require('path');
const globby = require('globby');
const pTry = require('p-try');
const macos = require('./lib/macos');
const linux = require('./lib/linux');
const win = require('./lib/win');
module.exports = (iterable, opts) => pTry(() => {
iterable = Array.from(typeof iterable === 'string' ? [iterable] : iterable).map(String);
opts = Object.assign({glob: true}, opts);
const paths = (opts.glob === false ? iterable : globby.sync(iterable, {
expandDirectories: false,
nodir: false,
nonull: true
}))
.map(x => path.resolve(x))
.filter(x => {
try {
return fs.lstatSync(x);
} catch (err) {
if (err.code === 'ENOENT') {
return false;
}
throw err;
}
});
if (paths.length === 0) {
return;
}
switch (process.platform) {
case 'darwin': return macos(paths);
case 'win32': return win(paths);
default: return linux(paths);
}
});