Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 31, 2019
1 parent 75c270b commit bdfbd07
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
52 changes: 36 additions & 16 deletions index.d.ts
@@ -1,18 +1,38 @@
export interface Options {
/**
* Enable globbing when matching file paths.
*
* @default true
*/
readonly glob?: boolean;
declare namespace trash {
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>;
declare const trash: {
/**
Move files and folders to the trash.
@param input - Accepts paths and [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@example
```
import trash = require('trash');
(async () => {
await trash(['*.png', '!rainbow.png']);
})();
```
*/
(input: string | string[], options?: trash.Options): Promise<void>;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function trash(
// input: string | string[],
// options?: Options
// ): Promise<void>;
// export = trash;
default: typeof trash;
};

export = trash;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -53,4 +53,5 @@ const trash = (paths, options) => pTry(() => {
});

module.exports = trash;
// TODO: Remove this for the next major release
module.exports.default = trash;
4 changes: 2 additions & 2 deletions index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import trash from '.';
import {expectType} from 'tsd';
import trash = require('.');

expectType<Promise<void>>(trash('/path/to/item1'));
expectType<Promise<void>>(trash(['/path/to/item1', '/path/to/item2']));
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -43,17 +43,17 @@
"escape-string-applescript": "^2.0.0",
"globby": "^7.1.1",
"make-dir": "^1.3.0",
"move-file": "^1.0.0",
"move-file": "^1.1.0",
"p-map": "^2.0.0",
"p-try": "^2.0.0",
"run-applescript": "^3.0.0",
"uuid": "^3.1.0",
"p-try": "^2.2.0",
"run-applescript": "^3.2.0",
"uuid": "^3.3.2",
"xdg-trashdir": "^2.1.1"
},
"devDependencies": {
"ava": "^1.0.0-rc.1",
"ava": "^1.4.1",
"tempfile": "^2.0.0",
"tsd-check": "^0.3.0",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit bdfbd07

Please sign in to comment.