npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-console

v4.0.1

Published

Shorthand methods to manage console output. Output with different colors and format styles.

Downloads

58

Readme

smart-console

Simple JavaScript library that provides shorthand methods to manage console output with 0 dependencies. Customize your console output with different colors and format styles.

You can find the same library for the browser here.

For more info e images see Git Hub

Every console object method (for more info: Node.js "Console") has a name shortcut. Furthermore, predefined colors and style can be added to the log() messages.

Version 4.0

New Features:

  • Code completely rewritten with ES6 syntax
  • Add new "verbose" method. It is as a normal log but the output, at the beginning, has filename and number line. Any existing log method can be used in verbose mode, just use "v" instead of "l" (eg: c.l(text) becomes c.v(text) and c.lRBG(text) becomes c.vRBG(text))
  • Add new console methods: clear, count and countReset. Only for node version 8.3.0 or newer
  • Add TypeScript definition file
  • Add default colors to error, warning and info methods
  • Add a new way to insert variables in log
  • Add trace method
  • "process" object no longer supported

How to use it:

Insert the library as usual:

npm install --save smart-console
// JavaScript file
const { c } = require('smart-console');

// TypeScript file
import { c } from 'smart-console';

Write 'c' instead of 'console' and use one of the method shortcuts. For example:

console.log('test');

// Becomes
c.l('test');

Shorthands for console methods

All the shorthand methods use lower case

c.a(...extraParams) = console.assert()
c.cl() = console.clear()                        // node >= v8.3.0
c.c([label]) = console.count()                  // node >= v8.3.0
c.cr([label]) = console.countReset()            // node >= v8.3.0
c.dir(object, [optObj]) = console.dir()
c.e(text, ...extraParams) = console.error()
c.i(text, ...extraParams) = console.info()
c.l(text, ...extraParams) = console.log()
c.t([label]) = console.time()
c.te([label]) = console.timeEnd()
c.tr(...extraParams) = console.trace()
c.w(text, ...extraParams) = console.warning()
c.j(object, [space]) = console.log()            // to log stringify objects
c.v(text, ...extraParams) = console.log()       // NEW - to log filename and number line

For log() messages you can use 4 different ways to insert a variable:

let str = 'Awesome';
c.l('Smart Console is ' + str);
c.l('Smart Console is %s', str);
c.l(`Smart Console is ${str}`);
c.l('Smart Console is', str);       // NEW

The method j() can be used to log JS and JSON objects using JSON.stringify

var jsonObj = {'pas': 'rex', 'pas1': 'rex', 'pas2': 'rex', 'pas3': 'rex'};
c.j(jsonObj);
// output
// {
//     'pas': 'rex',
//     'pas1': 'rex',
//     'pas2': 'rex',
//     'pas3': 'rex'
// }
var jsObj = {pas: 'rex', pas1: 'rex', pas2: 'rex', pas3: 'rex'};
c.j(jsObj);
// output
// {
//     'pas': 'rex',
//     'pas1': 'rex',
//     'pas2': 'rex',
//     'pas3': 'rex'
// }

A second parameter can be added to insert white spaces. By default they are set to 4

var jsonObj = {'pas': 'rex', 'pas1': 'rex', 'pas2': 'rex', 'pas3': 'rex'};
c.j(jsonObj, 2);
// output
// {
//   'pas': 'rex',
//   'pas1': 'rex',
//   'pas2': 'rex',
//   'pas3': 'rex'
// }

The new method v() "verbose" can be used to log message with filename and line number. Any log method can be used, just use "v" instead of "l"

c.l('Smart Console') becomes c.v('Smart Console')
c.lb('Smart Console') becomes c.vb('Smart Console')
c.lM('Smart Console') becomes c.vM('Smart Console')
c.lMBG('Smart Console') becomes c.vMBG('Smart Console')
// output
// [File: path/file_name] [Line: 150:10] Text message

Format styles for log() method, for verbose use "v" instead of "l"

Format styles use lower case

c.lb() = bold
c.lf() = faint
c.lu() = underline
c.ll() = blink
c.ln() = negative
c.lh() = hidden

Colors for log() method, for verbose use "v" instead of "l"

Colors use upper case

c.lK() = black
c.lR() = red
c.lG() = green
c.lY() = yellow
c.lB() = blue
c.lM() = magenta
c.lC() = cyan
c.lW() = white

Bold + Colors for log() method, for verbose use "v" instead of "l"

Format styles use lower case and Colors use upper case

c.lbK() = bold + black
c.lbR() = bold + red
c.lbG() = bold + green
c.lbY() = bold + yellow
c.lbB() = bold + blue
c.lbM() = bold + magenta
c.lbC() = bold + cyan
c.lbW() = bold + white

Underline + Bold + Colors for log() method, for verbose use "v" instead of "l"

Format styles use lower case and Colors use upper case, bold style is added by default

c.luK() = underline + bold + black
c.luR() = underline + bold + red
c.luG() = underline + bold + green
c.luY() = underline + bold + yellow
c.luB() = underline + bold + blue
c.luM() = underline + bold + magenta
c.luC() = underline + bold + cyan
c.luW() = underline + bold + white

Blink + Bold + Colors for log() method, for verbose use "v" instead of "l"

Format styles use lower case and Colors use upper case, bold style is added by default

c.llK() = blink + bold + black
c.llR() = blink + bold + red
c.llG() = blink + bold + green
c.llY() = blink + bold + yellow
c.llB() = blink + bold + blue
c.llM() = blink + bold + magenta
c.llC() = blink + bold + cyan
c.llW() = blink + bold + white

Background Color + Bold for log() method, for verbose use "v" instead of "l"

Background Colors use upper case, bold style is added by default

c.lKBG() = background + bold + black
c.lRBG() = background + bold + red
c.lGBG() = background + bold + green
c.lYBG() = background + bold + yellow
c.lBBG() = background + bold + blue
c.lMBG() = background + bold + magenta
c.lCBG() = background + bold + cyan
c.lWBG() = background + bold + white

Different console colors produce different effects and contrasts

If you forget the shortcuts' name:

c.l(c);  // console methods

Git Hub Repository

Report an Issue

License