UNPKG

type-enforcer

Version:
29 lines (27 loc) 598 B
import isFunction from '../checks/isFunction'; /** * Enforce that a value is a function. Uses [isFunction](docs/checks.md#isFunction). * * @example * ``` javascript * import { enforce } from 'type-enforcer'; * * const a = () => {}; * const b = () => {}; * * enforce.function(a, b); * // => a * * enforce.function('', b); * // => b * ``` * * @function enforce.function * @alias enforceFunction * * @arg {*} value * @arg {Function} alt - Returned if the value is not the correct type * * @returns {Function} */ export default (value, alt) => isFunction(value) ? value : alt;