Commit 0fb67ce 1 parent 9df917c commit 0fb67ce Copy full SHA for 0fb67ce
File tree 1 file changed +11
-0
lines changed
ext/node/polyfills/internal/util
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 25
25
26
26
import {
27
27
validateObject ,
28
+ validateOneOf ,
28
29
validateString ,
29
30
} from "ext:deno_node/internal/validators.mjs" ;
30
31
import { codes } from "ext:deno_node/internal/error_codes.ts" ;
@@ -562,10 +563,20 @@ export function stripVTControlCharacters(str) {
562
563
return str . replace ( ansi , "" ) ;
563
564
}
564
565
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
+
565
575
export default {
566
576
format,
567
577
getStringWidth,
568
578
inspect,
569
579
stripVTControlCharacters,
570
580
formatWithOptions,
581
+ styleText,
571
582
} ;
You can’t perform that action at this time.
0 commit comments