Socket
Socket
Sign inDemoInstall

warning

Package Overview
Dependencies
2
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    warning

A mirror of Facebook's Warning


Version published
Weekly downloads
9.2M
increased by5.84%
Maintainers
1
Install size
32.4 kB
Created
Weekly downloads
 

Package description

What is warning?

The 'warning' npm package is a utility that allows developers to print warning messages to the console. It is typically used to alert developers of potential issues or misuses of an API that are not severe enough to warrant throwing an error. It is often used in development environments to provide guidance without interrupting the execution of the program.

What are warning's main functionalities?

Conditional warnings

This feature allows developers to conditionally display warning messages based on a boolean condition. If the condition is true, the warning message is printed to the console.

var warning = require('warning');

var shouldWarn = true;
warning(shouldWarn, 'This is a warning message that will only be displayed if shouldWarn is true.');

Other packages similar to warning

Changelog

Source

4.0.3 (2019-02-09)

Bug Fixes

  • incorrect formatting of message with arguments (b188176)

<a name="4.0.2"></a>

Readme

Source

Warning npm version

Greenkeeper badge A mirror of Facebook's Warning

Usage

npm install warning
// some script
var warning = require('warning');

var ShouldBeTrue = false;

warning(
  ShouldBeTrue,
  'This thing should be true but you set to false. No soup for you!'
);
//  'This thing should be true but you set to false. No soup for you!'

Similar to Facebook's (FB) invariant but only logs a warning if the condition is not met. This can be used to log issues in development environments in critical paths. Removing the logging code for production environments will keep the same logic and follow the same code paths.

FAQ (READ before opening an issue)

Why do you use console.error instead of console.warn ?

This is a mirror of Facebook's (FB) warning module used within React's source code (and other FB software). As such this module will mirror their code as much as possible.

The descision to use error over warn was made a long time ago by the FB team and isn't going to change anytime soon.

The source can be found here: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/__forks__/warning.js The reasoning can be found here and elsewhere: https://github.com/facebook/fbjs/pull/94#issuecomment-168332326

Can I add X feature?

This is a mirror of Facebook's (FB) warning and as such the source and signature will mirror that module.

If you believe a feature is missing than please open a feature request there. If it is approved and merged in that this module will be updated to reflect that change, otherwise this module will not change.

Use in Production

It is recommended to add babel-plugin-dev-expression with this module to remove warning messages in production.
















Don't Forget To Be Awesome

Keywords

FAQs

Last updated on 09 Feb 2019

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