Socket
Socket
Sign inDemoInstall

ts-invariant

Package Overview
Dependencies
1
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-invariant

TypeScript implementation of invariant(condition, message)


Version published
Weekly downloads
4.6M
decreased by-1.13%
Maintainers
1
Install size
76.7 kB
Created
Weekly downloads
 

Package description

What is ts-invariant?

The ts-invariant package provides utility functions for asserting invariants within TypeScript applications. It is designed to throw errors when certain conditions are not met, which can be useful for catching programming errors and enforcing certain constraints at runtime.

What are ts-invariant's main functionalities?

Invariant

The invariant function is used to assert that a condition is true. If the condition is false, it will throw an error with the provided error message.

import { invariant } from 'ts-invariant';
invariant(condition, 'Expected condition to be true');

Invariant.warn

The invariant.warn function is used to log a warning message to the console. It does not throw an error.

import { invariant } from 'ts-invariant';
invariant.warn('This is a warning message');

Invariant.error

The invariant.error function is used to log an error message to the console. It does not throw an error.

import { invariant } from 'ts-invariant';
invariant.error('This is an error message');

Other packages similar to ts-invariant

Readme

Source

ts-invariant

TypeScript implementation of invariant(condition, message).

Supports invariant.log, invariant.warn, and invariant.error, which wrap console methods of the same name, and may be stripped in production by rollup-plugin-invariant.

The verbosity of these methods can be globally reconfigured using the setVerbosity function:

import { setVerbosity } from "ts-invariant";

setVerbosity("log"); // display all messages (default)
setVerbosity("warn"); // display only warnings and errors
setVerbosity("error"); // display only errors
setVerbosity("silent"); // display no messages

Keywords

FAQs

Last updated on 13 May 2022

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