Skip to content

Commit

Permalink
style: fix formatting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdUlHamedMaree committed May 5, 2024
1 parent 1d7ed58 commit 1f7c4c2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
export interface Options {
/**
/**
Match only the first ANSI escape.
@default false
*/
readonly onlyFirst?: boolean;
readonly onlyFirst?: boolean;
}


/**
Regular expression for matching ANSI escape codes.
Expand All @@ -31,11 +30,11 @@ ansiRegex().test('cake');
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
```
*/
export default function ansiRegex({ onlyFirst = false }: Options = {}) {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
].join('|');
export default function ansiRegex({onlyFirst = false}: Options = {}) {
const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
].join('|');

return new RegExp(pattern, onlyFirst ? undefined : 'g');
return new RegExp(pattern, onlyFirst ? undefined : 'g');
}

0 comments on commit 1f7c4c2

Please sign in to comment.