Skip to content

Commit

Permalink
Add TypeScript definition (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 18, 2019
1 parent c20aa7f commit 1a5ac93
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions index.d.ts
@@ -0,0 +1,4 @@
/**
Get the visual width of the widest line in a string - the number of columns required to display it.
*/
export default function widestLine(input: string): number;
5 changes: 4 additions & 1 deletion index.js
@@ -1,7 +1,7 @@
'use strict';
const stringWidth = require('string-width');

module.exports = input => {
const widestLine = input => {
let max = 0;

for (const line of input.split('\n')) {
Expand All @@ -10,3 +10,6 @@ module.exports = input => {

return max;
};

module.exports = widestLine;
module.exports.default = widestLine;
4 changes: 4 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,4 @@
import {expectType} from 'tsd-check';
import widestLine from '.';

expectType<number>(widestLine('古\n\u001B[1m@\u001B[22m'));
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"string",
Expand Down Expand Up @@ -44,10 +45,11 @@
"fixed-width"
],
"dependencies": {
"string-width": "^2.1.1"
"string-width": "^3.1.0"
},
"devDependencies": {
"ava": "^0.25.0",
"xo": "^0.23.0"
"ava": "^1.3.1",
"tsd-check": "^0.5.0",
"xo": "^0.24.0"
}
}

0 comments on commit 1a5ac93

Please sign in to comment.