Ministry of Technology
Show Menu

Argument Guard

Argument Guard
Created by Ministry
Language
JavaScript (ES5)
Type
Library

This project provides simple guard methods for throwing appropriate type errors when arguments are incorrect.

Variants supported...

  • throwIf() - Throws if the parameter is null or undefined.
  • throwIfNotIn() - Throws if the required parameter is not in the range of expected values.
  • throwIfNull() - Throws if the required parameter is null.
  • throwIfUndefined() - Throws if the parameter is undefined.
  • throwIfNaN() - Throws if the specified parameter is not a number.

Sample usage

const guard = require("arg-guard");

const myFunc = function(requiredArg, otherArg) {
    guard.throwIf(requiredArg, "requiredArg");
}
Visit us on GitHub