undef-check
v0.0.4
Published
Undefined or Null Checker.
Downloads
5
Maintainers
Readme
undef-check
Undefined and Null Checker
npm i undef-check
import module
// ES6 Syntax
import {undefCheck} from "undef-check";
// Commonjs Syntax
const {undefCheck} = require("undef-check");
// Commonjs with custom name
const undefinedChecker = require("undef-check").undefCheck;
usage
undefCheck(possibleUndefinedVariable);
demo
let nullVariable = null;
let undefinedVariable = void 0;
undefCheck(undefinedVariable); // throws error with default message
undefCheck(nullVariable, "Variable cannot be null."); // throws error with "Variable cannot be null." message
undefCheck(-6.2342); // no errors
undefCheck("Hello, world"); // no errors
types
type undefCheck = (value: any, message?: string) => void; // throws Error.