0.0.7 • Published 2 years ago

@matheussartori/better-console v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

About the project

This JavaScript library was made to improve terminal outputs, but remember that console.log is an asynchronous function, and they can slow your performance.

I felt the need to do something like this because lately I've been doing a lot of scripts to throw data from one system to another, and this library has helped me a lot.

Installation

npm install @matheussartori/better-console
# or
yarn add @matheussartori/better-console
# or
pnpm install @matheussartori/better-console

Usage

import { BConsole } from '@matheussartori/better-console'

BConsole.print('Hello World!', {
  date: {
    show: true,
    textColor: 'blackBright'
  },
  textColor: 'cyan',
  emojiLeft: 'fire'
})
import { BConsole } from '@matheussartori/better-console'

BConsole.printLong([
  {
    data: 'Now we have ',
    options: {
      textColor: 'blueBright'
    }
  }, {
    data: '2 different styles.',
    options: {
      backgroundColor: 'bgBlue'
    }
  }
], {
  date: {
    show: true,
    textColor: 'blackBright'
  }
})

API

Print method

import { BConsole } from '@matheussartori/better-console'

BConsole.print(data, options)

// Examples
BConsole.print('Server is running at port 3333')

BConsole.print(JSON.stringify(response.data), {
  textColor: 'cyanBright',
  emojiRight: 'bomb'
})

BConsole.print('Time now', {
  date: {
    show: true
  }
})

The print method is used when you want to print a single value through the console. The first (data) argument could be any type that will work on the default console.

The second argument (options) is optional, and here you can find all the definitions:

Print long method

import { BConsole } from '@matheussartori/better-console'

BConsole.printLong(data, options)

// Examples
BConsole.printLong([
  {
    data: 'Hello, ',
    options: {
      textColor: 'cyan'
    }
  },
  {
    data: 'World!',
    options: {
      backgroundColor: 'bgMagenta'
    }
  }
], {
  date: {
    show: true,
    format: 'HH:mm:ss'
  }
})

The print long method is used when you want to print two or more values in the same line, with different styles, through the console. The first (data) argument must be an array of PrintLongItem, which consists of the data (any value) and some options.

Here you can find all the PrintLongItem definitions.

The second argument (options) is optional, and here you can find all the definitions:

The textColor and backgroundColor are not in the print long options, because they belong to each item of the data.

Wrappers

Wrappers are functions that have the options already defined and can't be changed. They can be used when you don't want to customize the BConsole, or create a HOC.

Right now, only the ServerWrappers are available, and they don't receive any other argument besides the data.

import { ServerWrappers } from '@matheussartori/better-console'

ServerWrappers.info('Information')
ServerWrappers.success('Success')
ServerWrappers.error('Error')

Types

Text Color types

The color types can be used to change the text color, on print and printLong methods.

For more details, see chalk documentation.

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • blackBright
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright

Background Color types

The background color types can be used to change the text background color, on print and code>printLong methods.

For more details, see chalk documentation.

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlackBright
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright

Emoji types

The emoji types are used to add an emoji to the beggining or the end of a line.

Not all emojis are available and you can simple copy and paste them into the data, but you can also use the options for this.

  • tangerine (🍊)
  • redHeart (❤️)
  • fire (🔥)
  • faceWithPeekingEye (🫣)
  • faceHoldingBackTears (🥹)
  • heartHands (🫶)
  • dottedLineFade (🫥)
  • smilingFaceWithSmilingEyes (😊)
  • bomb (💣)
  • battery (🔋)
  • lightbulb (💡)
  • flag:brazil (🇧🇷)
0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago