@lpm.dev/neo.ansi

Pool

ansi

Modern, zero-dependency ANSI escape code parser and stripper - beats strip-ansi by 10%+

install @lpm.dev/neo.ansi

hasAnsi

function
function hasAnsi(input: string): boolean

Check if string contains ANSI escape codes This is a fast check for the 7-bit ESC introducer and supported 8-bit C1 introducers/terminators. It intentionally does not perform full parsing.

Parameters

inputstringInput string to check

Returns

booleantrue if the string contains ESC or a supported C1 control

Example

hasAnsi('\x1b[31mRed\x1b[0m')  // => true
hasAnsi('Plain text')          // => false
hasAnsi('')                    // => false