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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sb-log

v1.0.7

Published

A library for formatted console logs

Readme

sb-log

Library for easy console logs.

Installation

npm install --save sb-log

Usage

A sample usage of SbLogBlock:

const { SbLogBlock } = require('sb-log');
const log = new SbLogBlock();
log.log("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor inv");

// Output:
// Lorem ipsum dolor sit amet, co
// nsetetur sadipscing elitr, sed
//  diam nonumy eirmod tempor inv

With the default options of SbLogBlock, a string can be logged to the console which has a width of 30 characters. If the string exceeds this width, the string gets wrapped onto a new line. The only downside to this is that as you can see, the string gets cut mid word. This will maybe fixed in future versions.

The default options also include a default format:

// Default SbLog options:
{
	width: 30,
	format: 'default',
	applyFormatToWholeBlock: false,
	prelog: prelog.none // lines => lines
}

The prelog option gets applied to the output, before logging it to the console. The function takes an argument of SbLines, which get built by SbLog, when calling log. There is also a method to directly create the SbLines:

const lines = log.build("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor inv");

In the log method of SbLog, the following happens:

this.options.prelog(this.build(string)).forEach(line => console.log(line))

You can plug into a log, by calling the build method and do whatever you desire with the output.

Formats

There are some predefined formats, which can be used by passing a string like 'default', into the format field of the log's options. The formats are defined using chalk:

| Format | Implementation | | --------- | -------------------------- | | default | string => string | | bold | chalk.bold | | primary | chalk.cyanBright.bold | | secondary | chalk.magentaBright.bold | | success | chalk.greenBright.bold | | warn | chalk.yellowBright.bold | | fail | chalk.redBright.bold |

You can plug in any function which takes a string and returns a string, but you need to be careful with zero-width-characters! At the moment only the characters for ANSI-Color-Codes are accounted for.

Prelog

The prelog provides two predefined functions: The first is the identity function lines => lines and the second is the border function. The border function takes a configuration as parameter:

border(config = 'solid')

The config can take any value provided by the lineConfig module:

| Configuration | Description | | --------------- | ------------------------------------------------------------ | | solid | A solid border with sharp corners. | | solidBold | A solid bold border with sharp corners. | | solidRounded | A solid border with round outside corners and sharp inside corners. | | dashed | A dashed border with sharp corners. | | dashedBold | A dashed bold border with sharp corners. | | dashedRounded | A dashed border with round outside corners and sharp inside corners. | | empty | No border, but one space. Don't use this for no border, use prelog.none. |

The border can be applied as follows:

const { SbLog, prelog } = require('sb-log');
const logBorder = new SbLog({
	prelog: prelog.border()
});
logBorder.log("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor inv");

// Output:
// ┌────────────────────────────────┐
// │ Lorem ipsum dolor sit amet, co │
// │ nsetetur sadipscing elitr, sed │
// │  diam nonumy eirmod tempor inv │
// └────────────────────────────────┘

Again you can substitute any function which takes a SbLines object and returns a string array.

SbLines - The fundamental building block

This class takes the same options as SbLog, without the prelog field. The class extends an array and overrides the push method, but provides a substitute pushUnformatted(...lines). What the default push method does is best described by an example:

const { SbLines } = require('sb-log');

const linesWholeBlock = new SbLines()
linesWholeBlock.setOptions({
  format: chalk.underline,
  applyFormatToWholeBlock: true
})

linesWholeBlock.push("This is some sample line.")
linesWholeBlock.forEach(line => console.log([line]))

const linesPartialBlock = new SbLines()
linesPartialBlock.setOptions({
  format: chalk.underline,
  applyFormatToWholeBlock: false
})

linesPartialBlock.push("This is some sample line.")
linesPartialBlock.forEach(line => console.log([line]))

// linesWholeBlock Output:
// [ '\x1B[4mThis is some sample line.     \x1B[24m' ]

// linesPartialBlock Output:
// [ '\x1B[4mThis is some sample line.\x1B[24m     ' ]

The above SbLines receive two different strings as the first line. This is caused by the applyFormatToWholeBlock option. If this flag is set to true, the format (in this case underline), will be set to the whole line. If not, only the last line with non whitespace characters will not have the whole line formatted:

// Same example but push two lines and an empty line:
...
linesWholeBlock.push("This is some sample line.")
linesWholeBlock.push("This is some sample line.")
linesWholeBlock.addMarginBottom(1);
...
linesPartialBlock.push("This is some sample line.")
linesPartialBlock.push("This is some sample line.")
linesPartialBlock.addMarginBottom(1);
...

// linesWholeBlock Output:
// [ '\x1B[4mThis is some sample line.     \x1B[24m' ]
// [ '\x1B[4mThis is some sample line.     \x1B[24m' ]
// [ '\x1B[4m                              \x1B[24m' ]

// linesPartialBlock Output:
// [ '\x1B[4mThis is some sample line.     \x1B[24m' ]
// [ '\x1B[4mThis is some sample line.\x1B[24m     ' ]
// [ '                              ' ]

As you can see in the linesPartialBlock, the format only gets applied to the last line with non-whitespace characters. You can also make use of the addEpmtyLines method to push empty lines. There are also other useful static methods:

const { SbLines } = require('sb-log');
const options = {
  format: chalk.underline,
  applyFormatToWholeBlock: false
}


SbLines.fromArrayFormatted(["This is some sample line."], options)
// [ '\x1B[4mThis is some sample line.\x1B[24m     ' ]

SbLines.fromArrayUnformatted(["This is some sample line."], options)
// [ 'This is some sample line.' ]

SbLines.fromString("Lorem ipsum dolor sit amet, consetetur sadipscing", options)
// [ '\x1B[4mLorem ipsum dolor sit amet, co\x1B[24m' ]
// [ '\x1B[4mnsetetur sadipscing\x1B[24m           ' ]

...

There are also methods to calculate the total width, max-width, total-height and max-height of multiple SbLines. The public members consist of adding margin to the left, right, top and bottom. For further functions see the GitHub Page.

Other logs

There are other logs:

| Log Name | Purpose | | ----------------- | ------------------------------------------------------------ | | SbLogHorizontal | Combines logs into one log and joins the lines horizontally. | | SbLogVertical | Combines logs into one log and joins the lines vertically. | | SbLogTable | Combines logs into one log. The loggers can be arranged into a table. The configuration of the table layout happens in the tables options. | | SbLogField | Logs different fields with different formats. You can use predefined configurations in fieldConfig or you can define your own. |

A log extends the core log SbLogCore. This class defines the log method any only accepts a prelog as an options. It also defines an empty build method, which just returns an empty array.

Further Documentation

For more accurate and detailed insight go visit the GitHub Page and look into the source code or the documentation.

Creator

Severin Buchser