0.3.0 • Published 3 years ago
dyndef v0.3.0
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