mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(node/util): styleText (#22758)
Implements https://github.com/nodejs/node/pull/51850
This commit is contained in:
parent
9df917c0be
commit
0fb67ce43e
1 changed files with 11 additions and 0 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue