before
function before(n, func) { let result if (typeof func != 'function') { throw new TypeError('Expected a function') } return function(...args) { if (--n > 0) { result = func.apply(this, args) } if (n <= 1) { func = undefined } return result }}export default before
once
import before from './before.js'function once(func) { return before(2, func)}export default once
———————————-
getTag
const toString = Object.prototype.toString/** * Gets the `toStringTag` of `value`. * * @private * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */function getTag(value) { if (value == null) { return value === undefined ? '[object Undefined]' : '[object Null]' } return toString.call(value) }export default getTag
isSymbol
import getTag from './.internal/getTag.js'/** * Checks if `value` is classified as a `Symbol` primitive or object. * * @since 4.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * isSymbol(Symbol.iterator) * // => true * * isSymbol('abc') * // => false */function isSymbol(value) { const type = typeof value return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]')}export default isSymbol
baseToString
import isSymbol from '../isSymbol.js'/** Used as references for various `Number` constants. */const INFINITY = 1 / 0/** Used to convert symbols to primitives and strings. */const symbolToString = Symbol.prototype.toString/** * The base implementation of `toString` which doesn't convert nullish * values to empty strings. * * @private * @param {*} value The value to process. * @returns {string} Returns the string. */function baseToString(value) { // Exit early for strings to avoid a performance hit in some environments. if (typeof value == 'string') { return value } if (Array.isArray(value)) { // Recursively convert values (susceptible to call stack limits). return `${value.map(baseToString)}` } if (isSymbol(value)) { return symbolToString ? symbolToString.call(value) : '' } const result = `${value}` return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result}export default baseToString
baseToNumber
import isSymbol from '../isSymbol.js'/** Used as references for various `Number` constants. */const NAN = 0 / 0/** * The base implementation of `toNumber` which doesn't ensure correct * conversions of binary, hexadecimal, or octal string values. * * @private * @param {*} value The value to process. * @returns {number} Returns the number. */function baseToNumber(value) { if (typeof value == 'number') { return value } if (isSymbol(value)) { return NAN } return +value}export default baseToNumber
createMathOperation
import baseToNumber from './baseToNumber.js'import baseToString from './baseToString.js'/** * Creates a function that performs a mathematical operation on two values. * * @private * @param {Function} operator The function to perform the operation. * @param {number} [defaultValue] The value used for `undefined` arguments. * @returns {Function} Returns the new mathematical operation function. */function createMathOperation(operator, defaultValue) { return (value, other) => { if (value === undefined && other === undefined) { return defaultValue } if (value !== undefined && other === undefined) { return value } if (other !== undefined && value === undefined) { return other } if (typeof value === 'string' || typeof other === 'string') { value = baseToString(value) other = baseToString(other) } else { value = baseToNumber(value) other = baseToNumber(other) } return operator(value, other) }}export default createMathOperation
add
import createMathOperation from './.internal/createMathOperation.js'/** * Adds two numbers. * * @since 3.4.0 * @category Math * @param {number} augend The first number in an addition. * @param {number} addend The second number in an addition. * @returns {number} Returns the total. * @example * * add(6, 4) * // => 10 */const add = createMathOperation((augend, addend) => augend + addend, 0)export default add