-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
166a0d5
commit e77ea17
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {expectType} from 'tsd'; | ||
import ansiRegex from '.'; | ||
|
||
expectType<RegExp>(ansiRegex()); | ||
expectType<RegExp>(ansiRegex({onlyFirst: true})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters