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 3364582 commit 6a8de4f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
35 changes: 29 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
/**
* Convert a camelized/dasherized/underscored string into a humanized one: `fooBar-Baz_Faz` → `Foo bar baz faz`.
*
* @param text - The string to make human readable.
*/
export default function humanizeString(text: string): string;
declare const humanizeString: {
/**
Convert a camelized/dasherized/underscored string into a humanized one: `fooBar-Baz_Faz` → `Foo bar baz faz`.
@param text - The string to make human readable.
@example
```
import humanizeString = require('humanize-string');
humanizeString('fooBar');
//=> 'Foo bar'
humanizeString('foo-bar');
//=> 'Foo bar'
humanizeString('foo_bar');
//=> 'Foo bar'
```
*/
(text: string): string;

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

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

module.exports = humanizeString;
// TODO: Remove this for the next major release
module.exports.default = humanizeString;
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 humanizeString from '.';
import {expectType} from 'tsd';
import humanizeString = require('.');

expectType<string>(humanizeString('fooBar'));
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 @@ -38,8 +38,8 @@
"decamelize": "^2.0.0"
},
"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 6a8de4f

Please sign in to comment.