This package provides pretty-print logging functions for Node.js.
npm install @nopecha/pprint
Add to the top of the entry file of the project.
import '@nopecha/pprint'
The above will expose the pretty-print logging functions to the global scope.
Replace console
with global
to color-code terminal outputs in Node.js.
Available are trace
, debug
, info
, log
, warn
, and error
.
global.trace() // Red
global.debug('this is green')
global.info('this is cyan')
global.warn('this is yellow')
global.error('this is red')
global.log('this does not have a color yet')
Add color to log
messages. Color codes are prefixed with !
in their own string.
global.log('!r', 'this is red')
global.log('!g', 'this is green')
global.log('!b', 'this is blue')
Add background colors with a second color code.
global.log('!rb', 'this is red on blue')
Add text styles with a third color code.
global.log('!uwd', 'underlined') // underlined, white on dark
global.log('!bdw', 'bolded') // bolded, dark on white
global.log('!igw', 'italicized') // italicized, green on white
Multiple colors can be used in a single log statement.
Note that all color code strings including "!"
are zero width, except "! "
where a color-stop code can contain a space that is left untrimmed.
global.log('!r', 'this is red', '!', ' this is normal ', '!b', 'blue', '! ', 'normal')
© 2024 NopeCHA, LLC