Skip to content

Latest commit

 

History

History
352 lines (218 loc) · 7.33 KB

api.md

File metadata and controls

352 lines (218 loc) · 7.33 KB

Table of Contents

assertArgument

Assert that a value is true

Parameters

  • bool boolean value that is expected to be a true boolean or at least "truthy" value
  • message 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

isBoolean

Assert that a value is a boolean

Parameters

  • bool boolean value that is expected to be a boolean
  • message 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

isString

Assert that a value is a string

Parameters

  • str string value that is expected to be a string
  • message 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

isNumber

Assert that a value is a number

Parameters

  • num number value that is expected to be a number
  • message 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

isObject

Assert that a value is an object

Parameters

  • obj object value that is expected to be a object
  • message 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

isArray

Assert that a value is an array

Parameters

  • arr array value that is expected to be an array
  • message 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

isFunction

Assert that a value is a function

Parameters

  • fn function value that is expected to be a function
  • message 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

isRegExp

Assert that a value is a RegExp

Parameters

  • re RegExp value that is expected to be a RegExp
  • message 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

isPromise

Assert that a value is a promise

Parameters

  • p promise value that is expected to be a promise
  • message 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

isDate

Assert that a value is a Date object

Parameters

  • date Date value that is expected to be a Date object
  • message 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

isError

Assert that a value is an Error

Parameters

  • errObj Error value that is expected to be an Error
  • message 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

isBuffer

Assert that a value is a Buffer

Parameters

  • buf Buffer value that is expected to be a Buffer
  • message 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