suppress-warnings
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Suppress Warnings!

This module helps suppress some annoying warnings you may get that you're either too lazy to fix, or can't because it's not in a module you control.

The main function takes an array of "filter functions", as the first parameter, of which the arguments will be the same as process.emitWarning (It's also dynamic, so as node changes, it should also change.), the second parameter can be used to change the default behavior (blacklist), into a whitelist.

Examples:

JavaScript

// This must be called BEFORE any of the errors get sent, so require this first and run the function first before requiring any other modules
const SuppressWarnings = require("suppress-warnings");
// say you were getting a log like this: https://butts-are.cool/Code_-_Insiders_qeiR4Gtkyh.png
// (which is the warning that prompted me to make this)
// name: DeprecationWarning
// message: OutgoingMessage.prototype._headers is deprecated
 
// the first parameter is an array of filter functions
// return TRUE to hide the warning, and FALSE to pass it back to node
 
// the second parameter turns the default behavior (blacklist) into a whitelist
// where TRUE to pass it to node, and FALSE to hide it
SuppressWarnings([
    // warning can be an Error object or a string
    // name is always a string (can be absent)
    // I really don't know what ctor is, but it's in the ts definition
    (warning, name, ctor) => name === "DeprecationWarning" && warning.toString() === "OutgoingMessage.prototype._headers is deprecated"
]);

TypeScript

// This must be called BEFORE any of the errors get sent, so require this first and run the function first before requiring any other modules
import SuppressWarnings from "suppress-warnings";
 
// this is all the same, see JavaScript version for details
 
SuppressWarnings([
    (warning, name, ctor) => name === "DeprecationWarning" && warning.toString() === "OutgoingMessage.prototype._headers is deprecated"
]);

Package Sidebar

Install

npm i suppress-warnings

Homepage

furry.cool

Weekly Downloads

171

Version

1.0.2

License

MIT

Unpacked Size

10.3 kB

Total Files

9

Last publish

Collaborators

  • donovan_dmc