New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@origin-yaropolk/debug-assert

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@origin-yaropolk/debug-assert

Helps your app meet fail-fast/fail-safe principles

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Small lib that helps your app meet fail-fast and fail-save principles.

Usage

import { assert } from 'debug-assert';

assert(myCondition, 'Print this if failed');

You can setup your own fail-fast function:

import { assert, setupFailFast } from 'debug-assert';

setupFailFast((err: Error) => {
  console.error(err);
  collectSomeData();
  process.abort();
});

assert(myCondition, 'Print this if failed');

Change the principle by calling setupMode function:

import { assert, setupMode } from 'debug-assert';

// calls fail-fast function
// it's default behaviour
assert(myCondition, 'Print this if failed');

setupMode('fail-safe');
// throws an exception
assert(myCondition, 'Print this if failed');

setupMode('ignore');
// replaced with noop
assert(myCondition, 'Print this if failed');

There is an assertNotNull alias:

import { assertNotNull } from 'debug-assert';

assertNotNull(null, 'Print this if failed'); // will fail
assertNotNull(undefined, 'Print this if failed'); // not fail
assertNotNull(0, 'Print this if failed'); // not fail

Keywords

debug assert

FAQs

Package last updated on 12 Dec 2024

Did you know?

Socket

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