1.2.1 • Published 2 years ago

@squirrel-forge/node-cfx v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@squirrel-forge/node-cfx

Node stdout/console styler, replace the basic console methods and allow for coloured output.

Install

npm i @squirrel-forge/node-cfx

Example output

@squirrel-forge/node-cfx example text output

Usage

Getting and using a default instance.

const { cfx, ASCIIREF, OutputStyler } = require( '@squirrel-forge/node-cfx' );
cfx.log( '[ul][fgreen]underlined green text[re]' );

Default styled output.

cfx.success( 'success' );
cfx.error( 'error' );
cfx.warn( 'warning' );
cfx.info( 'info' );

Get a styled string:

const str = cfx.setStyle( '[ul][fgreen]underlined green text[re]' ); // \x1b[4m\x1b[32munderlined green text\x1b[0m

To enable automatic prefixing with the current timestamp set the prependTime property:

cfx.prependTime = true;

To change the timestamp style, use the timestampPrefix and timestampSuffix properties:

cfx.timestampPrefix = '[fwhite][[re][th]';
cfx.timestampSuffix = '[re][fwhite]][re] ';

Setting a custom timestamp format, see time-stamp for details.

cfx.timestampFormat = 'YYYY-MM-DD HH:mm:ss';

Styling options

Control and text style

CodeControlCodeText
reResetboBold
rvReversethThin
--ulUnderline
--blBlink
--hdHidden

Text and background colors

TextBackgroundColor
fblackbblackBlack
fredbredRed
fgreenbgreenGreen
fyellowbyellowYellow
fbluebblueBlue
fmagentabmagentaMagenta
fcyanbcyanCyan
fwhitebwhiteWhite

Overriding default styles

Default styles and reset.

cfx.style = {
    error : '[bred][fwhite] ',
    warn : '[byellow][fblack] ',
    info : '[bblack][fcyan] ',
    success : '[bgreen][fblack] ',
};
this.styleReset = ' [re]';

Default reset, used when no other reset is passed to the internal _write method, useful when making your own style methods.

cfx.defaultReset = ' [re]';

Issues and docs

If you encounter any issues, please report here.


Check the sourcecode on github for detailed comments.