@bemoje/assert-args

Assert that the passed arguments are defined.

Usage no npm install needed!

<script type="module">
  import bemojeAssertArgs from 'https://cdn.skypack.dev/@bemoje/assert-args';
</script>

README

@bemoje/assert-args

Assert that the passed arguments are defined.

Version

NPM version

Travis CI

dependencies

Dependencies

dependencies

Stats

NPM downloads Forks

Donate

Buy Me A Beer donate button PayPal donate button

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