ansi-regex

WebJar for ansi-regex

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

ansi-regex
Last Version

Last Version

6.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

ansi-regex
WebJar for ansi-regex
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/chalk/ansi-regex

Download ansi-regex

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/ansi-regex/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>ansi-regex</artifactId>
    <version>6.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/ansi-regex/
implementation 'org.webjars.npm:ansi-regex:6.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/ansi-regex/
implementation ("org.webjars.npm:ansi-regex:6.0.0")
'org.webjars.npm:ansi-regex:jar:6.0.0'
<dependency org="org.webjars.npm" name="ansi-regex" rev="6.0.0">
  <artifact name="ansi-regex" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='ansi-regex', version='6.0.0')
)
libraryDependencies += "org.webjars.npm" % "ansi-regex" % "6.0.0"
[org.webjars.npm/ansi-regex "6.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ansi-regex

Regular expression for matching ANSI escape codes

Install

$ npm install ansi-regex

Usage

import ansiRegex from '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']

API

ansiRegex(options?)

Returns a regex for matching ANSI escape codes.

options

Type: object

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.

Maintainers


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
org.webjars.npm

chalk

Terminal string styling done right

Versions

Version
6.0.0
5.0.1
5.0.0
4.1.0
4.0.0
3.0.0
2.1.1
2.0.0
1.1.1
0.2.1