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

consolator

v0.1.1

Published

A JavaScript library for printing styled messages to the console.

Downloads

16

Readme

Consolator

A JavaScript library for printing styled messages to the console.

Caveat

This is a proof of concept -- that a library, with a single API, can create styled console output on both the server (Node.js) and in the browser.

Installation

npm install consolator

OR

bower install consolator

How It (Currently) Works

Consolator wraps messages in POJOs (Plain Old JavaScript Objects) and then stringifies them, adding a surrounding, customizable opening and closing token -- {{{ and }}} by default.

Those strigified objects are then passed to a posting method, like Consolator.prototype.log, which outputs them to the console using the appropriate styling syntax.

Usage

Server Example:

var c = require('consolator').create();

c.log(c.time(), c.green('This demonstrates ' + c.bold('nested')) + ' styles');
c.log(c.ansi(5, 'Blinking text'));

Browser Example (supports styled output with Chrome and Firebug):

<script src="consolator.min.js"></script>

var c = new Consolator();

c.log(c.time(), c.green('This demonstrates ' + c.bold('nested')) + ' styles');
c.image('http://placekitten.com/600/400', {
  width: 300, 
  fallback: c.css({ 
    'font-size': '24px',
    'font-weight': 'bold' 
  }, 'Kitten') 
});

API

This is a placeholder for a more complete explanation.

Consolator Object

  • Consolator.create(opts)

OR

  • new Consolator(opts)

Options

  • opts.open
  • opts.close

The opening and closing tokens for stringified Consolator objects. {{{ and }}} by default.

  • opts.fallbackSupport

Consolator will print unstyled messages for all browsers other than Chrome if this option is set to true. It is set to false by default. (Note: Consolator.prototype.image has a seperate mechanism for handling fallbacks.)

  • opts.punctuation
  • opts.boolean
  • opts.brace
  • opts.bracket
  • opts.colon
  • opts.comma
  • opts.hyphen
  • opts.key
  • opts.number
  • opts.quote
  • opts.string
  • opts.time
  • opts.type

Any of these options can be set with a properties object like the following:

{ punctuation: { color: 'gray', 'font-weight': 'bold' }}

Posting Methods

Extensions of Console Methods

These methods are required to post the output of non-posting Consolator methods.

  • Consolator.prototype.error(arguments)
  • Consolator.prototype.info(arguments)
  • Consolator.prototype.log(arguments)
  • Consolator.prototype.warn(arguments)

Other Posting Methods

  • Consolator.prototype.object(object, opts)
  • Consolator.prototype.image(url, opts)

Console images are only supported by Chrome at this time. opts.fallback is a gracefully-degrading option that has the effect of a posting method, and can contain any of the non-posting methods as a part of its value. For example, { fallback: c.bold('some text') } would be a valid opts argument.

Non-posting Methods

These must be wrapped within a posting method, like Consolator.prototype.log

Colors

  • Consolator.prototype.black(string|number|boolean|object)
  • Consolator.prototype.red(string|number|boolean|object)
  • Consolator.prototype.green(string|number|boolean|object)
  • Consolator.prototype.yellow(string|number|boolean|object)
  • Consolator.prototype.blue(string|number|boolean|object)
  • Consolator.prototype.magenta(string|number|boolean|object)
  • Consolator.prototype.cyan(string|number|boolean|object)
  • Consolator.prototype.gray(string|number|boolean|object)
  • Consolator.prototype.darkGray(string|number|boolean|object)
  • Consolator.prototype.lightRed(string|number|boolean|object)
  • Consolator.prototype.lightGreen(string|number|boolean|object)
  • Consolator.prototype.lightYellow(string|number|boolean|object)
  • Consolator.prototype.lightBlue (string|number|boolean|object)
  • Consolator.prototype.lightMagenta(string|number|boolean|object)
  • Consolator.prototype.lightCyan(string|number|boolean|object)
  • Consolator.prototype.white(string|number|boolean|object)

Background Colors

  • Consolator.prototype.blackBg(string|number|boolean|object)
  • Consolator.prototype.redBg(string|number|boolean|object)
  • Consolator.prototype.greenBg(string|number|boolean|object)
  • Consolator.prototype.yellowBg(string|number|boolean|object)
  • Consolator.prototype.blueBg(string|number|boolean|object)
  • Consolator.prototype.magentaBg(string|number|boolean|object)
  • Consolator.prototype.cyanBg(string|number|boolean|object)
  • Consolator.prototype.grayBg(string|number|boolean|object)
  • Consolator.prototype.darkGrayBg(string|number|boolean|object)
  • Consolator.prototype.lightRedBg(string|number|boolean|object)
  • Consolator.prototype.lightGreenBg(string|number|boolean|object)
  • Consolator.prototype.lightYellowBg(string|number|boolean|object)
  • Consolator.prototype.lightBlue Bg(string|number|boolean|object)
  • Consolator.prototype.lightMagentaBg(string|number|boolean|object)
  • Consolator.prototype.lightCyanBg(string|number|boolean|object)
  • Consolator.prototype.whiteBg(string|number|boolean|object)

Styles

  • Consolator.prototype.bold(string|number|boolean|object)
  • Consolator.prototype.faint(string|number|boolean|object)
  • Consolator.prototype.italic(string|number|boolean|object)
  • Consolator.prototype.underline(string|number|boolean|object)
  • Consolator.prototype.blink(string|number|boolean|object)
  • Consolator.prototype.blinkFast(string|number|boolean|object)
  • Consolator.prototype.negative(string|number|boolean|object)
  • Consolator.prototype.hidden(string|number|boolean|object)
  • Consolator.prototype.lineThrough(string|number|boolean|object)

Timestamp

  • Consolator.prototype.time(opts)

ANSI Escape Codes (server)

  • Consolator.prototype.ansi(code, string|number|boolean|object)

http://en.wikipedia.org/wiki/ANSI_escape_code

CSS (Chrome & Firebug)

  • Consolator.prototype.css(properties, string|number|boolean|object)

The properties argument should take the form of an object. For example, the following would be valid:

{ padding: '0 10px', 'font-size': '14px', 'font-weight': 'bold' }

Tests

Coming soon.

License

The MIT License (MIT)

Copyright (c) 2014 Michael J. Bondra < [email protected] >

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.