-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 <hemanth.hm@gmail.com> PR-URL: #51850 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
- Loading branch information
1 parent
861e040
commit c501346
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'); |