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

silentconsole

v1.0.1

Published

silence the console output or filter what makes method execute

Downloads

4

Readme

silentConsole

Globally overwrite console methods - silence all, filter individually.

Motivation

Just debugging a legacy project and I had too many logs / warnings printing to the console. I started to remove / comment them, but realized they could be useful later on. This module is just an extension of the code I wrote for that use.

Usage

Install

npm install --save-dev silentconsole

How to Implement

You can use it at the file level, but it is best for importing at top level (usually your main entry ie index.js) and using for global silencing / filtering of console output.

Globally silence console.log and console.warn

import silentConsole from 'silentconsole';
silentConsole('log');
silentConsole('warn');

console.log('foo'); // will not print to console
console.warn('foo'); // will not print to console
console.info('foo'); // will print 'foo' to console

Globally filter console.log and console.warn with filter method as second argument to silentConsole

import silentConsole from 'silentconsole';
silentConsole('log', (text) => !text.includes('bar'));
silentConsole('warn', (text) => !text.includes('baz'));

console.log('foo'); // will print 'foo' to console
console.log('bar'); // will not print to console

console.warn('foo bar'); // will print 'foo bar' to console
console.warn('foo bar baz'); // will not print to console

Globally silence console.log, but allow it for single instances

original will be added to the console object storing all of the original methods of console.

import silentConsole from 'silentconsole';
silentConsole('log');

console.log('foo'); // will not print to console
console.log('bar'); // will not print to console

console.original.log('foo'); // will print 'foo' to console

Globally set as false, restore to make further statements work

This is not a great good use.

Either call method again with no 2nd parameter
import silentConsole from 'silentconsole';  
silentConsole('log');
console.log('foo'); // will not print to console
console.log('bar'); // will not print to console

silentConsole('log');
console.log('foo'); // will print 'foo' to console
console.log('bar'); // will print 'bar' to console

Or call method again with 2nd parameter false as in, do not override log.
import silentConsole from 'silentconsole';  
silentConsole('log');
console.log('foo'); // will not print to console
console.log('bar'); // will not print to console

silentConsole('log', false);
console.log('foo'); // will print 'foo' to console
console.log('bar'); // will print 'bar' to console

Prints all arguments passed like a standard console method

Even if you setup the silentConsole, you can still pass in multiple arguments. The printed results will be a bit different depending on what you pass as last argument.

import silentConsole from 'silentconsole';
silentConsole('log', (text) => !text.includes('test'));

console.log('foo', 'bar', 'baz'); // will print 'foo bar baz' to console
console.log('foo', 'bar'); // will print 'foo bar' to console

Author

STRsplit | ---| Steve Reed |