# call-if

> Micro-library of functions that call a given function if a given condition is met.

Latest version **1.0.5** (published 2018-10-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install call-if
pnpm add call-if
yarn add call-if
bun add call-if
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-10-09 |
| First published | 2018-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | bsara |
| Keywords | call, callif, call-if, callunless, call-unless, if, unless, condition, conditional, conditionals |

## Links

- npm: https://www.npmjs.com/package/call-if
- Repository: https://github.com/bsara/call-if
- Homepage: https://github.com/bsara/call-if#readme
- Issues: https://github.com/bsara/call-if/issues
- npm.io page: https://npm.io/package/call-if

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2018-10-09
- 1.0.4 — 2018-02-21
- 1.0.3 — 2018-02-18
- 1.0.2 — 2018-02-18
- 1.0.1 — 2018-02-18
- 1.0.0 — 2018-02-18

## README

# call-if [![NPM Package](https://img.shields.io/npm/v/call-if.svg?style=flat-square)][npm]

![ISC License](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)

> 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 its 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 'call-if';


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`

  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`

  Function to be called if `condition` evaluates to `true`.

- **...funcParams** `?...*`

  Parameters to be passed to `func`, if called.


<br/>
<br/>


# License

ISC License (ISC)

Copyright (c) 2018, Brandon D. Sara (http://bsara.pro/)

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.



[license]: https://github.com/bsara/call-if/blob/master/LICENSE "License"
[npm]:     https://www.npmjs.com/package/call-if                "NPM Package: call-if"

---
_Source: https://npm.io/package/call-if · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
