Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add TypeScript definition (#81)
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 8, 2019
1 parent 27018aa commit c029c43
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
18 changes: 18 additions & 0 deletions index.d.ts
@@ -0,0 +1,18 @@
export interface Options {
/**
* Enable globbing when matching file paths.
*
* @default true
*/
readonly glob?: boolean;
}

/**
* Move files and folders to the trash.
*
* @param input - Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
*/
export default function trash(
input: string | string[],
options?: Options
): Promise<void>;
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -7,7 +7,7 @@ const macos = require('./lib/macos');
const linux = require('./lib/linux');
const windows = require('./lib/windows');

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

options = {
Expand Down Expand Up @@ -51,3 +51,6 @@ module.exports = (paths, options) => pTry(() => {
return linux(paths);
}
});

module.exports = trash;
module.exports.default = trash;
8 changes: 8 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,8 @@
import {expectType} from 'tsd-check';
import trash from '.';

expectType<Promise<void>>(trash('/path/to/item1'));
expectType<Promise<void>>(trash(['/path/to/item1', '/path/to/item2']));
expectType<Promise<void>>(
trash(['/path/to/item1', '/path/to/item2'], {glob: false})
);
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -13,10 +13,11 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts",
"lib"
],
"keywords": [
Expand Down Expand Up @@ -52,6 +53,7 @@
"devDependencies": {
"ava": "^1.0.0-rc.1",
"tempfile": "^2.0.0",
"xo": "^0.23.0"
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
1 change: 1 addition & 0 deletions test.js
Expand Up @@ -51,6 +51,7 @@ test('no glob', async t => {
if (process.platform !== 'win32') {
fs.writeFileSync('fixture-noglob*.js', '');
}

fs.writeFileSync('fixture-noglob1.js', '');

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

0 comments on commit c029c43

Please sign in to comment.