Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TypeScript definition to CommonJS compatible export #82

Merged
merged 1 commit into from Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
}
}