diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..203e012 --- /dev/null +++ b/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; diff --git a/index.js b/index.js index 334d0e1..97077a0 100644 --- a/index.js +++ b/index.js @@ -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 = { @@ -51,3 +51,6 @@ module.exports = (paths, options) => pTry(() => { return linux(paths); } }); + +module.exports = trash; +module.exports.default = trash; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..b55a268 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,8 @@ +import {expectType} from 'tsd-check'; +import trash from '.'; + +expectType>(trash('/path/to/item1')); +expectType>(trash(['/path/to/item1', '/path/to/item2'])); +expectType>( + trash(['/path/to/item1', '/path/to/item2'], {glob: false}) +); diff --git a/package.json b/package.json index f2d81e6..75e4eb4 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "node": ">=8" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava && tsd-check" }, "files": [ "index.js", + "index.d.ts", "lib" ], "keywords": [ @@ -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" } } diff --git a/test.js b/test.js index 569c7a4..48364e3 100644 --- a/test.js +++ b/test.js @@ -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});