- assertArgument
- isBoolean
- isString
- isNumber
- isObject
- isArray
- isFunction
- isRegExp
- isPromise
- isDate
- isError
- isBuffer
Assert that a value is true
Parameters
bool
boolean value that is expected to be atrue
boolean or at least "truthy" valuemessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAString (str) {
assert(typeof str === 'string', 'str param must be a string')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not true
Returns undefined
Assert that a value is a boolean
Parameters
bool
boolean value that is expected to be a booleanmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithABoolean (bool) {
assert.isBoolean(bool, 'bool param must be a string')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a boolean
Returns undefined
Assert that a value is a string
Parameters
str
string value that is expected to be a stringmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAString (str) {
assert.isString(str, 'str param must be a string')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a string
Returns undefined
Assert that a value is a number
Parameters
num
number value that is expected to be a numbermessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithANumber (num) {
assert.isNumber(num, 'num param must be a number')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a number
Returns undefined
Assert that a value is an object
Parameters
obj
object value that is expected to be a objectmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAString (obj) {
assert.isObject(obj, 'obj param must be an object')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not an object
Returns undefined
Assert that a value is an array
Parameters
arr
array value that is expected to be an arraymessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithnArray (arr) {
assert.isArray(arr, 'arr param must be an array')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not an array
Returns undefined
Assert that a value is a function
Parameters
fn
function value that is expected to be a functionmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAFunction (fn) {
assert.isFunction(fn, 'fn param must be a function')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a function
Returns undefined
Assert that a value is a RegExp
Parameters
re
RegExp value that is expected to be a RegExpmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithARegExp (re) {
assert.isRegExp(re, 're param must be a regexp')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a RegExp
Returns undefined
Assert that a value is a promise
Parameters
p
promise value that is expected to be a promisemessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAPromise (p) {
assert.isPromise(p, 'p param must be a ')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a promise
Returns undefined
Assert that a value is a Date object
Parameters
date
Date value that is expected to be a Date objectmessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithADate (date) {
assert.isDate(date, 'date param must be a Date object')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a Date object
Returns undefined
Assert that a value is an Error
Parameters
errObj
Error value that is expected to be an Errormessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithAnError (errObj) {
assert.isError(errObj, 'errObj param must be an Error')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not an Error
Returns undefined
Assert that a value is a Buffer
Parameters
buf
Buffer value that is expected to be a Buffermessage
string? optional message describing the assertion
Examples
var assert = require('assert-argument')
function doSomethingWithABuffer (buf) {
assert.isBuffer(buf, 'buf param must be a Buffer')
}
*
- Throws ArgumentError throws an
ArgumentError
if the value is not a Buffer
Returns undefined