warning
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
loose-envify | 1.4.0 | 2.78 kB | MIT | prod |
Warning is a JavaScript package that acts as a mirror of Facebook's Warning module. Its primary function is to log warnings if certain predefined conditions are not met, making it especially useful for identifying issues in development environments during critical paths. Unlike Facebook's invariant, which completely halts execution when a condition fails, Warning simply logs these discrepancies so you can review them at your convenience. This ensures that the same logic and code paths are maintained even when the logging code is removed for production environments.
Using Warning in your JavaScript project is straightforward. After installing it through npm using the command npm install warning
, you can require it in your script and then use it to check conditions. Here's an example:
// Import the package
var warning = require('warning');
// Define a variable
var ShouldBeTrue = false;
// Use warning to check the condition
warning(
ShouldBeTrue,
'This thing should be true but you set to false. No soup for you!'
);
// Output: 'This thing should be true but you set to false. No soup for you!'
In the above example, if ShouldBeTrue
doesn't contain a truthy value, the warning message is logged to the console.
The documentation for Warning is available directly in the source which is hosted on Facebook's GitHub. The specific link to the source file is here.
Remember to read through the Frequently Asked Questions (FAQ) in the repository before opening an issue. If you want to add a new feature, it's advisable to open a feature request in Facebook's warning module. This is because Warning follows Facebook's module closely, any changes in the source will be reflected in this package.
For use in production environments, Warning recommends adding babel-plugin-dev-expression to remove warning messages in production.