Skip to content

Instantly share code, notes, and snippets.

@burdiuz
Last active December 29, 2019 19:03
Show Gist options
  • Save burdiuz/ed85abf7d6df0231baead12231afbef3 to your computer and use it in GitHub Desktop.
Save burdiuz/ed85abf7d6df0231baead12231afbef3 to your computer and use it in GitHub Desktop.
@actualwave/call-if-function -- calls function and returns everything else

@actualwave/call-if-function

callIfFunction accepts multiple arguments and checks first one. If it is a function, it will be called with other arguments passed to it(just like for Function.call()) If it is not a function, then value from first argument wil be returned.

I use it in react components, to check if component children are react nodes or a renderer function.

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const { isFunction } = require('@actualwave/is-function');
const callIfFunction = (value, ...args) => (isFunction(value) ? value(...args) : value);
exports.callIfFunction = callIfFunction;
exports.default = callIfFunction;
{
"name": "@actualwave/call-if-function",
"description": "Calls function and returns everything else",
"version": "0.0.1",
"main": "index.js",
"keywords": [
"function",
"call"
],
"author": {
"name": "Oleg Galaburda",
"email": "burdiuz@gmail.com",
"url": "http://actualwave.com/"
},
"bugs": {
"url": "https://gist.github.com/burdiuz/ed85abf7d6df0231baead12231afbef3",
"email": "burdiuz@gmail.com"
},
"homepage": "https://gist.github.com/burdiuz/ed85abf7d6df0231baead12231afbef3",
"dependencies": {
"@actualwave/is-function": "0.0.1"
},
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment