From f4164fa4c3754d6256f9f90e16db1c53cc33afbf Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 19 Sep 2021 17:44:33 -0400 Subject: [PATCH] util: expose stripVTControlCharacters() This commit exposes the existing stripVTControlCharacters() method with docs and some additional input validation. PR-URL: https://github.com/nodejs/node/pull/40214 Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- doc/api/util.md | 15 +++++++++++++++ lib/internal/util/inspect.js | 3 +++ lib/util.js | 4 +++- test/parallel/test-util.js | 10 +++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index 8ca9d240b1f141..208e3a84d513bd 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -1109,6 +1109,21 @@ doSomething[kCustomPromisifiedSymbol] = (foo) => { }; ``` +## `util.stripVTControlCharacters(str)` + + +* `str` {string} +* Returns: {string} + +Returns `str` with any ANSI escape codes removed. + +```js +console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m')); +// Prints "value" +``` + ## Class: `util.TextDecoder`