Comparing version 1.0.0 to 1.0.1
@@ -21,8 +21,6 @@ /** | ||
/** | ||
* @param {Boolean} condition - Condition used to determine whether to call end | ||
* return the result of `func` or `undefined`. | ||
* @param {Function} func - Function to be called if condition evaluates to | ||
* @param {Function} func - Function to be called if `condition` evaluates to | ||
* `true`. | ||
@@ -44,3 +42,3 @@ * @param {...?*} funcParams - Parameters to be passed to `func`, if called. | ||
* return the result of `func` or `undefined`. | ||
* @param {Function} func - Function to be called if condition evaluates to | ||
* @param {Function} func - Function to be called if `condition` evaluates to | ||
* `true`. | ||
@@ -47,0 +45,0 @@ * @param {...?*} funcParams - Parameters to be passed to `func`, if called. |
@@ -35,7 +35,6 @@ /** | ||
/** | ||
* @param {Boolean} condition - Condition used to determine whether to call end | ||
* return the result of `func` or `undefined`. | ||
* @param {Function} func - Function to be called if condition evaluates to | ||
* @param {Function} func - Function to be called if `condition` evaluates to | ||
* `true`. | ||
@@ -57,3 +56,3 @@ * @param {...?*} funcParams - Parameters to be passed to `func`, if called. | ||
* return the result of `func` or `undefined`. | ||
* @param {Function} func - Function to be called if condition evaluates to | ||
* @param {Function} func - Function to be called if `condition` evaluates to | ||
* `true`. | ||
@@ -60,0 +59,0 @@ * @param {...?*} funcParams - Parameters to be passed to `func`, if called. |
{ | ||
"name": "call-if", | ||
"version": "1.0.0", | ||
"description": "Functions that call a given function if given conditions are met.", | ||
"version": "1.0.1", | ||
"description": "Micro-library of functions that call a given function if a given condition is met.", | ||
"authors": [ | ||
@@ -6,0 +6,0 @@ "Brandon Sara (http://bsara.pro)" |
@@ -5,5 +5,85 @@ # call-if [![NPM Package](https://img.shields.io/npm/v/call-if.svg?style=flat-square)][npm] | ||
> A micro-library of functions that call a given function if a given condition is met. | ||
> This library was created for both convenience purposes and for the cleaner code that | ||
> can be produced by using it's provided functions. | ||
> **NOTE:** Compatible with ES4+ browsers, AMD, CommonJS, ES6 Imports, and HTML | ||
> script references. | ||
[Changelog](https://github.com/bsara/call-if/blob/master/CHANGELOG.md) | ||
## Install | ||
```bash | ||
$ npm i --save call-if | ||
``` | ||
## Usage | ||
```js | ||
import { callIf, callIfOrNull } from 'callIf'; | ||
function myFunc(valueToPrint, valueToReturn) { | ||
console.log(valueToPrint); | ||
return valueToReturn; | ||
} | ||
callIf(true, myFunc, "Fish fingers and custard", 42); // Prints "Fish fingers and custard" & returns 42 | ||
callIf(false, myFunc, "Fish fingers and custard", 42); // Prints nothing and returns `undefined` | ||
callIfOrNull(true, myFunc, "Fish fingers and custard", 42); // Prints "Fish fingers and custard" & returns 42 | ||
callIfOrNull(false, myFunc, "Fish fingers and custard", 42); // Prints nothing and returns `null` | ||
``` | ||
## API | ||
### callIf(condition, func, *[...funcParams]*) | ||
Returns the result of calling `func` if given `condition` evaluates to `true`; otherwise, | ||
returns `undefined`. | ||
- **condition** `Boolean` | ||
Condition used to determine whether to call end return the result of `func` or `undefined`. | ||
- **func** `*` | ||
Function to be called if `condition` evaluates to `true`. | ||
- **...funcParams** `*` | ||
Parameters to be passed to `func`, if called. | ||
<br/> | ||
### callIfOrNull(condition, func, *[...funcParams]*) | ||
Returns the result of calling `func` if given `condition` evaluates to `true`; otherwise, | ||
returns `null`. | ||
- **condition** `Boolean` | ||
Condition used to determine whether to call end return the result of `func` or `null`. | ||
- **func** `*` | ||
Function to be called if `condition` evaluates to `true`. | ||
- **...funcParams** `*` | ||
Parameters to be passed to `func`, if called. | ||
<br/> | ||
<br/> | ||
@@ -10,0 +90,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11499
8
112