File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
ext/node/polyfills/internal/util Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 2525
2626import {
2727 validateObject ,
28+ validateOneOf ,
2829 validateString ,
2930} from "ext:deno_node/internal/validators.mjs" ;
3031import { codes } from "ext:deno_node/internal/error_codes.ts" ;
@@ -562,10 +563,20 @@ export function stripVTControlCharacters(str) {
562563 return str . replace ( ansi , "" ) ;
563564}
564565
566+ export function styleText ( format , text ) {
567+ validateString ( text , "text" ) ;
568+ const formatCodes = inspect . colors [ format ] ;
569+ if ( formatCodes == null ) {
570+ validateOneOf ( format , "format" , Object . keys ( inspect . colors ) ) ;
571+ }
572+ return `\u001b[${ formatCodes [ 0 ] } m${ text } \u001b[${ formatCodes [ 1 ] } m` ;
573+ }
574+
565575export default {
566576 format,
567577 getStringWidth,
568578 inspect,
569579 stripVTControlCharacters,
570580 formatWithOptions,
581+ styleText,
571582} ;
You can’t perform that action at this time.
0 commit comments