From 396b14b6c642affd46b0533f5af7c31e073ad29a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 19 Sep 2021 17:44:33 -0400 Subject: [PATCH 1/2] 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 ea8bbd5e286887..576db37779fc30 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -1111,6 +1111,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`