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

aggregated-cli-reporter

v1.0.0

Published

A way of reporting results of multiple processes without overflowing the terminal

Downloads

13

Readme

aggregated-cli-reporter

A way of reporting results of multiple processes without overflowing the terminal.

It will rewrite the previous lines, so there never are more visible than the latest message.

Note: If something else is writing to stdout, it will interfere with this module, since this module can only delete the x last lines, which no longer matches the actual lines written to stdout.

Usage

The interface:

class AggregatedCLIReporter {
	constructor({ showTime = true, showName = false })
	set(name, messages, { showTime = true, showName = false })
}

Creating a new reporter

import AggregatedCLIReporter from 'aggregated-cli-reporter'
// Or
const AggregatedCLIReporter = require('aggregated-cli-reporter')

const reporter = new AggregatedCLIReporter()

The constructor can take some configuration options:

  • showTime: Shows a timestamp that the message was received. Defaults to true.
  • showName: Shows the name passed to #set(). Defaults to false.
const reporter = new AggregatedCLIReporter({
	showTime: false,
	showName: true,
})

Writing logs

The reporter.set() method sets the latest output for a specific name.

reporter.set('tool1', 'Some message')

/* output:
12:45:12: Some message
*/

There can only ever be one message per name, but there is no limit to the number of names.

reporter.set('tool2', 'Some other message')

/* output:
12:45:12: Some message
12:47:22: Some other message
*/

// skip 12 seconds

reporter.set('tool2', 'Something new happened')

/* output:
12:45:12: Some message
12:47:34: Something new happened
*/

The names are printed in the order that they were last modified, so the latest message is always in the bottom.

reporter.set('tool1', 'Something happened to the first tool')

/* output:
12:47:34: Something new happened
12:49:01: Something happened to the first tool
*/

Any characters can be added, including colors and newlines.

reporter.set('tool1', 'Tool 1 is split\non lines')
/* output:
12:47:34: Something new happened
13:01:43: Tool 1 is split
on lines
*/

The message can also be an array, in which case the tool will print each value on a separate line, all prefixed.

reporter.set('tool1', [ 'Something happened', 'that should', 'be split\non lines' ])

/* output:
12:47:34: Something new happened
13:02:23: Something happened
13:02:23: that should
13:02:23: be split
on lines
*/

Overriding options per message

The #set() call takes the same arguments as the constructor. The options will override the default for that specific message only.

const reporter = new AggregatedCLIReporter({ showTime: true, showName: true })

reporter.set('tool1', 'abc')
/* output:
12:34:56: tool1: abc
*/

reporter.set('tool1', 'abc', { showName: false })
/* output:
12:34:56: abc
*/

reporter.set('tool2', 'def', { showTime: false })
/* output:
12:34:56: abc
tool2: def
*/

reporter.set('tool3', [ 'ghi', 'jkl' ])
/* output:
12:34:56: abc
tool2: def
12:34:56: tool3: ghi
12:34:56: tool3: jkl
*/