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

gloucester

v1.0.3

Published

A verbosity detection and comparison library with integration with Commander JS.

Downloads

41

Readme

Gloucester

A verbosity detection and comparison library with integration with Commander JS.

Named after Richard, Duke of Gloucester - the Shakespearian character with the longest monolog.

Installation

npm install gloucester

Verbosity

Typically, a CLI application will be in a single state of verbosity at any given time.

There are five verbosity levels:

  • quiet
  • normal
  • verbose
  • superVerbose
  • ridiculouslyVerbose

The default, or "normal" verbosity level is normal. A user of a CLI application can typcally request more or less output through the use of either environment variables or flags (such as the -v flag). It is then up to the CLI application to determine what to output.

Basic Usage

Starting very simply, you can retrieve and set verbosity through a globally available singleton instance of the GloucesterEvaluator class:

import gloucester from 'gloucester';

console.info(gloucester.verbosity); // normal
gloucester.verbosity = 'verbose';
console.info(gloucester.verbosity); // verbose

Then, one might want to output some details based on a comparison of verbosity levels:

if (gloucester.is.quiet) {
	return;
}

if (gloucester.is.normal) {
	console.info('Here is a normal level of detail');
}

if (gloucester.is.gte('verbose')) {
	stderr.write('Here are some details');
}

if (gloucester.is.gte('superVerbose')) {
	stderr.write('Here are some finickity tiny little details');
}
// Checks against exact verbosity levels

gloucester.is.quiet;
gloucester.is.normal;
gloucester.is.verbose;
gloucester.is.superVerbose;
gloucester.is.ridiculouslyVerbose;

gloucester.is.gt('normal'); // greater than
gloucester.is.gte('normal'); // greater than or equal to
gloucester.is.lt('normal'); // less than
gloucester.is.lte('normal'); // less than or equal to

Getting from Environment Variables

There is a helper function to get the current verbosity from an environment variable:

// This will look for an environment variable called VERBOSITY
gloucester.setVerbosityFromEnvironmentVariable();

// This will look for an environment variable called APP_NAME_VERBOSITY
gloucester.setVerbosityFromEnvironmentVariable({ prefix: 'app_name' });

// This will look for an environment variable with a completely custom name called MONKEY
gloucester.setVerbosityFromEnvironmentVariable({ variable: 'monkey' });

Setting verbosity in CommanderJS

If you are using CommanderJS, there is a helper function to set up commander.

This will set up the following flags as global flags in your CLI application which will set the verbosity in your gloucester instance:

  • --quiet
  • -v | --verbose
  • -vv | --super-verbose
  • -vvv | --ridiculously-verbose

It will fall back to using the APP_NAME_VERBOSITY environment variable if no flags are used (where APP_NAME is your CommanderJS .name() - in the example below the variable would be MY_CLI_APP_VERBOSITY).

import { Command } from 'commander';
import gloucester from 'gloucester';
import setupCommanderAndGloucester from 'gloucester/lib/integrations/commander';

const program = new Command();

program.name('my-cli-app');

setupCommanderAndGloucester(program, gloucester);