0.3.0 • Published 3 years ago

dyndef v0.3.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
3 years ago

Dyndef: Dynamic Defensive Programming for JavaScript

is

Verify that a value is of a certain type.

// examples/is.js

import {is} from "dyndef";

try {
  // doesn't throw
  is("string").string();
  // throws
  is(true).string();
} catch (error) {
  if (error instanceof TypeError) {
    console.log(error.message);
    // -> `true` must be of type string
  }
}

maybe

Verify that a value is of a certain type, or that it is undefined or null.

// examples/maybe.js

import {maybe} from "dyndef";

try {
  // doesn't throw
  maybe("string").string();
  maybe().string();
  maybe(null).string();
  // throws
  maybe(true).string();
} catch (error) {
  if (error instanceof TypeError) {
    console.log(error.message);
    // -> `true` must be of type string
  }
}

License

BSD-3-Clause

0.3.0

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.1.0

3 years ago