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

pretty-cli

v0.0.14

Published

Pretty-cli is a lightweight utility that helps you to create nice looking command line interfaces. It forces a well structured output and gives unimited flexibility with its templating system without adding any overhead.

Downloads

116

Readme

Pretty-cli

Pretty-cli is a lightweight utility that helps you to create nice looking command line interfaces. It forces a well structured output and gives unimited flexibility with its templating system without adding any overhead. Freely inspired by my experience with bunyan Check the code examples.

out

Installation

Just use NPM and you're ready to go

npm install pretty-cli --save

Code Example

Instead of using console.log to output your messages:

console.log("First error message");
console.log("Other unformatted error message");

with pretty-cli you can

  • Use different type of output
pretty = require('pretty-cli')();

pretty.log("Log Message");
pretty.error("Error Message");
pretty.warning("Warning Message");
pretty.info("Info Message");

Use templates that unify your design

pretty = require('pretty-cli')({
  template:
})
pretty.log("Log Message");
pretty.error("Error Message");
pretty.warning("Warning Message");
pretty.info("Info Message");

With custom templates you can unify your styles and use complex objects.

pretty = require('pretty-cli')({
  template: require('myTemplate')
})
pretty.error({message:'../files/test.js\n',name:'MODULE', type:'title'})
pretty.error({message:'Test', description:"Long description message or code sample"})

Create custom templates in a breeze, they are pure javascript! In this example I'm using colors, but you can use everything you prefer.
There are no limitations.

var colors = require('colors');

var MY_TEMPLATE = {
  'info': function(message){return ' I '.bgBlue.black +" " + message},
  'error': function(message){return ' E '.bgRed.white +" " + message},
  'log': function(message){return ' L '.bgWhite.black +" " + message},
  'warning': function(message){return ' W '.bgYellow.black +" " + message}
}

Advanced Use

Create custom print methods to automate special tasks

pretty = require('pretty-cli')({
  template: require('myTemplate')
})

pretty.addCustomMethod('stats', function(content){
  return pretty.error({
    type:'title',
    name:'STATS',
    message: "time: "+ content.time+', errors:'+ content.errors+', warnings:'+content.warnings})
})

pretty.error({type:'title', name:'BUILD', message:'complete with errors'})
pretty.stats({time:'30ms', errors:12, warnings:3})

pretty-cli

You can also define custom methods using the template itself.
This feature is very useful when you have to define a new message type (by default pretty-cli ships log, error, success, info).

const TEMPLATE = {
  //...
  note: (message)=>{return 'NOTE:'+message}
}

pretty = require('pretty-cli')({
  template: TEMPLATE
})

pretty.note('my note')

Context

Pretty-cli focuses on semplicity and reusability. You don't have to repeat yourself.

When you're looping through items sometimes happens that you want to mantain a similar context while changing just specific parts. For this purpose you can use .context() to achieve that functionality.

var cli = require('pretty-cli')();

cli.context({
  type:'looped item'
});
//Shows current context
console.log(cli.context());
// { type:'looped item' }
for(var i=0;i<10;i++){
  cli.log({message:'Item '+i})
}

Context is automatically merged for every following message.
To clean the context you can simply set it to an empty object.

cli.context({
});
//Shows current context
console.log(cli.context());
// {}

Utils

Motivation

This library has been created to help the js community in creating nice looking command line interfaces with the objective of improving current practices and standardize the output.

Tests

Tests can be run with mocha

mocha test

Contributors

Contributors are very very welcome.
The project needs:

  • People who can create nice looking templates
  • New ideas to help the workflow of developers
  • Pull requests

License

The MIT License (MIT) Copyright (c) 2016 Michael Cereda http://michaelcereda.com

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.