A tool that provides color and style printing.
It works as console.log logger, so make sure you can use it.
Use npm or yarn.
npm i @huiyan/color-log
yarn add @huiyan/color-log
The basic usage is as follows:
const { colorlog } = require('@huiyan/color-log');
colorlog.log('This is the log print.');
colorlog.info('This is the info print.');
colorlog.success('This is the success print.');
colorlog.warn('This is the warn print.');
colorlog.error('This is the error print.');
colorlog.banner('This is the banner print.', 'red');
colorlog.text('This is the text print.', 'dim');
colorlog.text('This is the text print.', ['underline', 'bright']);
In addition, the last parameter of the function can control the behavior after printing by passing the callback function.
The parameter of the callback function is the basic information of this printing, and this parameter will also be returned.
export type Result = {
content: string,
type: string,
value?: string
};
export type Callback = (options: Result) => unknown;
You can also preview the printing effect by using the test function.
const { colorlog } = require('@huiyan/color-log');
colorlog.test();
To cope with more usage scenarios, color-log provides some convenient tool functions. More tool functions may be provided in future versions.
Used to expand the original console.log.
const { logEx } = require('@huiyan/color-log');
console.log(['red', 'bgWhite', 'underline'], 'hello world');
console.log(['\x1b[31m', 'bgWhite', 'underline'], 'hello world');
console.log(['\x1b[31m', 'bgWhite', 'underline', 'hello world']);