0.3.5 • Published 8 months ago

unoout v0.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Unoout

A stylish UI kit to give that visual boost to your command line.

typescript-image npm-image license-image

"Unoout" is a logging library focused on simplicity. Without complicated or excessive configurations, it provides a straightforward and efficient experience for recording your logs. Simple, to the point, and effective.

Usage

Logger

The Logger instance is the heart of the library and is responsible for generating log messages. The library exports a default Logger instance, but you can also create your own instance.

Logger Methods

MethodDescription
logger.logStandard log
logger.infoInformation log
logger.debugDebugging log
logger.waitLog indicating a wait
logger.eventLog related to events
logger.readyLog indicating readiness
logger.warnWarning log
logger.offLog indicating shutdown or deactivation
logger.errorError log
logger.fatalFatal error log

All methods accept the following parameters:

  • message: The main log message.
  • prefix?: Optional prefix to be displayed before the message.
  • sufix?: Optional suffix to be displayed after the message.

Output format:

[level] - ([prefix]) [message] ([sufix)])
Creating an instance:

You can create your own Logger instance and customize its behavior:

import { Logger } from 'unoout'
const logger = new Logger({
  output: 'log', // or 'stdout'
  datetime: true,
})
  • output: Defines the output method. If set to log, it will use console.log. If set to stdout, it will use process.stdout.write.
  • datetime: If true, the log will include the date in ISO format.

Spinner

The Spinner is a logging utility designed for instances where you need to await a promise. It provides a visual loading in the console to indicate a waiting or processing state.

Importing and Creating an Instance:

import { Spinner } from 'unoout';

const spinner = new Spinner(options?);

Options:

You can configure the spinner with the following options:

OptionTypeDescriptionDefault
framesstring[]The sequence of frames for the spinner animation.['. ', '.. ', '...', ' ..', ' .', ' ']
intervalnumberThe interval (in milliseconds) between frames.250
defaultLoggerSpinnerLoggerOptionsDefault logger settings for spinner messages.{}

The SpinnerLoggerOptions allows you to configure the following:

OptionTypeDescriptionDefault
framesLogLevelThe log level.LogLevel.wait
intervalstringPrefix to be displayed before the message.None
defaultLoggerstringSuffix to be displayed after the message.None

Methods:

  • spinner.start(message: string, prefix?: string, sufix?: string): Begins the spinner with the given message, prefix, and suffix.
  • spinner.stop(): Halts the spinner.
  • spinner.update(message?: string, forceSpin?: boolean, options?: SpinnerLoggerOptions): Modifies the spinner's message or options. If forceSpin is true, it triggers the spinner even if it's not currently running.

Usage:

const spinner = new Spinner()

spinner.start('Loading...')
// ... some async operation
spinner.stop()

Stamp

The Stamp class is used to display steps or instructions in the terminal. These steps can be for starting development, bundling code for production, updating a CLI version, among others.

Importing and Creating an Instance:

import { Stamp } from 'unoout'

const stamp = new Stamp()

Methods:

  • stamp.setBoxType(type: BoxKeys): Sets the type of the box. Available types are keys from the boxes object.
  • stamp.setInstruction(isInstruction = true): Specifies whether the box is an instruction.
  • stamp.setHeading(heading: string): Sets the heading for the box.
  • stamp.addMessage(message: string): Adds a message to the box.
  • stamp.render(): Renders the box to the terminal.

Box Types

The Stamp class supports various box types for rendering. Here's an overview of the available box types:

Box TypeCharacters
single┌ ─ ┐ │ ┘ └
double╔ ═ ╗ ║ ╝ ╚
round╭ ─ ╮ │ ╯ ╰
bold┏ ━ ┓ ┃ ┛ ┗
classic+ - + \| + -

Usage:

const stamp = new Stamp()

stamp
  .setHeading('Development Instructions')
  .addMessage('Install the dependencies.')
  .addMessage('Run the local server.')
  .addMessage('Access the address http://localhost:3000')
  .setInstruction(true)
  .render()

Acknowledgment

Special thanks to the libraries that inspired the creation and enhancement of unoout:

Their pioneering work was instrumental in guiding and motivating us in building this library. 🙏

0.3.5

8 months ago

0.3.4

8 months ago

0.3.3

8 months ago

0.3.2

8 months ago

0.3.1

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago