UNPKG

tty-strings

Version:

Tools for working with strings displayed in the terminal

26 lines 847 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ansiRegex_1 = require("./ansiRegex"); const regex = (0, ansiRegex_1.default)(); /** * Remove ANSI escape codes from a string. * * @remarks * This method is adapted from chalk's {@link https://github.com/chalk/strip-ansi|`strip-ansi`} package, * but uses a more comprehensive regular expression to match escape sequences. * * @example * ```ts * import { stripAnsi } from 'tty-strings'; * * const stripped = stripAnsi('\x1b[32mfoo\x1b[39m'); // 'foo' * ``` * * @param string - Input string to strip. * @returns The input string with all ANSI escape codes removed. */ function stripAnsi(string) { return (typeof string === 'string') ? string.replace(regex, '') : String(string); } exports.default = stripAnsi; //# sourceMappingURL=stripAnsi.js.map