1.0.2 • Published 4 years ago

@bemoje/assert-args v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@bemoje/assert-args

Assert that the passed arguments are defined.

Version

Travis CI

Dependencies

Stats

Donate

Installation

npm install @bemoje/assert-args
npm install --save @bemoje/assert-args
npm install --save-dev @bemoje/assert-args

Usage

import assertArgs from '@bemoje/assert-args'

/**
 * Adds a and b and throws Error if any parameters are missing
 */
function add(a, b) {
  assertArgs(a, b)
  return a + b
}

/**
 * Calls the callback and returns true if the callback throws an error and false otherwise.
 */
function didItThrow(callback) {
  try {
    callback()
    return false
  } catch (e) {
    return true
  }
}

didItThrow(() => add(1, 4))
//=> false

didItThrow(() => add(1))
//=> true

Tests

Uses Jest to test module functionality. Run tests to get coverage details.

npm run test

API

Table of Contents

assertArgs

Assert that the passed arguments are defined.

Parameters
  • args ...any arguments array

  • Throws Error If any passed argument is undefined.

Returns void