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 #6

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
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"
}
}