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 #32

Merged
merged 10 commits into from Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
33 changes: 33 additions & 0 deletions index.d.ts
@@ -0,0 +1,33 @@
// TypeScript Version: 3.6.3

interface Options {
onlyFirst: boolean;
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Regular expression for matching ANSI escape codes

@example
```
import ansiRegex from 'ansi-regex';

ansiRegex().test('\u001B[4mcake\u001B[0m');
//=> true

ansiRegex().test('cake');
//=> false

'\u001B[4mcake\u001B[0m'.match(ansiRegex());
//=> ['\u001B[4m', '\u001B[0m']

'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
//=> ['\u001B[4m']

'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
```
*/

declare function ansiRegex(options?: Options): RegExp;

export = ansiRegex;
4 changes: 4 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,4 @@
import ansiRegex from '.';
import {expectType} from 'tsd';

expectType<RegExp>(ansiRegex());
Akim95 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -13,11 +13,12 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava",
"test": "xo && ava && tsd",
"view-supported": "node fixtures/view-codes.js"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"ansi",
Expand Down Expand Up @@ -48,6 +49,7 @@
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.9.0",
"xo": "^0.24.0"
}
}