@visulima/ansi
Version:
ANSI escape codes for some terminal swag.
24 lines (23 loc) • 917 B
text/typescript
/**
* Removes ANSI escape codes from a string.
*
* This function first removes OSC (Operating System Command) sequences like title strings
* (e.g., `\u001B]0;title\u0007`) and then uses a comprehensive regex (from the `ansi-regex` package)
* to strip all other ANSI escape codes.
* @param input The string from which to remove ANSI escape codes.
* @returns The input string with all ANSI escape codes stripped.
* @example
* ```typescript
* import { strip } from "@visulima/ansi";
*
* const textWithAnsi = "\x1b[32mHello, \x1b[1mWorld!\x1b[0m";
* const strippedText = strip(textWithAnsi);
* console.log(strippedText); // Output: "Hello, World!"
*
* const titleSequence = "\u001B]0;My Window Title\u0007Some content";
* const strippedTitle = strip(titleSequence);
* console.log(strippedTitle); // Output: "Some content"
* ```
*/
declare const strip: (input: string) => string;
export default strip;