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

a-nicer-console

v1.0.2

Published

`console` extended with support for colors on `info|warning|error|success` and better support for objects

Downloads

7

Readme

a-nicer-console

Fancy extras for the Node console.

Features

This is a drop-in replacement for Node's native console; all the original console functions remain intact.

  • Adds colors to the output when using console.error|warn|info|success
  • Logs deeply nested objects
  • Adds the function console.success which is essentially console.log in a, by default, green tone
  • Adds the function console.file which writes the log to a file instead of stdout
  • Allows adding your own functions by adding a key-value pair to the color configuration. This will, just like console.success, be a colorized version of console.log

Installation

You can add a-nicer-console to your project with:

npm i a-nicer-console

Usage

import console from 'a-nicer-console' 
// alternatively: const console = require('a-nicer-console')

// Colored console output when using `console.error|warn|info|success`
console.error('This is an error message');
console.warn('This is a warning message');
console.info('This is an info message');
console.success('This is a success message, a functionality provided by this package');

// Outputting of deeply nested objects
const obj = { /* some deeply nested Object */ };

// Output the whole object; the native console would only print: 
// { a: { deeply: { nested: [Object] } } }. 
// In difference to `console.dir` you don't need to provide a configuration object.
console.log(obj); 

// Write to a log file, by default
console.file(obj, 'The large object and this message should be written to your log file');

Configuration

Maybe you like this package but the colors aren’t to your taste. Or you want to add console.foo() in some fancy color. Finally, if you are using a log file, you have to provide the path to this file somewhere. This is where the configuration file comes into the game.

Let’s see how this works. The default configuration looks like this:

{
    log: 'logs/console.log',
    colors: {
        error: '#FF5E5B',
        warn: '#FFBA5B',
        info: '#4DBDD9',
        success: '#ACDB4E',
        log: 'reset'
    }
}

To overwrite these values create a file called console-config.json at the root of your project, all values are optional. This package contains a file called console-config.example that you can use as a template.

Acceptable values

  • ANSI escape codes. Some of these values allow adding formats such as bold or italic etc.
  • RGB arrays (e.g. [51, 51, 102])
  • Colors in hex format (e.g. #333366 or #336)

Adding custom functions

Custom functions provide a new flavor of console.log with your own colors, nothing complex. Add a key-value pair to your configuration file like in this example:

{
    "colors": {
        "customFunction": [253, 134, 18]
    }
}

You can use this new flavor like so:

console.customFunction('This is a message which should be orange');

Example configuration

Your console-config.json should look about like this, again, all values are optional:

{
   "log": "logs/my-log.txt",
   "colors": {
      "error": [255, 0, 0],
      "warn": "#ff0",
      "info": "blueBright",
      "success": "#00ff00",
      "log": "reset",
      "customFunction": [253, 134, 18]
   }
}

Credits

Under the hood, a-nicer-console uses chalk and a bit of fs-extra. And then of course whatever they are using as well. Thanks to the authors for their work!