Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent 45996f2 commit 20dba2c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
27 changes: 15 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
declare const unusedFilename: {
/**
* Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
*
* @param filePath - The path to check for filename collision.
* @returns Either the original `filename` or the `filename` appended with a number.
*/
Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
@param filePath - The path to check for filename collision.
@returns Either the original `filename` or the `filename` appended with a number.
*/
(filePath: string): Promise<string>;

/**
* Synchronously get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
*
* @param filePath - The path to check for filename collision.
* @returns Either the original `filename` or the `filename` appended with a number.
*/
Synchronously get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`.
@param filePath - The path to check for filename collision.
@returns Either the original `filename` or the `filename` appended with a number.
*/
sync(filePath: string): string;
}

export default unusedFilename;
// TODO: Remove this for the next major release
default: typeof unusedFilename;
};

export = unusedFilename;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const unusedFilename = filePath => {
};

module.exports = unusedFilename;
// TODO: Remove this for the next major release
module.exports.default = unusedFilename;

module.exports.sync = filePath => {
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import unusedFilename from '.';
import {expectType} from 'tsd';
import unusedFilename = require('.');

expectType<Promise<string>>(unusedFilename('rainbow.txt'));
expectType<string>(unusedFilename.sync('rainbow.txt'));
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -36,11 +36,11 @@
],
"dependencies": {
"modify-filename": "^1.1.0",
"path-exists": "^3.0.0"
"path-exists": "^4.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit 20dba2c

Please sign in to comment.