
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
invariant-slim
Advanced tools
A simpler version of Facebook's invariant implementation from React.
invariant-slim
is available as an npm package. Simply run npm install invariant-slim
command.
To use it in your project:
import invariant from 'invariant-slim'; // ES6 syntax
var invariant = require('invariant-slim'); // ES5 syntax
Use invariant()
to assert state which your program assumes to be true.
Pass in a condition to be evaluated and a format to be displayed as an error message.
The format respects the sprintf
-style syntax ('%s' will be replaced by whatever arguments are passed in).
The following code will not throw:
invariant(
true,
'Demo message'
);
The following code will throw with a static message and will output the following error in the console - 'Invariant Violation: A static error message':
invariant(
false,
'A static error message'
);
The following code will throw with a dynamic formatted error message and will output the following error in the console - 'Invariant Violation: A dynamic error message arg1,arg2':
invariant(
false,
'A dynamic error message %s',
['arg1', 'arg2']
);
This software is released under the terms of WTFPL v2.0 license.
FAQs
A simpler version of Facebook's invariant implementation from React
We found that invariant-slim demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.