diff --git a/ext/node/polyfills/internal/util/inspect.mjs b/ext/node/polyfills/internal/util/inspect.mjs index f702c39c5d..2f9167dfb2 100644 --- a/ext/node/polyfills/internal/util/inspect.mjs +++ b/ext/node/polyfills/internal/util/inspect.mjs @@ -25,6 +25,7 @@ import { validateObject, + validateOneOf, validateString, } from "ext:deno_node/internal/validators.mjs"; import { codes } from "ext:deno_node/internal/error_codes.ts"; @@ -562,10 +563,20 @@ export function stripVTControlCharacters(str) { return str.replace(ansi, ""); } +export function styleText(format, text) { + validateString(text, "text"); + const formatCodes = inspect.colors[format]; + if (formatCodes == null) { + validateOneOf(format, "format", Object.keys(inspect.colors)); + } + return `\u001b[${formatCodes[0]}m${text}\u001b[${formatCodes[1]}m`; +} + export default { format, getStringWidth, inspect, stripVTControlCharacters, formatWithOptions, + styleText, };