Package detail

@dozerg/condition

daidodo30.3kMIT1.0.11

Preconditions utility for TypeScript and JavaScript.

precondition, condition, assert, isNonNull

readme

Condition

npm Downloads Build Status

Utilities for preconditions and assertions for TypeScript and JavaScript.

Install

npm i @dozerg/condition

Usage

import { isNonNull, assertNonNull } from '@dozerg/condition';

function foo(p?: string) {
  assertNonNull(p);
  p.length; // OK, p is string
  // ...

  const a = [1, undefined, 2];   // a is (number | undefined)[]
  const b = a.filter(isNonNull); // b is [1, 2], i.e. number[]
  // ...
}

APIs

License

MIT © Zhao DAI daidodo@gmail.com

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[1.0.3] - 2022-09-18

Added

  • isObject
  • assertIsObject

[1.0.1] - 2022-02-27

Added

  • assertIsBigint
  • assertIsBoolean
  • assertIsClass
  • assertIsNumber
  • assertIsString
  • assertNonNull
  • assertTrue
  • isBigint
  • isBoolean
  • isClass
  • isNonNull
  • isNumber
  • isString