1.0.0 • Published 5 years ago

@tigre/dev-warning v1.0.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
5 years ago

@tigre/dev-warning

A simple, tiny library for enabling development only warnings to be easily published to the console.

The library automatically stops producing the warnings when built in production mode. To build in production mode use whichever bundler you like and ensure that process.env.NODE_ENV is set to equal production.

This module does nothing useful in production mode, so if you have tree-shaking enabled you can wrap any call to this module with:

import createDevWarning from "@tigre/dev-warning";

if (process.env.NODE_ENV === "development") {

	// Perform the check that needs a development warning
	if (/* someone made a development mistake */) {
		createDevWarning(
			"<The error message>", 		// A useful and descriptive error message
			{ 							// This object is optional, when included it will only 
										// display the message once per unique set of switches in the file
										// All fields in this object are optional.
				file: __filename, 		// Typically useful to include, `__filename` needs to be enabled in webpack
				warning: "warning", 	// Also very useful unless a single warning possible
				detail: "detail",
				extra: "extra"
			}, 
			{ 
				more: "details" 		// Optional object that gets printed in the console.warn call.
										//  This can be used to provide extra diagnostic details to solve the problem.
			}
		);
	}
}

Recommended usage:

import createDevWarning from "@tigre/dev-warning";

// Easy, repeats every time
if (process.env.NODE_ENV === "development") {
	createDevWarning("Repeating warning");
}

// Medium, only triggers once
if (process.env.NODE_ENV === "development") {
	createDevWarning("warning", {
		file: __filename,
		warning: "single time"
	});
}

// Detailed, only triggers once, gives lots of how to fix details
if (process.env.NODE_ENV === "development") {
	createDevWarning("warning", {
		file: __filename,
		warning: "single time"
	}, {
		causedBy: "information",
		reason: "bad"
	});
}