Skip to content

Repository files navigation

@northern/console

A lightweight TypeScript console wrapper with support for color tags and quiet mode.

Features

  • Color Tags: Use XML-style tags to colorize console output
  • Quiet Mode: Suppress all output when needed
  • Color Toggle: Disable colors for CI environments or plain text output
  • Customizable Colors: Define your own color map using Chalk
  • TypeScript Support: Full type definitions included

Installation

npm install @northern/console

Usage

Basic Usage

importConsolefrom'@northern/console';constconsole=newConsole();// Use color tags to format outputconsole.write('Run <command>npm install</command> to get started');console.write('This is <highlight>important</highlight>!');console.write('Status: <success>Complete</success>');

Quiet Mode

// Create a quiet console that suppresses all outputconstquietConsole=newConsole(true);quietConsole.write('This will not appear');// No output

Disable Colors

// Create a console without colors (useful for CI environments)constplainConsole=newConsole(false,false);plainConsole.write('Run <command>npm test</command>');// Output: "Run npm test"

Custom Color Map

importchalkfrom'chalk';constcustomColors={command: chalk.green,highlight: chalk.yellow,error: chalk.bgRed.whiteBright,warning: chalk.bgYellow.black,info: chalk.bgBlue.whiteBright,success: chalk.bgGreen.whiteBright,custom: chalk.magenta.bold,};constconsole=newConsole(false,true,customColors);console.write('This is <custom>custom colored</custom> text');

Dumping Objects

constconsole=newConsole();constdata={user: {name: 'John',age: 30},settings: {theme: 'dark'}};// Dump with full depth and colorsconsole.dump(data);

API

Constructor

newConsole(isQuiet?: boolean,isColor?: boolean,colorMap?: Record<string,ChalkInstance>)

Parameters:

  • isQuiet (optional): When true, suppresses all output. Defaults to false.
  • isColor (optional): When true, enables color output. Defaults to true.
  • colorMap (optional): Custom color mapping using Chalk instances.

Methods

write(...args: unknown[]): void

Writes output to the console with color tag processing. Suppressed in quiet mode.

Example:

console.write('Status: <success>OK</success>');console.write('Multiple','arguments','supported');

dump(o: unknown): void

Dumps an object to the console with full depth and colors. Useful for debugging. Suppressed in quiet mode.

Example:

console.dump({complex: {nested: {object: true}}});

Default Color Tags

The following color tags are available by default:

  • <command>text</command> - Green text
  • <highlight>text</highlight> - Yellow text
  • <error>text</error> - White text on red background
  • <warning>text</warning> - Black text on yellow background
  • <info>text</info> - White text on blue background
  • <success>text</success> - White text on green background

License

MIT

About

A lightweight TypeScript console wrapper with support for color tags and quiet mode.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages