@crpt/react-utils
Version:
A useful kit for daily using
22 lines (17 loc) • 993 B
JavaScript
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
import warning from 'warning';
/**
* @param {any} accumulator
*/
export var checkAccumulator = function checkAccumulator(accumulator) {
var isValid = typeof accumulator === 'function';
var message = ' (utils/lib/propsUtils) accumulateWith: Expected "accumulator" of type \'' + (typeof accumulator === 'undefined' ? 'undefined' : _typeof(accumulator)) + '\' to be a function. ';
return isValid ? true : warning(isValid, message.replace(/ +/g, ' '));
};
/**
* @param {Array} sources
* @param {Function} accumulator
*/
export var accumulateWith = function accumulateWith(sources, accumulator) {
return checkAccumulator(accumulator) ? accumulator.apply(undefined, [{}].concat(sources)) : undefined;
};