@npm--packages/chalkboard

Logger implementation for command line interfaces.

Usage no npm install needed!

<script type="module">
  import npmPackagesChalkboard from 'https://cdn.skypack.dev/@npm--packages/chalkboard';
</script>

README

Chalkboard

Logger implementation for command line interfaces.

Installation

Via npm

npm i @npm--packages/chalkboard

Via Yarn

yarn add @npm--packages/chalkboard

Usage

const chalkboard = require('@npm--packages/chalkboard');

const _log = chalkboard(options);

_log.log('Hello World');

Read Options for more information about options
Read API for more information about APIs

Options

Chalkboard support 3 options: additional, maps and prefix.

Here the is data structure of options:

type TOptions = {
    // Optional
    // You can add you own log types with your own style
    // By default There are 3 set of log sets, "alert", "bold", "highlighted", but you can overwrite them or add your own set if you want.
    additional: {
        [setName: string]: {
            [typeName: string]: {
                map: string,
                type: "debug" | "error" | "info" | "log" | "warn" 
            }
        }
    },
    // Optional
    // You can config the style of these log types
    // By default "debug" | "error" | "info" | "log" | "warn" already styled, but you can still overwrite them.
    map: {
        ["debug" | "error" | "info" | "log" | "warn"]: string
    },
    // Optional
    // Prefix will be added to all additional log set and all log type appear in options.map.  
    prefix: ''
}

Example:

For syntax of map, please refer to README of chalk - tagged-template-literal
For available colors, please refer to README of chalk - colors
For available background colors, please refer to README of chalk - Background colors

const chalkboard = require('@npm--packages/chalkboard');

const _log = chalkboard({
    additional: {
        day: {
            monday: { map: "red.bold", type: "error" }, // Red bolded text with no background color 
            tuesday: { map: "orange.bold", type: "info" }, // Orange bolded text with no background color
            wednesday: { map: "yellow.dim", type: "log" }, // Yellow dimmed text with no background color
            thursday: { map: "green.bold.underline", type: "warn" } // Green bolded text with underline and no background color
        }
    },
    map: {
        error: "red.bold", // Red bolded text with no background color
        info: "blue.underline", // Blue text with underline and no background color
        log: "white.bgGreen", // White text with green background
        warn: "yellow.bold" // Yellow bolded text with no background color
    },
    prefix: 'Week'
});

_log.day.monday('Today is Monday'); // Red bolded text with no background color
_log.day.tuesday('Today is Tuesday'); // Orange bolded text with no background color
_log.day.wednesday('Today is Wednesday'); // Yellow dimmed text with no background color
_log.day.thursday('Today is Thirday'); // Green bolded text with underline and no background color
_log.error('Hello world'); // Red bolded text with no background color
_log.info('Hello world'); // Blue text with underline and no background color
_log.log('Hello world'); // White text with green background
_log.warn('Hello world'); // Yellow bolded text with no background color

API

built-in

Non additional set

List of available type is from https://nodejs.org/api/console.html

_log.<type>(...arguments: any);

Additional set

_log.<additional.setName>.<additional.setName.typeName>(...arguments: any);

console

Chalkboard built based on Node.js console.

Chalkboard extended all function in console and styled some of them by default(listed in options.map).

chalk

// You can play with chalk by using the chalk object from chalkbaord
const chalk = _log.chalk;

Read chalk to play with chalk.

Additional

By default, there are 3 set of additional log set:

  • "alert"
  • "bold"
  • "highlighted"

Each of the set provide 5 log type:

  • "debug"
  • "error"
  • "info"
  • "log"
  • "warn"
const chalkboard = require('@npm--packages/chalkboard');

const _log = chalkboard();

_log.alert.debug('Additional - alert - debug');
_log.alert.error('Additional - alert - error');
// ...etc

_log.bold.info('Additional - bold - info');
_log.bold.log('Additional - bold - log');
// ...etc

_log.highlighted.warn('Additional - highlighted - warn');
_log.highlighted.debug('Additional - highlighted - debug');
// ...etc

Windows

If you're on Windows, do yourself a favor and use Windows Terminal instead of cmd.exe.