ansi-regex
Advanced tools
Comparing version 3.0.0 to 4.0.0
10
index.js
'use strict'; | ||
module.exports = () => { | ||
module.exports = options => { | ||
options = Object.assign({ | ||
onlyFirst: false | ||
}, options); | ||
const pattern = [ | ||
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', | ||
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))' | ||
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' | ||
].join('|'); | ||
return new RegExp(pattern, 'g'); | ||
return new RegExp(pattern, options.onlyFirst ? undefined : 'g'); | ||
}; |
102
package.json
{ | ||
"name": "ansi-regex", | ||
"version": "3.0.0", | ||
"description": "Regular expression for matching ANSI escape codes", | ||
"license": "MIT", | ||
"repository": "chalk/ansi-regex", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava", | ||
"view-supported": "node fixtures/view-codes.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"ansi", | ||
"styles", | ||
"color", | ||
"colour", | ||
"colors", | ||
"terminal", | ||
"console", | ||
"cli", | ||
"string", | ||
"tty", | ||
"escape", | ||
"formatting", | ||
"rgb", | ||
"256", | ||
"shell", | ||
"xterm", | ||
"command-line", | ||
"text", | ||
"regex", | ||
"regexp", | ||
"re", | ||
"match", | ||
"test", | ||
"find", | ||
"pattern" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "ansi-regex", | ||
"version": "4.0.0", | ||
"description": "Regular expression for matching ANSI escape codes", | ||
"license": "MIT", | ||
"repository": "chalk/ansi-regex", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava", | ||
"view-supported": "node fixtures/view-codes.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"ansi", | ||
"styles", | ||
"color", | ||
"colour", | ||
"colors", | ||
"terminal", | ||
"console", | ||
"cli", | ||
"string", | ||
"tty", | ||
"escape", | ||
"formatting", | ||
"rgb", | ||
"256", | ||
"shell", | ||
"xterm", | ||
"command-line", | ||
"text", | ||
"regex", | ||
"regexp", | ||
"re", | ||
"match", | ||
"test", | ||
"find", | ||
"pattern" | ||
], | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"xo": "^0.23.0" | ||
} | ||
} |
@@ -26,5 +26,24 @@ # ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex) | ||
//=> ['\u001B[4m', '\u001B[0m'] | ||
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true})); | ||
//=> ['\u001B[4m'] | ||
``` | ||
## API | ||
### ansiRegex([options]) | ||
Returns a regex for matching ANSI escape codes. | ||
#### options | ||
##### onlyFirst | ||
Type: `boolean`<br> | ||
Default: `false` *(Matches any ANSI escape codes in a string)* | ||
Match only the first ANSI escape. | ||
## FAQ | ||
@@ -31,0 +50,0 @@ |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4364
11
66
0