ansi-regex

2019-01-12 admin

ansi-regex是什么

什么是ansi-regex,Regular expression for matching ANSI escape codes

ansi-regex使用教程帮助文档

ansi-regex Build Status

Regular expression for matching ANSI escape codes


<div align=“center”>Get professional support for this package with a Tidelift subscription <sub>Tidelift helps make open source sustainable for maintainers while giving companies assurances about security, maintenance, and licensing for their dependencies.</sub></div>


Install

$ npm install ansi-regex

Usage

const 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']

API

ansiRegex([options])

Returns a regex for matching ANSI escape codes.

options

onlyFirst

Type: boolean Default: false (Matches any ANSI escape codes in a string)

Match only the first ANSI escape.

FAQ

Why do you test for codes not in the ECMA 48 standard?

Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.

On the historical side, those ECMA standards were established in the early 90’s whereas the VT100, for example, was designed in the mid/late 70’s. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar ‘anarchy’ of codes is in the x86 architecture for processors; there are a ton of “interrupts” that can mean different things on certain brands of processors, most of which have been phased out.

Security

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Maintainers

License

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-50791.html

文章标题:ansi-regex

回到顶部