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

margaret-lanterman

v1.0.6

Published

A file logging library.

Downloads

27

Readme

Margaret Lanterman

A file logging library.

Name: Margaret Lanterman - the Log Lady of Twin Peaks

Installation

npm i margaret-lanterman

Basic Usage

import lanterman from 'margaret-lanterman';

lanterman.buffer.addStream(); // @todo - finish off docs

// This will write a section
lanterman.section('Start doing thing X', async () => {
	lanterman.write('Did a thing...', 'note'); // prefixes [note] to the line
	lanterman.write('Did another thing...', 'note');

	// a sub-section
	lanterman.section('A sub-section!', async () => {

		// JSON encodes an object, prefixes [response] to the line
		lanterman.write({ url: 'request.com' }, 'response');
		lanterman.write({ response: 'response from request' }, 'response');
	});
});

Feedback

You can set up a feedback handler to respond to messages - for example to provide some visual feedback.

lanterman.feedback.withFeedback(
	(message, verbosity) => verbosity === 'verbose' ? stderr.write(`[info] ${message}`),
	() => {
		lanterman.feedback('Sending API Request', 'verbose');
		// ... send a request
		lanterman.feedback('Response was succesful', 'superVerbose');
	},
);

Uses the gloucester verbosity library for verbosity levels.

Integration with Commander JS

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

This will set up two log streams - in the directory ~/.logs/{program-name}. One "latest" file, which will always have the latest log stream in it, and one "per-diem" file which will have a file for every execution, and will prune any files from previous calendar days.

import { Command } from 'commander';
import lanterman from 'lanterman';
import setupCommanderAndLanterman from 'margaret-lanterman/lib/integrations/commander';

const program = new Command();

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

setupCommanderAndLanterman(program, gloucester);

Integration with Listr2

If you are using Listr2, there are two helper functions to wrap tasks.

Wrap Tasks In Sections

This will take a list of tasks, and will wrap each of the tasks inside a lanterman.section() call, using the task's title as the section title.

import {Listr, delay} from 'listr2';
import {wrapListrTasksInSections} from 'margaret-lanterman/lib/integrations/listr';

new Listr(wrapListrTasksInSections([
	{
		title: 'Task One',
		async task() {
			lanterman.write('Some details about task one');
		}
	},
	{
		title: 'Task Two',
		async task() {
			lanterman.write('Some details about task two');
		}
	},
]));

Wrap Tasks In Feedback

This will take a list of tasks, and will wrap each of the tasks inside a lanterman.feedback.withFeedback() call, adding a few features:

  • Sets future tasks to gray
  • Sets current tasks to cyan
  • Sets completed tasks to green
  • Appends any calls to feedback lanterman.feedback.send() to the title (overwriting any previous ones) - or if using a verbosity level higher than normal, puts it on a line below (using task.output)
import {Listr, delay} from 'listr2';
import {wrapListrTasksInFeedback} from 'margaret-lanterman/lib/integrations/listr';

new Listr(wrapListrTasksInFeedback([
	{
		title: 'Task One',
		async task() {
			await delay(1000);
			lanterman.feedback.send('Doing a thing', 'verbose');
			await delay(1000);
			lanterman.feedback.send('Trying somethign else', 'verbose');
			await delay(1000);
		}
	},
]));

All

If you want to use both of these, there is a wrapListrTasks function which will apply both of these.

import {Listr, delay} from 'listr2';
import {wrapListrTasks} from 'margaret-lanterman/lib/integrations/listr';

new Listr(wrapListrTasks([]));