Skip to content

Commit

Permalink
Add TypeScript definition (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 18, 2019
1 parent 5cb7e20 commit 89dc7f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions 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;
5 changes: 4 additions & 1 deletion 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;
4 changes: 4 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,4 @@
import {expectType} from 'tsd-check';
import stripAnsi from '.';

expectType<string>(stripAnsi('\u001b[4mcake\u001b[0m'));
10 changes: 6 additions & 4 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": [
"strip",
Expand Down Expand Up @@ -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"
}
}

0 comments on commit 89dc7f6

Please sign in to comment.