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 all 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
37 changes: 37 additions & 0 deletions index.d.ts
@@ -0,0 +1,37 @@
declare namespace ansiRegex {
interface Options {
/**
Match only the first ANSI escape.

@default false
*/
onlyFirst: boolean;
}
}

/**
Regular expression for matching ANSI escape codes.

@example
```
import ansiRegex = require('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?: ansiRegex.Options): RegExp;

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

expectType<RegExp>(ansiRegex());
Akim95 marked this conversation as resolved.
Show resolved Hide resolved
expectType<RegExp>(ansiRegex({onlyFirst: true}));
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"
}
}