Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 1, 2019
1 parent 1b9dbc6 commit 578e6a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
32 changes: 26 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/**
* Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`.
*
* @param input - The string to titleize.
*/
export default function titleize(input: string): string;
declare const titleize: {
/**
Capitalize every word in a string: `unicorn cake` → `Unicorn Cake`.
@param input - The string to titleize.
@example
```
import titleize = require('titleize');
titleize('foo bar');
//=> 'Foo Bar'
titleize('foo-bar');
//=> 'Foo-Bar'
```
*/
(input: string): string;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function titleize(input: string): string;
// export = titleize;
default: typeof titleize;
};

export = titleize;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const titleize = input => {
};

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

expectType<string>(titleize('foo bar'));
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -32,8 +32,8 @@
"convert"
],
"devDependencies": {
"ava": "^1.2.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit 578e6a9

Please sign in to comment.