diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..2500c20 --- /dev/null +++ b/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; diff --git a/index.js b/index.js index c98a4ae..f49a3a8 100644 --- a/index.js +++ b/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')) { @@ -10,3 +10,6 @@ module.exports = input => { return max; }; + +module.exports = widestLine; +module.exports.default = widestLine; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..e9a5477 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd-check'; +import widestLine from '.'; + +expectType(widestLine('古\n\u001B[1m@\u001B[22m')); diff --git a/package.json b/package.json index 4578af2..ff99ba2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } }