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

Add TypeScript definition #5

Merged
merged 1 commit into from Mar 18, 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
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"
}
}