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

bitwane

v1.8.1

Published

A universal logger

Downloads

32

Readme

bitwane

Logging with styles, and formatting for node, and most browsers.

Install

npm install bitwane

Usage

import { Logger } from 'bitwane';
const logger = new Logger();
//Format the output
logger.log('The %(value) is big.', {value: 'moon'});
logger.log('The $(red)moon$() is red');
logger.log('The $(green:red)moon$() is green, and red.');
logger.log('The $(green:magenta underline)moon$() is green, magenta, and underlined.')

You should see something like this:

Terminal output image!

//indent the output
const indent = 4;
logger.log('This should be indented', null, indent);

The syntax for string formatting is %(property).

The syntax for styles is $(foreground:background other text styles separated by spaces).

This syntax $() clears styles.

foreground is the foreground color, and background is a background color.

Colors (foreground, and background) supported by bitwane:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Other supported styles:

  • bright
  • dim
  • underline

The API of a bitwane Logger instance

  • logger.log()
  • logger.error()
  • logger.info()
  • logger.warn()

All of the above have the same usage logger.method(string, object). The object is optional.

logger.list(obj, options)

logger.list() prints an object, or array as a formatted list.

logger.list({
    one: 'one',
    two: 'two',
    three: 'three'
});

logger.list([
    'one',
    'two',
    'three'
]);
//With options
logger.list([
    'one',
    'two',
    'three'
], {
    //The logging type/A method on this object
    type:'log',
    //Indent the list
    indent: 0,
    //Repeat sep (default = 1)
    extra: 1,
    //sep separates the property/index from the value
    //(default = ' ')
    sep: ' ',
    //A dot after the index of a list array
    //(default = '.')
    dot: '.',
    //Alter each index, and value
    //right before logging.
    every(index, val){
        return index + val;
    }
});

logger.tree()

Print an object using logger.tree(object).

You can also indent the object using logger.tree(object, number).

The object you pass can be any javascript value.

Objects, and arrays passed to logger.tree() are formatted for easy reading.

There are also two experimental methods.

  • logger.ok()
  • logger.notok()

The constructor

const logger = new Logger({
    //How much should each indent be.
    //The default is 2
    indentLength: 2,
    //Add a symbol prefix while in a terminal
    prefix: true, //default false,
    each(value){ //default null
        //value is the formatted log input
        //without styles
    }
});

The every() method

The every constructor method can be used to intercept input values, and alter them. It is optional.

Use the output() method to finally print the input value. If the output() method isn't called nothing will be printed.

const logger = new Logger({
    every(type, input, format, indent){
        this.output(type, input, format, indent);
    }
});

About

bitwane only accepts styles that are available for both the terminal, and browser.

This way a module author can have formatting without worrying too much about their logs working every where. Low color resolution for terminals was chosen as the baseline for maximum compatibility.

Some styles like blink, reverse, or hidden have not been added as the code for such a feature would significantly slow down logging.

bitwane is also meant to be fast. For the majority of coding avoiding premature optimization is probably a good thing. It's viable to make sure helper libraries are fast though. Especially for testing.

Happy coding!