Socket
Socket
Sign inDemoInstall

call-if

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

call-if - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

CHANGELOG.md

6

index.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc