ansi-regex

  • Version 6.1.0
  • Published
  • 5.41 kB
  • No dependencies
  • MIT license

Install

npm i ansi-regex
yarn add ansi-regex
pnpm add ansi-regex

Overview

Regular expression for matching ANSI escape codes

Index

Functions

Type Aliases

Functions

function ansiRegex

ansiRegex: (options?: Options) => RegExp;
  • Regular expression for matching ANSI escape codes.

    Example 1

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

Type Aliases

type Options

type Options = {
/**
Match only the first ANSI escape.
@default false
*/
readonly onlyFirst: boolean;
};

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (4)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ansi-regex.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ansi-regex)
    • HTML
      <a href="https://www.jsdocs.io/package/ansi-regex"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>