@jsheaven/status-message
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

@jsheaven/status-message

Prints colorful status messages to the console

User Stories

  1. As a developer, I don't want to format log messages again and again using tags, ASCII color and console API

Features

  • Does offer colorful logging function
  • Severities are: error(...), warn(...), log(...), info(...), debug(...), trace(...)
  • Duration time measurements: time(label: string), timeEnd(label: string)
  • Uses the correct console API functions automatically (per severity)
  • Beautiful loading spinner animation
  • Ability to rewind and clear the previous line (custom animations)
  • Available as a simple API
  • Just 535 byte nano sized (ESM, gizpped)
  • Tree-shakable and side-effect free
  • First class TypeScript support
  • 100% Unit Test coverage

Example usage (API)

Setup

  • yarn: yarn add @jsheaven/status-message
  • npm: npm install @jsheaven/status-message

ESM

import { log, error, warn, info, debug, trace, time, timeEnd, spinner } from '@jsheaven/status-message'

time('Log every feature')

error('FATAL', 'You did not use this library yet')
warn('DANGER', 'Other logging libraries do not support arbitrary args', { right: true }, process.version)
log('SUCCESS', 'But this lib is only 361 bytes and has it all')
info('NOTE', 'It even has 100% test coverage')
debug('DEBUG', 'It is even tree-shakable')
trace('DURATION', 'You can trace the runtime of a task easily too:')

timeEnd('Log every feature')

Advanced use-cases

Loading spinner

const stopAnimation = spinner('Loading...')
await(async () => new Promise((resolve) => setTimeout(resolve, 2000)))()
stopAnimation()

Updating a value by clearing the previous line

let i = 1
const countTo100 = setInterval(() => {
  if (i > 1) clearPrevLine()
  info('COUNT', i)
  i++
  if (i > 100) clearInterval(countTo100)
}, 25)

Clearing 20 lines of the screen

for (let i = 0; i < 20; i++) clearPrevLine()

CommonJS

const { log, logTime, logTimeEnd } = require('@jsheaven/status-message')

// same API like ESM variant

Package Sidebar

Install

npm i @jsheaven/status-message

Weekly Downloads

33

Version

1.1.2

License

MIT

Unpacked Size

27.1 kB

Total Files

12

Last publish

Collaborators

  • mansi1
  • kyr0