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

@momsfriendlydevco/debug

v1.4.4

Published

Isomorphic, chainable log / debugging utility

Downloads

5

Readme

@MomsFriendlyDevCo/Debug

Isomorphic chainable log / debugging utility.

This module works in Node as well as the browser.

CJS

var log = require('@momsfriendlydevco/debug')('MyApp');

log('Hello World') // Will log `[MyApp] Hello World`

ESM

import Debug from '../lib/debugNode.js';
let log = Debug('MyApp');


log('Hello World') // Will log `[MyApp] Hello World`

API

The Debug function is a chainable object so any number of methods can be used in sequence.

log.as('New Context').force('Hello World') // Will log even if the current logger is disabled

Debug(prefix)

Create a new Debug instance and set its prefix.

debug(...msg)

Debug instance, output whatever input is given with the associated prefix.

See debug.log() for full details.

debug.log(...msg)

Output the message contents. This is just a convenience wrapper for debug(...msg) that makes chaining a little easier.

If the first argument is a number, it is assumed to be the verbosity level to print at.

import Debug from '../lib/debugNode.js';
let log = Debug('Foo').verbosity(1);

log('Default'); // Will output
log(1, 'One'); // Will output if verbosity >= 1
log(2, 'Two'); // Will not print as if verbosity == 1

debug.prefix(prefix)

Set a new, permanent prefix for this instance.

debug.as(prefix, ...msg?)

Set a temporary prefix for the next logging operation. This will revert to the last prefix after log() has performed an operation.

import Debug from '../lib/debugNode.js';
let log = Debug('Foo');

log('1'); // Output: [Foo] 1

log.as('Bar', '2'); // Output: [Bar] 2

log.as('Baz').log('3'); // Output: [Baz] 3

debug.warn(...msg)

Same as log() but outputs to STDERR instead of STDOUT.

debug.force(...msg)

Output even if this logger is disabled.

debug.enable(isEnabled?)

Set whether this debugger is enabled.

debug.disable(isDisabled?)

Opposite of enable()

debug.only(...msg)

Output a message (even if disabled) then disable this logger.

debug.verbosity(level)

Set the verbosity level of the debugging component.

debug.highlight(match, color, options)

Add a highlighting option to add color / special characters to matched text.

Match is a RegExp to match against and color is the function to use to decorate the match.

If capture groups are used they are passed as the arguments to the function in order, if no capture groups are present the entire matching string is highlighted.

let log = Debug('Highlighting')
log.highlight(/SKU:\d{3,6}/g, log.colors.blue, {prefix: '▷', suffix: '◁'});

log('Should highlight SKUs like SKU:123, SKU:66666 & SKU:123456');

Options are:

| Option | Type | Default | Description | |----------|----------|---------|-------------------------------------| | prefix | string | '' | Optional prefix to add to the match | | suffix | string | '' | Optional suffix to add to the match |

debug.new(prefix)

Create a new debugger based on the given prefix.

debug.clone(prefix)

Create a new debugger based on the given prefix but also copy over all existing settings.

debug.diff(options)

Selectively log the differences between two objects.

Options are:

|Name | Types | Default | Description | |--------------| ------------------------- | ---------| |log | function | this | Log output function to use, must provide color library as .colors subkey | |original | Object | | Original, pristine value to examine | |originalVia | function | | Optional function to run original via before diffing. Called as (original, settings) | |updated | Object | | Updated value, provide either this OR merge key | |updatedVia | function | | Optional function to run updated (or merged) obejcts through via before diffing. Called as (updated, settings) | |merge | Object | | Value to merge with original (mutating original) | |mergeVia | function | | Function to conduct the merge of original + merge. Called as (original, merge, settings), if this function returns non-falsy that value is now used as the updated object | |prefix | string | | String to use as prefix when a diff is detected | |ignore | Array or Set | ['updated'] | Paths to ignore from output | |noChanges | string | | String to force display if no changes are present, if omitted nothing is shown | |inspect | function | utils.inspect | Inspector to use when formatting object output. Called as (thing, settings) | |formatter | function | | Function to use for formated output. Called as (diff, settings) |

debug.colors

Only available to Node instances. Instance of Chalk to easily wrap coloring.

import Debug from '../lib/debugNode.js';
let log = Debug('MyApp', log.colors.red('Red'), log.colors.white('White'), log.colors.blue('Blue'));

debug.enabled

Boolean indicating if this debugger is enabled.