Skip to content

Commit c029c43

Browse files
BendingBendersindresorhus
authored andcommittedMar 8, 2019
Add TypeScript definition (#81)
1 parent 27018aa commit c029c43

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed
 

‎index.d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface Options {
2+
/**
3+
* Enable globbing when matching file paths.
4+
*
5+
* @default true
6+
*/
7+
readonly glob?: boolean;
8+
}
9+
10+
/**
11+
* Move files and folders to the trash.
12+
*
13+
* @param input - Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
14+
*/
15+
export default function trash(
16+
input: string | string[],
17+
options?: Options
18+
): Promise<void>;

‎index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const macos = require('./lib/macos');
77
const linux = require('./lib/linux');
88
const windows = require('./lib/windows');
99

10-
module.exports = (paths, options) => pTry(() => {
10+
const trash = (paths, options) => pTry(() => {
1111
paths = (typeof paths === 'string' ? [paths] : paths).map(String);
1212

1313
options = {
@@ -51,3 +51,6 @@ module.exports = (paths, options) => pTry(() => {
5151
return linux(paths);
5252
}
5353
});
54+
55+
module.exports = trash;
56+
module.exports.default = trash;

‎index.test-d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {expectType} from 'tsd-check';
2+
import trash from '.';
3+
4+
expectType<Promise<void>>(trash('/path/to/item1'));
5+
expectType<Promise<void>>(trash(['/path/to/item1', '/path/to/item2']));
6+
expectType<Promise<void>>(
7+
trash(['/path/to/item1', '/path/to/item2'], {glob: false})
8+
);

‎package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
1919
"index.js",
20+
"index.d.ts",
2021
"lib"
2122
],
2223
"keywords": [
@@ -52,6 +53,7 @@
5253
"devDependencies": {
5354
"ava": "^1.0.0-rc.1",
5455
"tempfile": "^2.0.0",
55-
"xo": "^0.23.0"
56+
"tsd-check": "^0.3.0",
57+
"xo": "^0.24.0"
5658
}
5759
}

‎test.js

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ test('no glob', async t => {
5151
if (process.platform !== 'win32') {
5252
fs.writeFileSync('fixture-noglob*.js', '');
5353
}
54+
5455
fs.writeFileSync('fixture-noglob1.js', '');
5556

5657
await trash(['fixture-noglob*.js'], {glob: false});

0 commit comments

Comments
 (0)
Please sign in to comment.