diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..55394b7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ +/** +Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). +*/ +export default function stripAnsi(str: string): string; diff --git a/index.js b/index.js index 96e0292..2d6ebcc 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,7 @@ 'use strict'; const ansiRegex = require('ansi-regex'); -module.exports = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input; +const stripAnsi = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input; + +module.exports = stripAnsi; +module.exports.default = stripAnsi; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..29d4f66 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd-check'; +import stripAnsi from '.'; + +expectType(stripAnsi('\u001b[4mcake\u001b[0m')); diff --git a/package.json b/package.json index b81cb21..3be60ac 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": [ "strip", @@ -46,7 +47,8 @@ "ansi-regex": "^4.1.0" }, "devDependencies": { - "ava": "^0.25.0", - "xo": "^0.23.0" + "ava": "^1.3.1", + "tsd-check": "^0.5.0", + "xo": "^0.24.0" } }