Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 31, 2019
1 parent 7d5a88f commit f43ce03
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
33 changes: 21 additions & 12 deletions index.d.ts
@@ -1,12 +1,21 @@
/**
Get the visual width of the widest line in a string - the number of columns required to display it.
@example
```
import widestLine from 'widest-line';
widestLine('古\n\u001B[1m@\u001B[22m');
//=> 2
```
*/
export default function widestLine(input: string): number;
declare const widestLine: {
/**
Get the visual width of the widest line in a string - the number of columns required to display it.
@example
```
import widestLine = require('widest-line');
widestLine('古\n\u001B[1m@\u001B[22m');
//=> 2
```
*/
(input: string): number;

// TODO: remove this in the next major version, refactor definition to:
// declare function widestLine(input: string): number;
// export = widestLine;
default: typeof widestLine;
};

export = widestLine;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -12,4 +12,5 @@ const widestLine = input => {
};

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

expectType<number>(widestLine('古\n\u001B[1m@\u001B[22m'));
6 changes: 3 additions & 3 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 @@ -47,8 +47,8 @@
"string-width": "^4.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.5.0",
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit f43ce03

Please sign in to comment.