Skip to content

Utilities

Logging utilities for CLI output formatting. The module exports a singleton instance as Utilities.

Diagram

100%Ctrl + wheel to zoom

Usage

ts
import { UtilitiesClass } from "@briklab/lib/cli-john";

let Utilities = new UtilitiesClass();
Utilities.info("Starting...");
Utilities.warning("Missing config, using defaults.");
Utilities.error("Failed to run command.");

Class: UtilitiesClass

Properties

PropertyTypeDescription
styleSheetStyleSheetStyle registry used for tags.
tagsRecord<string, TagConfig>Tag configuration map.

TagConfig shape:

ts
{
  tag: string;
  showErrorInTag: boolean;
  paddingLeft: number;
  paddingRight: number;
  styleName: string;
}

Constructor

Creates default tags: error, warning, and info, and assigns default colors:

  • error: red + bold
  • warning: orange + bold
  • info: blue

Methods

.addTag(name: string, config?: Partial<TagConfig>)

ArgumentTypeDescription
namestringThe tag name.
configPartial<TagConfig>Tag configuration overrides.

Adds a new tag or overwrites an existing tag config. Returns this for chaining.

.setTagStyle(tagName: string, style: InlineStyle)

ArgumentTypeDescription
tagNamestringThe tag name to style.
styleInlineStyleInline style instance.

Assigns a style to a tag and registers it in styleSheet. Returns this.

.log(tagName: string, ...messages: any[])

ArgumentTypeDescription
tagNamestringThe tag to use for formatting.
messagesany[]Messages forwarded to console.log.

Logs a message using the tag's formatting. If the tag does not exist, it logs with a plain console.log.

.error(...messages: any[])

Shortcut for log("error", ...).

.warning(...messages: any[])

Shortcut for log("warning", ...).

.info(...messages: any[])

Shortcut for log("info", ...).