Socket
Socket
Sign inDemoInstall

filter-console

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    filter-console

Filter out unwanted `console.log()` output


Version published
Weekly downloads
191K
increased by6.39%
Maintainers
1
Install size
7.30 kB
Created
Weekly downloads
 

Readme

Source

filter-console

Filter out unwanted console.log() output

Can be useful when you don't control the output, for example, filtering out PropType warnings from a third-party React component.

Install

$ npm install filter-console

Usage

import filterConsole from 'filter-console';

const disableFilter = filterConsole(['🐼']);

const log = () => {
	console.log('');
	console.log('🦄');
	console.log('🐼');
	console.log('🐶');
};

log();

disableFilter();

log();
$ node example.js

🦄
🐶

🦄
🐼
🐶

API

filterConsole(excludePatterns, options?)

Returns a function, which when called, disables the filter.

excludePatterns

Type: Array<string | RegExp | Function>

Console output that matches any of the given patterns are filtered from being logged. The patterns are matched against what would be logged and not the console method input arguments directly. Meaning an exclude pattern of 'foo bar' will match console.log('foo %s', 'bar').

Filter types:

  • string: Checks if the string pattern is included in the console output.
  • RegExp: Checks if the RegExp pattern matches the console output.
  • Function: Receives the console output as a string and is expected to return a truthy/falsy value of whether to exclude it.
options

Type: object

methods

Type: string[]
Default: ['log', 'debug', 'info', 'warn', 'error']

Console methods to filter.

console

Type: object
Default: console

Use a custom console object. Can be useful for testing or mocking.

Keywords

FAQs

Last updated on 26 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc