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

logdock

v0.2.2

Published

More advanced tool for creating animated CLI log

Downloads

15

Readme

logdock

BETA!

More advanced tool for creating updatable CLI log, including loaders, spinners, progress bars, groups, reports, etc.

Read Usage to best understood.

Api reference

.transform(handler : function | array<func>) : func

Specify message transformer. The handler accepts a message and returns transformed message. To keep together multiple transform logic should pass an array of transformers, which will be executed as a flow.

const log = require('logdock')
const chalk = require('chalk')

const beautyLog = log.transform([
  message => `[${message}]`,
  chalk.bgBlack.white,
]);

log.group (name : string) : func

Create new log function, which already have static left part. Group has title, that usually is simple string. If group title must be styled, you may specify transform before.

const log = require('logdock')
const chalk = require('chalk')

const appLog = log
  .transform([
    message => ` ${message} `,
    chalk.bgBlack.white,
  ])
  .group('MyApp');

You also pass transform as second argument.

const appLog = log
  .group('MyApp', [
    message => ` ${message} `,
    chalk.bgBlack.white,
  ]);

log.config(name)

Configurate and create new log function. See Config options for ditails.

const log = require('logdock')

const summLog = log
  .config({
    separator: ' + '
  })
  .group('1')
  .config({
    separator: ' = '
  })
  .group('2')

summLog('3'); // 1 + 2 = 3

log.stdout(stream)

Create new log with custom stdout.

const log = require('logdock');

const wstream = fs.createWriteStream('output.txt');

const logToFile = log.stdout(wstream);

log.output(handler)

Specify custom output handler, which overrides internal output, and returns new log instance.

const log = require('logdock');

const myLog = log.output(msg => console.log(msg));

Using custom output handler makes log.stdout useless.

.persist()

.pipe

Link to the in-log pipe. Use it to translate any child-process stdout to the log.

const child = spawn('node',  ['some-child-process.js')], {
  stdio: [process.stdin, 'pipe', 'inherit']
});

child.stdout.pipe(childLog.stream);

.done(lastMessage)

Works only with default output!

Release selected unit. After this, the unit message will be added to CLI log and removed from docks. There are no more iteractions with such unit will happends. And trying to pass another message will gives no effect.

const log = require('../lib');
const chalk = require('chalk');

const progressLog = log.transform(chalk.bold);
const title = progressLog.transform(chalk.bold.green);
const logX = progressLog.group('X').transform(chalk.blue);
const logY = progressLog.group('Y').transform(chalk.blue);
const logZ = progressLog.group('Z').transform(chalk.blue);

title('Calc XYZ');

let x = 0;
let y = 0;
let z = 0;
const interval = setInterval(() => {
  logX(`${x}%`);
  logY(`${y}%`);
  logZ(`${z}%`);

  if (x >= 100) {
    logX.done('OK');
  }
  if (y >= 100) {
    logY.done('OK');
  }
  if (z >= 100) {
    logZ.done('OK');
  }

  x += 1;
  y += 2;
  z += 4;

  if (x > 100 && y > 100 && z > 100) {
    clearInterval(interval);
  }
}, 10);

Config

hideEmpty (default: true)

If log accepts empty string, then its groups will be hidden.

const pure = log
  .group('Pure:')
  .config({
    hideEmpty: false
  })

const unpure = log
  .group('Unpure:')
  .config({
    hideEmpty: true
  })

pure(''); // [Will displays nothing]
unpure(''); // Unpure:

separator (default: ' ')

Specify separator between messages

const log = require('../lib');

const summLog = log
  .config({
    separator: ' + '
  })
  .group('1')
  .config({
    separator: ' = '
  })
  .group('2');

summLog('3'); // 1 + 2 = 3

streamStripEmptyTail (default: true)

Remove the trailing line breaks of outside stdout and stream chunks.