From f43ce03cf572dfa24e7de3b2d983526b5d8d77e2 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 31 Mar 2019 12:13:04 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#6) --- index.d.ts | 33 +++++++++++++++++++++------------ index.js | 1 + index.test-d.ts | 4 ++-- package.json | 6 +++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/index.d.ts b/index.d.ts index 77e0fa3..845ceaa 100644 --- a/index.d.ts +++ b/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; diff --git a/index.js b/index.js index f49a3a8..98f8ce4 100644 --- a/index.js +++ b/index.js @@ -12,4 +12,5 @@ const widestLine = input => { }; module.exports = widestLine; +// TODO: remove this in the next major version module.exports.default = widestLine; diff --git a/index.test-d.ts b/index.test-d.ts index e9a5477..c036faf 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd-check'; -import widestLine from '.'; +import {expectType} from 'tsd'; +import widestLine = require('.'); expectType(widestLine('古\n\u001B[1m@\u001B[22m')); diff --git a/package.json b/package.json index 388e4ed..a32fbef 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=8" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -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" } }