Ramda Adjunct 2.16.0

trunc.js

import { bind } from 'ramda';
import curry1 from 'ramda/src/internal/_curry1';

import polyfill from './internal/polyfills/Math.trunc';
import isFunction from './isFunction';

export const truncPolyfill = curry1(polyfill);

/**
 * Returns the integer part of a number by removing any fractional digits.
 *
 * @func trunc
 * @memberOf RA
 * @since {@link https://char0n.github.io/ramda-adjunct/2.15.0|v2.15.0}
 * @category Math
 * @sig Number | String -> Number
 * @param {number|string} number The number to trunc
 * @return {number} The integer part of the given number
 * @example
 *
 * RA.trunc(13.37); //=> 13
 * RA.trunc(42.84); //=> 42
 * RA.trunc(0.123); //=>  0
 * RA.trunc(-0.123); //=> -0
 * RA.trunc('-1.123'); //=> -1
 * RA.trunc(NaN); //=> NaN
 * RA.trunc('foo'); //=> NaN
 */

const trunc = isFunction(Math.trunc)
  ? curry1(bind(Math.trunc, Math))
  : truncPolyfill;

export default trunc;