-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: add styleText API to text formatting
Co-Authored-By: Hemanth HM <[email protected]> PR-URL: #51850 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Adrian Estrada <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
- Loading branch information
1 parent
8dc3f91
commit 88e08bb
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
|
||
[ | ||
undefined, | ||
null, | ||
false, | ||
5n, | ||
5, | ||
Symbol(), | ||
() => {}, | ||
{}, | ||
[], | ||
].forEach((invalidOption) => { | ||
assert.throws(() => { | ||
util.styleText(invalidOption, 'test'); | ||
}, { | ||
code: 'ERR_INVALID_ARG_VALUE', | ||
}); | ||
assert.throws(() => { | ||
util.styleText('red', invalidOption); | ||
}, { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
}); | ||
|
||
assert.throws(() => { | ||
util.styleText('invalid', 'text'); | ||
}, { | ||
code: 'ERR_INVALID_ARG_VALUE', | ||
}); | ||
|
||
assert.strictEqual(util.styleText('red', 'test'), '\u001b[31mtest\u001b[39m'); |