├── .gitattributes ├── first.js ├── .internal ├── metaMap.js ├── reEscape.js ├── reEvaluate.js ├── reInterpolate.js ├── freeGlobal.js ├── asciiSize.js ├── asciiToArray.js ├── getHolder.js ├── baseIsNaN.js ├── root.js ├── baseProperty.js ├── basePropertyOf.js ├── cacheHas.js ├── addSetEntry.js ├── setToArray.js ├── addMapEntry.js ├── basePropertyDeep.js ├── mapToArray.js ├── setToPairs.js ├── iteratorToArray.js ├── castArrayLikeObject.js ├── cloneArrayBuffer.js ├── cloneSymbol.js ├── baseForOwn.js ├── initCloneObject.js ├── isStrictComparable.js ├── parent.js ├── stringSize.js ├── createSet.js ├── copySymbols.js ├── baseForOwnRight.js ├── cloneRegExp.js ├── baseInRange.js ├── stringToArray.js ├── baseConforms.js ├── setToString.js ├── copySymbolsIn.js ├── basePick.js ├── baseValues.js ├── copyArray.js ├── getAllKeys.js ├── isPrototype.js ├── castPath.js ├── arrayEachRight.js ├── assocIndexOf.js ├── castSlice.js ├── cloneDataView.js ├── arrayEach.js ├── baseSum.js ├── arrayIncludes.js ├── cloneTypedArray.js ├── isFlattenable.js ├── getAllKeysIn.js ├── toKey.js ├── baseSortBy.js ├── baseToNumber.js ├── baseUnset.js ├── baseAssignValue.js ├── baseAt.js ├── matchesStrictComparable.js ├── assignMergeValue.js ├── getMatchData.js ├── strictLastIndexOf.js ├── baseUpdate.js ├── charsEndIndex.js ├── arrayIncludesWith.js ├── strictIndexOf.js ├── baseGet.js ├── charsStartIndex.js ├── getSymbolsIn.js ├── baseIndexOf.js ├── memoizeCapped.js ├── baseIndexOfWith.js ├── baseZipObject.js ├── baseMatches.js ├── baseFindKey.js ├── baseForRight.js ├── createRange.js ├── baseRange.js ├── baseFindIndex.js ├── getSymbols.js ├── arrayReduceRight.js ├── baseConformsTo.js ├── baseSortedUniq.js ├── arrayReduce.js ├── createCaseFirst.js ├── isIndex.js ├── basePickBy.js ├── nodeUtil.js ├── createRound.js ├── baseEach.js ├── baseEachRight.js ├── assignValue.js ├── basePullAt.js ├── baseFor.js ├── isKey.js ├── baseReduce.js ├── baseWhile.js ├── baseOrderBy.js └── hasUnicode.js ├── each.js ├── CHANGELOG ├── eachRight.js ├── .gitignore ├── .editorconfig ├── isNull.js ├── mean.js ├── last.js ├── isUndefined.js ├── sample.js ├── isNil.js ├── sum.js ├── add.js ├── initial.js ├── head.js ├── tail.js ├── divide.js ├── lowerFirst.js ├── capitalize.js ├── subtract.js ├── multiply.js ├── round.js ├── ceil.js ├── shuffle.js ├── floor.js ├── isWeakMap.js ├── isWeakSet.js ├── at.js ├── uniqueId.js ├── upperFirst.js ├── fromPairs.js ├── flatten.js ├── isElement.js ├── isArguments.js ├── pick.js ├── hasIn.js ├── isSymbol.js ├── nthArg.js ├── over.js ├── isString.js ├── flowRight.js ├── sortedUniq.js ├── defaultTo.js ├── flip.js ├── isBoolean.js ├── lt.js ├── isObjectLike.js ├── sortedIndex.js ├── gt.js ├── zip.js ├── sortedUniqBy.js ├── lte.js ├── defer.js ├── flattenDeep.js ├── gte.js ├── once.js ├── compact.js ├── functions.js ├── isSet.js ├── sortedLastIndex.js ├── take.js ├── cloneDeep.js ├── zipObjectDeep.js ├── isMap.js ├── overSome.js ├── drop.js ├── delay.js ├── overEvery.js ├── propertyOf.js ├── replace.js ├── dropRight.js ├── zipObject.js ├── has.js ├── lowerCase.js ├── negate.js ├── upperCase.js ├── uniq.js ├── ary.js ├── findLast.js ├── isDate.js ├── isRegExp.js ├── nth.js ├── isObject.js ├── sumBy.js ├── toPath.js ├── snakeCase.js ├── defaultsDeep.js ├── union.js ├── clamp.js ├── method.js ├── isArrayLikeObject.js ├── kebabCase.js ├── takeRight.js ├── toPlainObject.js ├── xor.js ├── map.js ├── sortedIndexOf.js ├── castArray.js ├── values.js ├── pullAll.js ├── sortedLastIndexOf.js ├── isArrayLike.js ├── isArrayBuffer.js ├── camelCase.js ├── methodOf.js ├── eq.js ├── flattenDepth.js ├── isLength.js ├── pull.js ├── some.js ├── startCase.js ├── mapObject.js ├── attempt.js ├── property.js ├── toInteger.js ├── invert.js ├── without.js ├── uniqBy.js ├── forEachRight.js ├── escapeRegExp.js ├── someValue.js ├── unset.js ├── meanBy.js ├── sortedIndexBy.js ├── isFunction.js ├── isError.js ├── after.js ├── isNumber.js ├── pickBy.js ├── flatMapDeep.js ├── isTypedArray.js ├── sortedLastIndexBy.js ├── flatMap.js ├── intersection.js ├── padEnd.js ├── rangeRight.js ├── takeWhile.js ├── dropWhile.js ├── invoke.js ├── padStart.js ├── toFinite.js ├── zipWith.js ├── get.js ├── keys.js ├── mapKey.js ├── repeat.js ├── unzipWith.js ├── dropRightWhile.js ├── filterObject.js ├── forOwn.js ├── takeRightWhile.js ├── flatMapDepth.js ├── forOwnRight.js ├── startsWith.js ├── conformsTo.js ├── isNative.js ├── reject.js ├── before.js ├── toSafeInteger.js ├── overArgs.js ├── chunk.js ├── update.js ├── mapValue.js ├── sampleSize.js ├── uniqWith.js ├── findLastKey.js └── toLength.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /first.js: -------------------------------------------------------------------------------- 1 | export { default } from './head.js' 2 | -------------------------------------------------------------------------------- /.internal/metaMap.js: -------------------------------------------------------------------------------- 1 | export default new WeakMap 2 | -------------------------------------------------------------------------------- /each.js: -------------------------------------------------------------------------------- 1 | export { default } from './forEach.js' 2 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | https://github.com/lodash/lodash/wiki/Changelog 2 | -------------------------------------------------------------------------------- /eachRight.js: -------------------------------------------------------------------------------- 1 | export { default } from './forEachRight.js' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.log 3 | doc/*.html 4 | node_modules 5 | .idea/ 6 | -------------------------------------------------------------------------------- /.internal/reEscape.js: -------------------------------------------------------------------------------- 1 | /** Used to match template delimiters. */ 2 | const reEscape = /<%-([\s\S]+?)%>/g 3 | 4 | export default reEscape 5 | -------------------------------------------------------------------------------- /.internal/reEvaluate.js: -------------------------------------------------------------------------------- 1 | /** Used to match template delimiters. */ 2 | const reEvaluate = /<%([\s\S]+?)%>/g 3 | 4 | export default reEvaluate 5 | -------------------------------------------------------------------------------- /.internal/reInterpolate.js: -------------------------------------------------------------------------------- 1 | /** Used to match template delimiters. */ 2 | const reInterpolate = /<%=([\s\S]+?)%>/g 3 | 4 | export default reInterpolate 5 | -------------------------------------------------------------------------------- /.internal/freeGlobal.js: -------------------------------------------------------------------------------- 1 | /** Detect free variable `global` from Node.js. */ 2 | const freeGlobal = typeof global == 'object' && global !== null && global.Object === Object && global 3 | 4 | export default freeGlobal 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | indent_size = 2 10 | indent_style = space 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | -------------------------------------------------------------------------------- /.internal/asciiSize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the size of an ASCII `string`. 3 | * 4 | * @private 5 | * @param {string} string The string inspect. 6 | * @returns {number} Returns the string size. 7 | */ 8 | function asciiSize({ length }) { 9 | return length 10 | } 11 | 12 | export default asciiSize 13 | -------------------------------------------------------------------------------- /.internal/asciiToArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts an ASCII `string` to an array. 3 | * 4 | * @private 5 | * @param {string} string The string to convert. 6 | * @returns {Array} Returns the converted array. 7 | */ 8 | function asciiToArray(string) { 9 | return string.split('') 10 | } 11 | 12 | export default asciiToArray 13 | -------------------------------------------------------------------------------- /.internal/getHolder.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the argument placeholder value for `func`. 3 | * 4 | * @private 5 | * @param {Function} func The function to inspect. 6 | * @returns {*} Returns the placeholder value. 7 | */ 8 | function getHolder(func) { 9 | const object = func 10 | return object.placeholder 11 | } 12 | 13 | export default getHolder 14 | -------------------------------------------------------------------------------- /.internal/baseIsNaN.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `isNaN` without support for number objects. 3 | * 4 | * @private 5 | * @param {*} value The value to check. 6 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. 7 | */ 8 | function baseIsNaN(value) { 9 | return value !== value 10 | } 11 | 12 | export default baseIsNaN 13 | -------------------------------------------------------------------------------- /.internal/root.js: -------------------------------------------------------------------------------- 1 | import freeGlobal from './freeGlobal.js' 2 | 3 | /** Detect free variable `self`. */ 4 | const freeSelf = typeof self == 'object' && self !== null && self.Object === Object && self 5 | 6 | /** Used as a reference to the global object. */ 7 | const root = freeGlobal || freeSelf || Function('return this')() 8 | 9 | export default root 10 | -------------------------------------------------------------------------------- /.internal/baseProperty.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `property` without support for deep paths. 3 | * 4 | * @private 5 | * @param {string} key The key of the property to get. 6 | * @returns {Function} Returns the new accessor function. 7 | */ 8 | function baseProperty(key) { 9 | return (object) => object == null ? undefined : object[key] 10 | } 11 | 12 | export default baseProperty 13 | -------------------------------------------------------------------------------- /.internal/basePropertyOf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `propertyOf` without support for deep paths. 3 | * 4 | * @private 5 | * @param {Object} object The object to query. 6 | * @returns {Function} Returns the new accessor function. 7 | */ 8 | function basePropertyOf(object) { 9 | return (key) => object == null ? undefined : object[key] 10 | } 11 | 12 | export default basePropertyOf 13 | -------------------------------------------------------------------------------- /.internal/cacheHas.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if a `cache` value for `key` exists. 3 | * 4 | * @private 5 | * @param {Object} cache The cache to query. 6 | * @param {string} key The key of the entry to check. 7 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. 8 | */ 9 | function cacheHas(cache, key) { 10 | return cache.has(key) 11 | } 12 | 13 | export default cacheHas 14 | -------------------------------------------------------------------------------- /.internal/addSetEntry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Adds `value` to `set`. 3 | * 4 | * @private 5 | * @param {Object} set The set to modify. 6 | * @param {*} value The value to add. 7 | * @returns {Object} Returns `set`. 8 | */ 9 | function addSetEntry(set, value) { 10 | // Don't return `set.add` because it's not chainable in IE 11. 11 | set.add(value) 12 | return set 13 | } 14 | 15 | export default addSetEntry 16 | -------------------------------------------------------------------------------- /.internal/setToArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts `set` to an array of its values. 3 | * 4 | * @private 5 | * @param {Object} set The set to convert. 6 | * @returns {Array} Returns the values. 7 | */ 8 | function setToArray(set) { 9 | let index = -1 10 | const result = new Array(set.size) 11 | 12 | set.forEach((value) => { 13 | result[++index] = value 14 | }) 15 | return result 16 | } 17 | 18 | export default setToArray 19 | -------------------------------------------------------------------------------- /isNull.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is `null`. 3 | * 4 | * @since 0.1.0 5 | * @category Lang 6 | * @param {*} value The value to check. 7 | * @returns {boolean} Returns `true` if `value` is `null`, else `false`. 8 | * @example 9 | * 10 | * isNull(null) 11 | * // => true 12 | * 13 | * isNull(void 0) 14 | * // => false 15 | */ 16 | function isNull(value) { 17 | return value === null 18 | } 19 | 20 | export default isNull 21 | -------------------------------------------------------------------------------- /mean.js: -------------------------------------------------------------------------------- 1 | import baseMean from './meanBy.js' 2 | 3 | /** 4 | * Computes the mean of the values in `array`. 5 | * 6 | * @since 4.0.0 7 | * @category Math 8 | * @param {Array} array The array to iterate over. 9 | * @returns {number} Returns the mean. 10 | * @example 11 | * 12 | * mean([4, 2, 8, 6]) 13 | * // => 5 14 | */ 15 | function mean(array) { 16 | return baseMean(array, (value) => value) 17 | } 18 | 19 | export default mean 20 | -------------------------------------------------------------------------------- /.internal/addMapEntry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Adds the key-value `pair` to `map`. 3 | * 4 | * @private 5 | * @param {Object} map The map to modify. 6 | * @param {Array} pair The key-value pair to add. 7 | * @returns {Object} Returns `map`. 8 | */ 9 | function addMapEntry(map, pair) { 10 | // Don't return `map.set` because it's not chainable in IE 11. 11 | map.set(pair[0], pair[1]) 12 | return map 13 | } 14 | 15 | export default addMapEntry 16 | -------------------------------------------------------------------------------- /.internal/basePropertyDeep.js: -------------------------------------------------------------------------------- 1 | import baseGet from './baseGet.js' 2 | 3 | /** 4 | * A specialized version of `baseProperty` which supports deep paths. 5 | * 6 | * @private 7 | * @param {Array|string} path The path of the property to get. 8 | * @returns {Function} Returns the new accessor function. 9 | */ 10 | function basePropertyDeep(path) { 11 | return (object) => baseGet(object, path) 12 | } 13 | 14 | export default basePropertyDeep 15 | -------------------------------------------------------------------------------- /last.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the last element of `array`. 3 | * 4 | * @since 0.1.0 5 | * @category Array 6 | * @param {Array} array The array to query. 7 | * @returns {*} Returns the last element of `array`. 8 | * @example 9 | * 10 | * last([1, 2, 3]) 11 | * // => 3 12 | */ 13 | function last(array) { 14 | const length = array == null ? 0 : array.length 15 | return length ? array[length - 1] : undefined 16 | } 17 | 18 | export default last 19 | -------------------------------------------------------------------------------- /.internal/mapToArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts `map` to its key-value pairs. 3 | * 4 | * @private 5 | * @param {Object} map The map to convert. 6 | * @returns {Array} Returns the key-value pairs. 7 | */ 8 | function mapToArray(map) { 9 | let index = -1 10 | const result = new Array(map.size) 11 | 12 | map.forEach((value, key) => { 13 | result[++index] = [key, value] 14 | }) 15 | return result 16 | } 17 | 18 | export default mapToArray 19 | -------------------------------------------------------------------------------- /.internal/setToPairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts `set` to its value-value pairs. 3 | * 4 | * @private 5 | * @param {Object} set The set to convert. 6 | * @returns {Array} Returns the value-value pairs. 7 | */ 8 | function setToPairs(set) { 9 | let index = -1 10 | const result = new Array(set.size) 11 | 12 | set.forEach((value) => { 13 | result[++index] = [value, value] 14 | }) 15 | return result 16 | } 17 | 18 | export default setToPairs 19 | -------------------------------------------------------------------------------- /.internal/iteratorToArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts `iterator` to an array. 3 | * 4 | * @private 5 | * @param {Object} iterator The iterator to convert. 6 | * @returns {Array} Returns the converted array. 7 | */ 8 | function iteratorToArray(iterator) { 9 | let data 10 | const result = [] 11 | 12 | while (!(data = iterator.next()).done) { 13 | result.push(data.value) 14 | } 15 | return result 16 | } 17 | 18 | export default iteratorToArray 19 | -------------------------------------------------------------------------------- /.internal/castArrayLikeObject.js: -------------------------------------------------------------------------------- 1 | import isArrayLikeObject from '../isArrayLikeObject.js' 2 | 3 | /** 4 | * Casts `value` to an empty array if it's not an array like object. 5 | * 6 | * @private 7 | * @param {*} value The value to inspect. 8 | * @returns {Array|Object} Returns the cast array-like object. 9 | */ 10 | function castArrayLikeObject(value) { 11 | return isArrayLikeObject(value) ? value : [] 12 | } 13 | 14 | export default castArrayLikeObject 15 | -------------------------------------------------------------------------------- /isUndefined.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is `undefined`. 3 | * 4 | * @since 0.1.0 5 | * @category Lang 6 | * @param {*} value The value to check. 7 | * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. 8 | * @example 9 | * 10 | * isUndefined(void 0) 11 | * // => true 12 | * 13 | * isUndefined(null) 14 | * // => false 15 | */ 16 | function isUndefined(value) { 17 | return value === undefined 18 | } 19 | 20 | export default isUndefined 21 | -------------------------------------------------------------------------------- /sample.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets a random element from `array`. 3 | * 4 | * @since 2.0.0 5 | * @category Array 6 | * @param {Array} array The array to sample. 7 | * @returns {*} Returns the random element. 8 | * @example 9 | * 10 | * sample([1, 2, 3, 4]) 11 | * // => 2 12 | */ 13 | function sample(array) { 14 | const length = array == null ? 0 : array.length 15 | return length ? array[Math.floor(Math.random() * length)] : undefined 16 | } 17 | 18 | export default sample 19 | -------------------------------------------------------------------------------- /.internal/cloneArrayBuffer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a clone of `arrayBuffer`. 3 | * 4 | * @private 5 | * @param {ArrayBuffer} arrayBuffer The array buffer to clone. 6 | * @returns {ArrayBuffer} Returns the cloned array buffer. 7 | */ 8 | function cloneArrayBuffer(arrayBuffer) { 9 | const result = new arrayBuffer.constructor(arrayBuffer.byteLength) 10 | new Uint8Array(result).set(new Uint8Array(arrayBuffer)) 11 | return result 12 | } 13 | 14 | export default cloneArrayBuffer 15 | -------------------------------------------------------------------------------- /.internal/cloneSymbol.js: -------------------------------------------------------------------------------- 1 | /** Used to convert symbols to primitives and strings. */ 2 | const symbolValueOf = Symbol.prototype.valueOf 3 | 4 | /** 5 | * Creates a clone of the `symbol` object. 6 | * 7 | * @private 8 | * @param {Object} symbol The symbol object to clone. 9 | * @returns {Object} Returns the cloned symbol object. 10 | */ 11 | function cloneSymbol(symbol) { 12 | return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {} 13 | } 14 | 15 | export default cloneSymbol 16 | -------------------------------------------------------------------------------- /.internal/baseForOwn.js: -------------------------------------------------------------------------------- 1 | import baseFor from './baseFor.js' 2 | import keys from '../keys.js' 3 | 4 | /** 5 | * The base implementation of `forOwn`. 6 | * 7 | * @private 8 | * @param {Object} object The object to iterate over. 9 | * @param {Function} iteratee The function invoked per iteration. 10 | * @returns {Object} Returns `object`. 11 | */ 12 | function baseForOwn(object, iteratee) { 13 | return object && baseFor(object, iteratee, keys) 14 | } 15 | 16 | export default baseForOwn 17 | -------------------------------------------------------------------------------- /.internal/initCloneObject.js: -------------------------------------------------------------------------------- 1 | import isPrototype from './isPrototype.js' 2 | 3 | /** 4 | * Initializes an object clone. 5 | * 6 | * @private 7 | * @param {Object} object The object to clone. 8 | * @returns {Object} Returns the initialized clone. 9 | */ 10 | function initCloneObject(object) { 11 | return (typeof object.constructor == 'function' && !isPrototype(object)) 12 | ? Object.create(Object.getPrototypeOf(object)) 13 | : {} 14 | } 15 | 16 | export default initCloneObject 17 | -------------------------------------------------------------------------------- /isNil.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is `null` or `undefined`. 3 | * 4 | * @since 4.0.0 5 | * @category Lang 6 | * @param {*} value The value to check. 7 | * @returns {boolean} Returns `true` if `value` is nullish, else `false`. 8 | * @example 9 | * 10 | * isNil(null) 11 | * // => true 12 | * 13 | * isNil(void 0) 14 | * // => true 15 | * 16 | * isNil(NaN) 17 | * // => false 18 | */ 19 | function isNil(value) { 20 | return value == null 21 | } 22 | 23 | export default isNil 24 | -------------------------------------------------------------------------------- /.internal/isStrictComparable.js: -------------------------------------------------------------------------------- 1 | import isObject from '../isObject.js' 2 | 3 | /** 4 | * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. 5 | * 6 | * @private 7 | * @param {*} value The value to check. 8 | * @returns {boolean} Returns `true` if `value` if suitable for strict 9 | * equality comparisons, else `false`. 10 | */ 11 | function isStrictComparable(value) { 12 | return value === value && !isObject(value) 13 | } 14 | 15 | export default isStrictComparable 16 | -------------------------------------------------------------------------------- /.internal/parent.js: -------------------------------------------------------------------------------- 1 | import baseGet from './baseGet.js' 2 | import slice from '../slice.js' 3 | 4 | /** 5 | * Gets the parent value at `path` of `object`. 6 | * 7 | * @private 8 | * @param {Object} object The object to query. 9 | * @param {Array} path The path to get the parent value of. 10 | * @returns {*} Returns the parent value. 11 | */ 12 | function parent(object, path) { 13 | return path.length < 2 ? object : baseGet(object, slice(path, 0, -1)) 14 | } 15 | 16 | export default parent 17 | -------------------------------------------------------------------------------- /.internal/stringSize.js: -------------------------------------------------------------------------------- 1 | import asciiSize from './asciiSize.js' 2 | import hasUnicode from './hasUnicode.js' 3 | import unicodeSize from './unicodeSize.js' 4 | 5 | /** 6 | * Gets the number of symbols in `string`. 7 | * 8 | * @private 9 | * @param {string} string The string to inspect. 10 | * @returns {number} Returns the string size. 11 | */ 12 | function stringSize(string) { 13 | return hasUnicode(string) ? unicodeSize(string) : asciiSize(string) 14 | } 15 | 16 | export default stringSize 17 | -------------------------------------------------------------------------------- /sum.js: -------------------------------------------------------------------------------- 1 | import baseSum from './.internal/baseSum.js' 2 | 3 | /** 4 | * Computes the sum of the values in `array`. 5 | * 6 | * @since 3.4.0 7 | * @category Math 8 | * @param {Array} array The array to iterate over. 9 | * @returns {number} Returns the sum. 10 | * @example 11 | * 12 | * sum([4, 2, 8, 6]) 13 | * // => 20 14 | */ 15 | function sum(array) { 16 | return (array != null && array.length) 17 | ? baseSum(array, (value) => value) 18 | : 0 19 | } 20 | 21 | export default sum 22 | -------------------------------------------------------------------------------- /add.js: -------------------------------------------------------------------------------- 1 | import createMathOperation from './.internal/createMathOperation.js' 2 | 3 | /** 4 | * Adds two numbers. 5 | * 6 | * @since 3.4.0 7 | * @category Math 8 | * @param {number} augend The first number in an addition. 9 | * @param {number} addend The second number in an addition. 10 | * @returns {number} Returns the total. 11 | * @example 12 | * 13 | * add(6, 4) 14 | * // => 10 15 | */ 16 | const add = createMathOperation((augend, addend) => augend + addend, 0) 17 | 18 | export default add 19 | -------------------------------------------------------------------------------- /initial.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Gets all but the last element of `array`. 5 | * 6 | * @since 0.1.0 7 | * @category Array 8 | * @param {Array} array The array to query. 9 | * @returns {Array} Returns the slice of `array`. 10 | * @example 11 | * 12 | * initial([1, 2, 3]) 13 | * // => [1, 2] 14 | */ 15 | function initial(array) { 16 | const length = array == null ? 0 : array.length 17 | return length ? slice(array, 0, -1) : [] 18 | } 19 | 20 | export default initial 21 | -------------------------------------------------------------------------------- /.internal/createSet.js: -------------------------------------------------------------------------------- 1 | import setToArray from './setToArray.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const INFINITY = 1 / 0 5 | 6 | /** 7 | * Creates a set object of `values`. 8 | * 9 | * @private 10 | * @param {Array} values The values to add to the set. 11 | * @returns {Object} Returns the new set. 12 | */ 13 | const createSet = (Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) 14 | ? (values) => new Set(values) 15 | : () => {} 16 | 17 | export default createSet 18 | -------------------------------------------------------------------------------- /head.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets the first element of `array`. 3 | * 4 | * @since 0.1.0 5 | * @alias first 6 | * @category Array 7 | * @param {Array} array The array to query. 8 | * @returns {*} Returns the first element of `array`. 9 | * @see last 10 | * @example 11 | * 12 | * head([1, 2, 3]) 13 | * // => 1 14 | * 15 | * head([]) 16 | * // => undefined 17 | */ 18 | function head(array) { 19 | return (array != null && array.length) 20 | ? array[0] 21 | : undefined 22 | } 23 | 24 | export default head 25 | -------------------------------------------------------------------------------- /tail.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets all but the first element of `array`. 3 | * 4 | * @since 4.0.0 5 | * @category Array 6 | * @param {Array} array The array to query. 7 | * @returns {Array} Returns the slice of `array`. 8 | * @example 9 | * 10 | * tail([1, 2, 3]) 11 | * // => [2, 3] 12 | */ 13 | function tail(array) { 14 | const length = array == null ? 0 : array.length 15 | if (!length) { 16 | return [] 17 | } 18 | const [head, ...result] = array 19 | return result 20 | } 21 | 22 | export default tail 23 | -------------------------------------------------------------------------------- /.internal/copySymbols.js: -------------------------------------------------------------------------------- 1 | import copyObject from './copyObject.js' 2 | import getSymbols from './getSymbols.js' 3 | 4 | /** 5 | * Copies own symbols of `source` to `object`. 6 | * 7 | * @private 8 | * @param {Object} source The object to copy symbols from. 9 | * @param {Object} [object={}] The object to copy symbols to. 10 | * @returns {Object} Returns `object`. 11 | */ 12 | function copySymbols(source, object) { 13 | return copyObject(source, getSymbols(source), object) 14 | } 15 | 16 | export default copySymbols 17 | -------------------------------------------------------------------------------- /.internal/baseForOwnRight.js: -------------------------------------------------------------------------------- 1 | import baseForRight from './baseForRight.js' 2 | import keys from '../keys.js' 3 | 4 | /** 5 | * The base implementation of `forOwnRight`. 6 | * 7 | * @private 8 | * @param {Object} object The object to iterate over. 9 | * @param {Function} iteratee The function invoked per iteration. 10 | * @returns {Object} Returns `object`. 11 | */ 12 | function baseForOwnRight(object, iteratee) { 13 | return object && baseForRight(object, iteratee, keys) 14 | } 15 | 16 | export default baseForOwnRight 17 | -------------------------------------------------------------------------------- /.internal/cloneRegExp.js: -------------------------------------------------------------------------------- 1 | /** Used to match `RegExp` flags from their coerced string values. */ 2 | const reFlags = /\w*$/ 3 | 4 | /** 5 | * Creates a clone of `regexp`. 6 | * 7 | * @private 8 | * @param {Object} regexp The regexp to clone. 9 | * @returns {Object} Returns the cloned regexp. 10 | */ 11 | function cloneRegExp(regexp) { 12 | const result = new regexp.constructor(regexp.source, reFlags.exec(regexp)) 13 | result.lastIndex = regexp.lastIndex 14 | return result 15 | } 16 | 17 | export default cloneRegExp 18 | -------------------------------------------------------------------------------- /divide.js: -------------------------------------------------------------------------------- 1 | import createMathOperation from './.internal/createMathOperation.js' 2 | 3 | /** 4 | * Divide two numbers. 5 | * 6 | * @since 4.7.0 7 | * @category Math 8 | * @param {number} dividend The first number in a division. 9 | * @param {number} divisor The second number in a division. 10 | * @returns {number} Returns the quotient. 11 | * @example 12 | * 13 | * divide(6, 4) 14 | * // => 1.5 15 | */ 16 | const divide = createMathOperation((dividend, divisor) => dividend / divisor, 1) 17 | 18 | export default divide 19 | -------------------------------------------------------------------------------- /.internal/baseInRange.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `inRange` which doesn't coerce arguments. 3 | * 4 | * @private 5 | * @param {number} number The number to check. 6 | * @param {number} start The start of the range. 7 | * @param {number} end The end of the range. 8 | * @returns {boolean} Returns `true` if `number` is in the range, else `false`. 9 | */ 10 | function baseInRange(number, start, end) { 11 | return number >= Math.min(start, end) && number < Math.max(start, end) 12 | } 13 | 14 | export default baseInRange 15 | -------------------------------------------------------------------------------- /.internal/stringToArray.js: -------------------------------------------------------------------------------- 1 | import asciiToArray from './asciiToArray.js' 2 | import hasUnicode from './hasUnicode.js' 3 | import unicodeToArray from './unicodeToArray.js' 4 | 5 | /** 6 | * Converts `string` to an array. 7 | * 8 | * @private 9 | * @param {string} string The string to convert. 10 | * @returns {Array} Returns the converted array. 11 | */ 12 | function stringToArray(string) { 13 | return hasUnicode(string) 14 | ? unicodeToArray(string) 15 | : asciiToArray(string) 16 | } 17 | 18 | export default stringToArray 19 | -------------------------------------------------------------------------------- /lowerFirst.js: -------------------------------------------------------------------------------- 1 | import createCaseFirst from './.internal/createCaseFirst.js' 2 | 3 | /** 4 | * Converts the first character of `string` to lower case. 5 | * 6 | * @since 4.0.0 7 | * @category String 8 | * @param {string} [string=''] The string to convert. 9 | * @returns {string} Returns the converted string. 10 | * @example 11 | * 12 | * lowerFirst('Fred') 13 | * // => 'fred' 14 | * 15 | * lowerFirst('FRED') 16 | * // => 'fRED' 17 | */ 18 | const lowerFirst = createCaseFirst('toLowerCase') 19 | 20 | export default lowerFirst 21 | -------------------------------------------------------------------------------- /.internal/baseConforms.js: -------------------------------------------------------------------------------- 1 | import baseConformsTo from './baseConformsTo.js' 2 | import keys from '../keys.js' 3 | 4 | /** 5 | * The base implementation of `conforms` which doesn't clone `source`. 6 | * 7 | * @private 8 | * @param {Object} source The object of property predicates to conform to. 9 | * @returns {Function} Returns the new spec function. 10 | */ 11 | function baseConforms(source) { 12 | const props = keys(source) 13 | return (object) => baseConformsTo(object, source, props) 14 | } 15 | 16 | export default baseConforms 17 | -------------------------------------------------------------------------------- /.internal/setToString.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sets the `toString` method of `func` to return `string`. 3 | * 4 | * @private 5 | * @param {Function} func The function to modify. 6 | * @param {Function} string The `toString` result. 7 | * @returns {Function} Returns `func`. 8 | */ 9 | function setToString(func, string) { 10 | return Object.defineProperty(func, 'toString', { 11 | 'configurable': true, 12 | 'enumerable': false, 13 | 'value': () => string, 14 | 'writable': true 15 | }) 16 | } 17 | 18 | export default setToString 19 | -------------------------------------------------------------------------------- /capitalize.js: -------------------------------------------------------------------------------- 1 | import upperFirst from './upperFirst.js' 2 | 3 | /** 4 | * Converts the first character of `string` to upper case and the remaining 5 | * to lower case. 6 | * 7 | * @since 3.0.0 8 | * @category String 9 | * @param {string} [string=''] The string to capitalize. 10 | * @returns {string} Returns the capitalized string. 11 | * @example 12 | * 13 | * capitalize('FRED') 14 | * // => 'Fred' 15 | */ 16 | function capitalize(string) { 17 | return upperFirst(string.toLowerCase()) 18 | } 19 | 20 | export default capitalize 21 | -------------------------------------------------------------------------------- /.internal/copySymbolsIn.js: -------------------------------------------------------------------------------- 1 | import copyObject from './copyObject.js' 2 | import getSymbolsIn from './getSymbolsIn.js' 3 | 4 | /** 5 | * Copies own and inherited symbols of `source` to `object`. 6 | * 7 | * @private 8 | * @param {Object} source The object to copy symbols from. 9 | * @param {Object} [object={}] The object to copy symbols to. 10 | * @returns {Object} Returns `object`. 11 | */ 12 | function copySymbolsIn(source, object) { 13 | return copyObject(source, getSymbolsIn(source), object) 14 | } 15 | 16 | export default copySymbolsIn 17 | -------------------------------------------------------------------------------- /subtract.js: -------------------------------------------------------------------------------- 1 | import createMathOperation from './.internal/createMathOperation.js' 2 | 3 | /** 4 | * Subtract two numbers. 5 | * 6 | * @since 4.0.0 7 | * @category Math 8 | * @param {number} minuend The first number in a subtraction. 9 | * @param {number} subtrahend The second number in a subtraction. 10 | * @returns {number} Returns the difference. 11 | * @example 12 | * 13 | * subtract(6, 4) 14 | * // => 2 15 | */ 16 | const subtract = createMathOperation((minuend, subtrahend) => minuend - subtrahend, 0) 17 | 18 | export default subtract 19 | -------------------------------------------------------------------------------- /.internal/basePick.js: -------------------------------------------------------------------------------- 1 | import basePickBy from './basePickBy.js' 2 | import hasIn from '../hasIn.js' 3 | 4 | /** 5 | * The base implementation of `pick` without support for individual 6 | * property identifiers. 7 | * 8 | * @private 9 | * @param {Object} object The source object. 10 | * @param {string[]} paths The property paths to pick. 11 | * @returns {Object} Returns the new object. 12 | */ 13 | function basePick(object, paths) { 14 | return basePickBy(object, paths, (value, path) => hasIn(object, path)) 15 | } 16 | 17 | export default basePick 18 | -------------------------------------------------------------------------------- /.internal/baseValues.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `values` and `valuesIn` which creates an 3 | * array of `object` property values corresponding to the property names 4 | * of `props`. 5 | * 6 | * @private 7 | * @param {Object} object The object to query. 8 | * @param {Array} props The property names to get values for. 9 | * @returns {Object} Returns the array of property values. 10 | */ 11 | function baseValues(object, props) { 12 | return props == null ? [] : props.map((key) => object[key]) 13 | } 14 | 15 | export default baseValues 16 | -------------------------------------------------------------------------------- /.internal/copyArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copies the values of `source` to `array`. 3 | * 4 | * @private 5 | * @param {Array} source The array to copy values from. 6 | * @param {Array} [array=[]] The array to copy values to. 7 | * @returns {Array} Returns `array`. 8 | */ 9 | function copyArray(source, array) { 10 | let index = -1 11 | const length = source.length 12 | 13 | array || (array = new Array(length)) 14 | while (++index < length) { 15 | array[index] = source[index] 16 | } 17 | return array 18 | } 19 | 20 | export default copyArray 21 | -------------------------------------------------------------------------------- /.internal/getAllKeys.js: -------------------------------------------------------------------------------- 1 | import getSymbols from './getSymbols.js' 2 | import keys from '../keys.js' 3 | 4 | /** 5 | * Creates an array of own enumerable property names and symbols of `object`. 6 | * 7 | * @private 8 | * @param {Object} object The object to query. 9 | * @returns {Array} Returns the array of property names and symbols. 10 | */ 11 | function getAllKeys(object) { 12 | const result = keys(object) 13 | if (!Array.isArray(object)) { 14 | result.push(...getSymbols(object)) 15 | } 16 | return result 17 | } 18 | 19 | export default getAllKeys 20 | -------------------------------------------------------------------------------- /multiply.js: -------------------------------------------------------------------------------- 1 | import createMathOperation from './.internal/createMathOperation.js' 2 | 3 | /** 4 | * Multiply two numbers. 5 | * 6 | * @since 4.7.0 7 | * @category Math 8 | * @param {number} multiplier The first number in a multiplication. 9 | * @param {number} multiplicand The second number in a multiplication. 10 | * @returns {number} Returns the product. 11 | * @example 12 | * 13 | * multiply(6, 4) 14 | * // => 24 15 | */ 16 | const multiply = createMathOperation((multiplier, multiplicand) => multiplier * multiplicand, 1) 17 | 18 | export default multiply 19 | -------------------------------------------------------------------------------- /.internal/isPrototype.js: -------------------------------------------------------------------------------- 1 | /** Used for built-in method references. */ 2 | const objectProto = Object.prototype 3 | 4 | /** 5 | * Checks if `value` is likely a prototype object. 6 | * 7 | * @private 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. 10 | */ 11 | function isPrototype(value) { 12 | const Ctor = value && value.constructor 13 | const proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto 14 | 15 | return value === proto 16 | } 17 | 18 | export default isPrototype 19 | -------------------------------------------------------------------------------- /.internal/castPath.js: -------------------------------------------------------------------------------- 1 | import isKey from './isKey.js' 2 | import stringToPath from './stringToPath.js' 3 | 4 | /** 5 | * Casts `value` to a path array if it's not one. 6 | * 7 | * @private 8 | * @param {*} value The value to inspect. 9 | * @param {Object} [object] The object to query keys on. 10 | * @returns {Array} Returns the cast property path array. 11 | */ 12 | function castPath(value, object) { 13 | if (Array.isArray(value)) { 14 | return value 15 | } 16 | return isKey(value, object) ? [value] : stringToPath(value) 17 | } 18 | 19 | export default castPath 20 | -------------------------------------------------------------------------------- /round.js: -------------------------------------------------------------------------------- 1 | import createRound from './.internal/createRound.js' 2 | 3 | /** 4 | * Computes `number` rounded to `precision`. 5 | * 6 | * @since 3.10.0 7 | * @category Math 8 | * @param {number} number The number to round. 9 | * @param {number} [precision=0] The precision to round to. 10 | * @returns {number} Returns the rounded number. 11 | * @example 12 | * 13 | * round(4.006) 14 | * // => 4 15 | * 16 | * round(4.006, 2) 17 | * // => 4.01 18 | * 19 | * round(4060, -2) 20 | * // => 4100 21 | */ 22 | const round = createRound('round') 23 | 24 | export default round 25 | -------------------------------------------------------------------------------- /.internal/arrayEachRight.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `forEachRight` for arrays. 3 | * 4 | * @private 5 | * @param {Array} [array] The array to iterate over. 6 | * @param {Function} iteratee The function invoked per iteration. 7 | * @returns {Array} Returns `array`. 8 | */ 9 | function arrayEachRight(array, iteratee) { 10 | let length = array == null ? 0 : array.length 11 | 12 | while (length--) { 13 | if (iteratee(array[length], length, array) === false) { 14 | break 15 | } 16 | } 17 | return array 18 | } 19 | 20 | export default arrayEachRight 21 | -------------------------------------------------------------------------------- /ceil.js: -------------------------------------------------------------------------------- 1 | import createRound from './.internal/createRound.js' 2 | 3 | /** 4 | * Computes `number` rounded up to `precision`. 5 | * 6 | * @since 3.10.0 7 | * @category Math 8 | * @param {number} number The number to round up. 9 | * @param {number} [precision=0] The precision to round up to. 10 | * @returns {number} Returns the rounded up number. 11 | * @example 12 | * 13 | * ceil(4.006) 14 | * // => 5 15 | * 16 | * ceil(6.004, 2) 17 | * // => 6.01 18 | * 19 | * ceil(6040, -2) 20 | * // => 6100 21 | */ 22 | const ceil = createRound('ceil') 23 | 24 | export default ceil 25 | -------------------------------------------------------------------------------- /shuffle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an array of shuffled values 3 | * @since 0.1.0 4 | * @category Array 5 | * @param {Array} array The array to shuffle. 6 | * @returns {Array} Returns the new shuffled array. 7 | * @example 8 | * 9 | * shuffle([1, 2, 3, 4]) 10 | * // => [4, 1, 3, 2] 11 | */ 12 | function shuffle(array) { 13 | for (let i = array.length - 1; i > 0; i--) { 14 | const j = Math.floor(Math.random() * (i + 1)); 15 | const temp = array[i]; 16 | array[i] = array[j]; 17 | array[j] = temp; 18 | } 19 | return array; 20 | } 21 | 22 | export default shuffle 23 | -------------------------------------------------------------------------------- /.internal/assocIndexOf.js: -------------------------------------------------------------------------------- 1 | import eq from '../eq.js' 2 | 3 | /** 4 | * Gets the index at which the `key` is found in `array` of key-value pairs. 5 | * 6 | * @private 7 | * @param {Array} array The array to inspect. 8 | * @param {*} key The key to search for. 9 | * @returns {number} Returns the index of the matched value, else `-1`. 10 | */ 11 | function assocIndexOf(array, key) { 12 | let { length } = array 13 | while (length--) { 14 | if (eq(array[length][0], key)) { 15 | return length 16 | } 17 | } 18 | return -1 19 | } 20 | 21 | export default assocIndexOf 22 | -------------------------------------------------------------------------------- /.internal/castSlice.js: -------------------------------------------------------------------------------- 1 | import slice from '../slice.js' 2 | 3 | /** 4 | * Casts `array` to a slice if it's needed. 5 | * 6 | * @private 7 | * @param {Array} array The array to inspect. 8 | * @param {number} start The start position. 9 | * @param {number} [end=array.length] The end position. 10 | * @returns {Array} Returns the cast slice. 11 | */ 12 | function castSlice(array, start, end) { 13 | const { length } = array 14 | end = end === undefined ? length : end 15 | return (!start && end >= length) ? array : slice(array, start, end) 16 | } 17 | 18 | export default castSlice 19 | -------------------------------------------------------------------------------- /.internal/cloneDataView.js: -------------------------------------------------------------------------------- 1 | import cloneArrayBuffer from './cloneArrayBuffer.js' 2 | 3 | /** 4 | * Creates a clone of `dataView`. 5 | * 6 | * @private 7 | * @param {Object} dataView The data view to clone. 8 | * @param {boolean} [isDeep] Specify a deep clone. 9 | * @returns {Object} Returns the cloned data view. 10 | */ 11 | function cloneDataView(dataView, isDeep) { 12 | const buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer 13 | return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength) 14 | } 15 | 16 | export default cloneDataView 17 | -------------------------------------------------------------------------------- /.internal/arrayEach.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `forEach` for arrays. 3 | * 4 | * @private 5 | * @param {Array} [array] The array to iterate over. 6 | * @param {Function} iteratee The function invoked per iteration. 7 | * @returns {Array} Returns `array`. 8 | */ 9 | function arrayEach(array, iteratee) { 10 | let index = -1 11 | const length = array == null ? 0 : array.length 12 | 13 | while (++index < length) { 14 | if (iteratee(array[index], index, array) === false) { 15 | break 16 | } 17 | } 18 | return array 19 | } 20 | 21 | export default arrayEach 22 | -------------------------------------------------------------------------------- /.internal/baseSum.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `sum` and `sumBy`. 3 | * 4 | * @private 5 | * @param {Array} array The array to iterate over. 6 | * @param {Function} iteratee The function invoked per iteration. 7 | * @returns {number} Returns the sum. 8 | */ 9 | function baseSum(array, iteratee) { 10 | let result 11 | 12 | for (const value of array) { 13 | const current = iteratee(value) 14 | if (current !== undefined) { 15 | result = result === undefined ? current : (result + current) 16 | } 17 | } 18 | return result 19 | } 20 | 21 | export default baseSum 22 | -------------------------------------------------------------------------------- /floor.js: -------------------------------------------------------------------------------- 1 | import createRound from './.internal/createRound.js' 2 | 3 | /** 4 | * Computes `number` rounded down to `precision`. 5 | * 6 | * @since 3.10.0 7 | * @category Math 8 | * @param {number} number The number to round down. 9 | * @param {number} [precision=0] The precision to round down to. 10 | * @returns {number} Returns the rounded down number. 11 | * @example 12 | * 13 | * floor(4.006) 14 | * // => 4 15 | * 16 | * floor(0.046, 2) 17 | * // => 0.04 18 | * 19 | * floor(4060, -2) 20 | * // => 4000 21 | */ 22 | const floor = createRound('floor') 23 | 24 | export default floor 25 | -------------------------------------------------------------------------------- /.internal/arrayIncludes.js: -------------------------------------------------------------------------------- 1 | import baseIndexOf from './baseIndexOf.js' 2 | 3 | /** 4 | * A specialized version of `includes` for arrays without support for 5 | * specifying an index to search from. 6 | * 7 | * @private 8 | * @param {Array} [array] The array to inspect. 9 | * @param {*} target The value to search for. 10 | * @returns {boolean} Returns `true` if `target` is found, else `false`. 11 | */ 12 | function arrayIncludes(array, value) { 13 | const length = array == null ? 0 : array.length 14 | return !!length && baseIndexOf(array, value, 0) > -1 15 | } 16 | 17 | export default arrayIncludes 18 | -------------------------------------------------------------------------------- /.internal/cloneTypedArray.js: -------------------------------------------------------------------------------- 1 | import cloneArrayBuffer from './cloneArrayBuffer.js' 2 | 3 | /** 4 | * Creates a clone of `typedArray`. 5 | * 6 | * @private 7 | * @param {Object} typedArray The typed array to clone. 8 | * @param {boolean} [isDeep] Specify a deep clone. 9 | * @returns {Object} Returns the cloned typed array. 10 | */ 11 | function cloneTypedArray(typedArray, isDeep) { 12 | const buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer 13 | return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length) 14 | } 15 | 16 | export default cloneTypedArray 17 | -------------------------------------------------------------------------------- /isWeakMap.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | 3 | /** 4 | * Checks if `value` is classified as a `WeakMap` object. 5 | * 6 | * @since 4.3.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. 10 | * @example 11 | * 12 | * isWeakMap(new WeakMap) 13 | * // => true 14 | * 15 | * isWeakMap(new Map) 16 | * // => false 17 | */ 18 | function isWeakMap(value) { 19 | return typeof value == 'object' && value !== null && getTag(value) == '[object WeakMap]' 20 | } 21 | 22 | export default isWeakMap 23 | -------------------------------------------------------------------------------- /isWeakSet.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | 3 | /** 4 | * Checks if `value` is classified as a `WeakSet` object. 5 | * 6 | * @since 4.3.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. 10 | * @example 11 | * 12 | * isWeakSet(new WeakSet) 13 | * // => true 14 | * 15 | * isWeakSet(new Set) 16 | * // => false 17 | */ 18 | function isWeakSet(value) { 19 | return typeof value == 'object' && value !== null && getTag(value) == '[object WeakSet]' 20 | } 21 | 22 | export default isWeakSet 23 | -------------------------------------------------------------------------------- /.internal/isFlattenable.js: -------------------------------------------------------------------------------- 1 | import isArguments from '../isArguments.js' 2 | 3 | /** Built-in value reference. */ 4 | const spreadableSymbol = Symbol.isConcatSpreadable 5 | 6 | /** 7 | * Checks if `value` is a flattenable `arguments` object or array. 8 | * 9 | * @private 10 | * @param {*} value The value to check. 11 | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. 12 | */ 13 | function isFlattenable(value) { 14 | return Array.isArray(value) || isArguments(value) || 15 | !!(spreadableSymbol && value && value[spreadableSymbol]) 16 | } 17 | 18 | export default isFlattenable 19 | -------------------------------------------------------------------------------- /at.js: -------------------------------------------------------------------------------- 1 | import baseAt from './.internal/baseAt.js' 2 | 3 | /** 4 | * Creates an array of values corresponding to `paths` of `object`. 5 | * 6 | * @since 1.0.0 7 | * @category Object 8 | * @param {Object} object The object to iterate over. 9 | * @param {...(string|string[])} [paths] The property paths to pick. 10 | * @returns {Array} Returns the picked values. 11 | * @example 12 | * 13 | * const object = { 'a': [{ 'b': { 'c': 3 } }, 4] } 14 | * 15 | * at(object, ['a[0].b.c', 'a[1]']) 16 | * // => [3, 4] 17 | */ 18 | function at(...paths) { 19 | return baseAt(paths) 20 | } 21 | 22 | export default at 23 | -------------------------------------------------------------------------------- /uniqueId.js: -------------------------------------------------------------------------------- 1 | /** Used to generate unique IDs. */ 2 | let idCounter = 0 3 | 4 | /** 5 | * Generates a unique ID. If `prefix` is given, the ID is appended to it. 6 | * 7 | * @since 0.1.0 8 | * @category Util 9 | * @param {string} [prefix=''] The value to prefix the ID with. 10 | * @returns {string} Returns the unique ID. 11 | * @see random 12 | * @example 13 | * 14 | * uniqueId('contact_') 15 | * // => 'contact_104' 16 | * 17 | * uniqueId() 18 | * // => '105' 19 | */ 20 | function uniqueId(prefix='') { 21 | const id = ++idCounter 22 | return `${prefix + id}` 23 | } 24 | 25 | export default uniqueId 26 | -------------------------------------------------------------------------------- /upperFirst.js: -------------------------------------------------------------------------------- 1 | import createCaseFirst from './.internal/createCaseFirst.js' 2 | 3 | /** 4 | * Converts the first character of `string` to upper case. 5 | * 6 | * @since 4.0.0 7 | * @category String 8 | * @param {string} [string=''] The string to convert. 9 | * @returns {string} Returns the converted string. 10 | * @see camelCase, kebabCase, lowerCase, snakeCase, startCase, upperCase 11 | * @example 12 | * 13 | * upperFirst('fred') 14 | * // => 'Fred' 15 | * 16 | * upperFirst('FRED') 17 | * // => 'FRED' 18 | */ 19 | const upperFirst = createCaseFirst('toUpperCase') 20 | 21 | export default upperFirst 22 | -------------------------------------------------------------------------------- /.internal/getAllKeysIn.js: -------------------------------------------------------------------------------- 1 | import getSymbolsIn from './getSymbolsIn.js' 2 | 3 | /** 4 | * Creates an array of own and inherited enumerable property names and symbols of `object`. 5 | * 6 | * @private 7 | * @param {Object} object The object to query. 8 | * @returns {Array} Returns the array of property names and symbols. 9 | */ 10 | function getAllKeysIn(object) { 11 | const result = [] 12 | for (const key in object) { 13 | result.push(key) 14 | } 15 | if (!Array.isArray(object)) { 16 | result.push(...getSymbolsIn(object)) 17 | } 18 | return result 19 | } 20 | 21 | export default getAllKeysIn 22 | -------------------------------------------------------------------------------- /.internal/toKey.js: -------------------------------------------------------------------------------- 1 | import isSymbol from '../isSymbol.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const INFINITY = 1 / 0 5 | 6 | /** 7 | * Converts `value` to a string key if it's not a string or symbol. 8 | * 9 | * @private 10 | * @param {*} value The value to inspect. 11 | * @returns {string|symbol} Returns the key. 12 | */ 13 | function toKey(value) { 14 | if (typeof value == 'string' || isSymbol(value)) { 15 | return value 16 | } 17 | const result = `${value}` 18 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result 19 | } 20 | 21 | export default toKey 22 | -------------------------------------------------------------------------------- /fromPairs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The inverse of `toPairs`is method returns an object composed 3 | * from key-value `pairs`. 4 | * 5 | * @since 4.0.0 6 | * @category Array 7 | * @param {Array} pairs The key-value pairs. 8 | * @returns {Object} Returns the new object. 9 | * @example 10 | * 11 | * fromPairs([['a', 1], ['b', 2]]) 12 | * // => { 'a': 1, 'b': 2 } 13 | */ 14 | function fromPairs(pairs) { 15 | const result = {} 16 | if (pairs == null) { 17 | return result 18 | } 19 | for (const pair of pairs) { 20 | result[pair[0]] = pair[1] 21 | } 22 | return result 23 | } 24 | 25 | export default fromPairs 26 | -------------------------------------------------------------------------------- /flatten.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | 3 | /** 4 | * Flattens `array` a single level deep. 5 | * 6 | * @since 0.1.0 7 | * @category Array 8 | * @param {Array} array The array to flatten. 9 | * @returns {Array} Returns the new flattened array. 10 | * @see flatMap, flatMapDeep, flatMapDepth, flattenDeep, flattenDepth 11 | * @example 12 | * 13 | * flatten([1, [2, [3, [4]], 5]]) 14 | * // => [1, 2, [3, [4]], 5] 15 | */ 16 | function flatten(array) { 17 | const length = array == null ? 0 : array.length 18 | return length ? baseFlatten(array, 1) : [] 19 | } 20 | 21 | export default flatten 22 | -------------------------------------------------------------------------------- /.internal/baseSortBy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `sortBy` which uses `comparer` to define the 3 | * sort order of `array` and replaces criteria objects with their corresponding 4 | * values. 5 | * 6 | * @private 7 | * @param {Array} array The array to sort. 8 | * @param {Function} comparer The function to define sort order. 9 | * @returns {Array} Returns `array`. 10 | */ 11 | function baseSortBy(array, comparer) { 12 | let { length } = array 13 | 14 | array.sort(comparer) 15 | while (length--) { 16 | array[length] = array[length].value 17 | } 18 | return array 19 | } 20 | 21 | export default baseSortBy 22 | -------------------------------------------------------------------------------- /isElement.js: -------------------------------------------------------------------------------- 1 | import isObjectLike from './isObjectLike.js' 2 | import isPlainObject from './isPlainObject.js' 3 | 4 | /** 5 | * Checks if `value` is likely a DOM element. 6 | * 7 | * @since 0.1.0 8 | * @category Lang 9 | * @param {*} value The value to check. 10 | * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. 11 | * @example 12 | * 13 | * isElement(document.body) 14 | * // => true 15 | * 16 | * isElement('') 17 | * // => false 18 | */ 19 | function isElement(value) { 20 | return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value) 21 | } 22 | 23 | export default isElement 24 | -------------------------------------------------------------------------------- /isArguments.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | 3 | /** 4 | * Checks if `value` is likely an `arguments` object. 5 | * 6 | * @since 0.1.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`. 10 | * @example 11 | * 12 | * isArguments(function() { return arguments }()) 13 | * // => true 14 | * 15 | * isArguments([1, 2, 3]) 16 | * // => false 17 | */ 18 | function isArguments(value) { 19 | return typeof value == 'object' && value !== null && getTag(value) == '[object Arguments]' 20 | } 21 | 22 | export default isArguments 23 | -------------------------------------------------------------------------------- /pick.js: -------------------------------------------------------------------------------- 1 | import basePick from './.internal/basePick.js' 2 | 3 | /** 4 | * Creates an object composed of the picked `object` properties. 5 | * 6 | * @since 0.1.0 7 | * @category Object 8 | * @param {Object} object The source object. 9 | * @param {...(string|string[])} [paths] The property paths to pick. 10 | * @returns {Object} Returns the new object. 11 | * @example 12 | * 13 | * const object = { 'a': 1, 'b': '2', 'c': 3 } 14 | * 15 | * pick(object, ['a', 'c']) 16 | * // => { 'a': 1, 'c': 3 } 17 | */ 18 | function pick(object, ...paths) { 19 | return object == null ? {} : basePick(object, paths) 20 | } 21 | 22 | export default pick 23 | -------------------------------------------------------------------------------- /.internal/baseToNumber.js: -------------------------------------------------------------------------------- 1 | import isSymbol from '../isSymbol.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const NAN = 0 / 0 5 | 6 | /** 7 | * The base implementation of `toNumber` which doesn't ensure correct 8 | * conversions of binary, hexadecimal, or octal string values. 9 | * 10 | * @private 11 | * @param {*} value The value to process. 12 | * @returns {number} Returns the number. 13 | */ 14 | function baseToNumber(value) { 15 | if (typeof value == 'number') { 16 | return value 17 | } 18 | if (isSymbol(value)) { 19 | return NAN 20 | } 21 | return +value 22 | } 23 | 24 | export default baseToNumber 25 | -------------------------------------------------------------------------------- /hasIn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `path` is a direct or inherited property of `object`. 3 | * 4 | * @since 4.0.0 5 | * @category Object 6 | * @param {Object} object The object to query. 7 | * @param {string} key The key to check. 8 | * @returns {boolean} Returns `true` if `key` exists, else `false`. 9 | * @see has, hasPath, hasPathIn 10 | * @example 11 | * 12 | * const object = create({ 'a': create({ 'b': 2 }) }) 13 | * 14 | * hasIn(object, 'a') 15 | * // => true 16 | * 17 | * hasIn(object, 'b') 18 | * // => false 19 | */ 20 | function hasIn(object, key) { 21 | return object != null && key in Object(object) 22 | } 23 | 24 | export default hasIn 25 | -------------------------------------------------------------------------------- /isSymbol.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | 3 | /** 4 | * Checks if `value` is classified as a `Symbol` primitive or object. 5 | * 6 | * @since 4.0.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. 10 | * @example 11 | * 12 | * isSymbol(Symbol.iterator) 13 | * // => true 14 | * 15 | * isSymbol('abc') 16 | * // => false 17 | */ 18 | function isSymbol(value) { 19 | const type = typeof value 20 | return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]') 21 | } 22 | 23 | export default isSymbol 24 | -------------------------------------------------------------------------------- /nthArg.js: -------------------------------------------------------------------------------- 1 | import nth from './nth.js' 2 | 3 | /** 4 | * Creates a function that gets the argument at index `n`. If `n` is negative, 5 | * the nth argument from the end is returned. 6 | * 7 | * @since 4.0.0 8 | * @category Util 9 | * @param {number} [n=0] The index of the argument to return. 10 | * @returns {Function} Returns the new pass-thru function. 11 | * @example 12 | * 13 | * const func = nthArg(1) 14 | * func('a', 'b', 'c', 'd') 15 | * // => 'b' 16 | * 17 | * const func = nthArg(-2) 18 | * func('a', 'b', 'c', 'd') 19 | * // => 'c' 20 | */ 21 | function nthArg(n) { 22 | return (...args) => nth(args, n) 23 | } 24 | 25 | export default nthArg 26 | -------------------------------------------------------------------------------- /over.js: -------------------------------------------------------------------------------- 1 | import map from './map.js' 2 | 3 | /** 4 | * Creates a function that invokes `iteratees` with the arguments it receives 5 | * and returns their results. 6 | * 7 | * @since 4.0.0 8 | * @category Util 9 | * @param {Function[]} [iteratees=[identity]] 10 | * The iteratees to invoke. 11 | * @returns {Function} Returns the new function. 12 | * @example 13 | * 14 | * const func = over([Math.max, Math.min]) 15 | * 16 | * func(1, 2, 3, 4) 17 | * // => [4, 1] 18 | */ 19 | function over(iteratees) { 20 | return function(...args) { 21 | return map(iteratees, (iteratee) => iteratee.apply(this, args)) 22 | } 23 | } 24 | 25 | export default over 26 | -------------------------------------------------------------------------------- /.internal/baseUnset.js: -------------------------------------------------------------------------------- 1 | import castPath from './castPath.js' 2 | import last from '../last.js' 3 | import parent from './parent.js' 4 | import toKey from './toKey.js' 5 | 6 | /** 7 | * The base implementation of `unset`. 8 | * 9 | * @private 10 | * @param {Object} object The object to modify. 11 | * @param {Array|string} path The property path to unset. 12 | * @returns {boolean} Returns `true` if the property is deleted, else `false`. 13 | */ 14 | function baseUnset(object, path) { 15 | path = castPath(path, object) 16 | object = parent(object, path) 17 | return object == null || delete object[toKey(last(path))] 18 | } 19 | 20 | export default baseUnset 21 | -------------------------------------------------------------------------------- /isString.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | 3 | /** 4 | * Checks if `value` is classified as a `String` primitive or object. 5 | * 6 | * @since 0.1.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is a string, else `false`. 10 | * @example 11 | * 12 | * isString('abc') 13 | * // => true 14 | * 15 | * isString(1) 16 | * // => false 17 | */ 18 | function isString(value) { 19 | const type = typeof value 20 | return type == 'string' || (type == 'object' && value != null && !Array.isArray(value) && getTag(value) == '[object String]') 21 | } 22 | 23 | export default isString 24 | -------------------------------------------------------------------------------- /flowRight.js: -------------------------------------------------------------------------------- 1 | import flow from './flow.js' 2 | 3 | /** 4 | * This method is like `flow` except that it composes a function that 5 | * invokes the given functions from right to left. 6 | * 7 | * @since 3.0.0 8 | * @category Util 9 | * @param {Function[]} [funcs] The functions to invoke. 10 | * @returns {Function} Returns the new composite function. 11 | * @see flow 12 | * @example 13 | * 14 | * function square(n) { 15 | * return n * n 16 | * } 17 | * 18 | * const addSquare = flowRight([square, add]) 19 | * addSquare(1, 2) 20 | * // => 9 21 | */ 22 | function flowRight(funcs) { 23 | return flow(funcs.reverse()) 24 | } 25 | 26 | export default flowRight 27 | -------------------------------------------------------------------------------- /sortedUniq.js: -------------------------------------------------------------------------------- 1 | import baseSortedUniq from './.internal/baseSortedUniq.js' 2 | 3 | /** 4 | * This method is like `uniq` except that it only works 5 | * for sorted arrays. 6 | * If the input array is known to be sorted `sortedUniq` is 7 | * faster than `uniq`. 8 | * 9 | * @since 4.0.0 10 | * @category Array 11 | * @param {Array} array The array to inspect. 12 | * @returns {Array} Returns the new duplicate free array. 13 | * @example 14 | * 15 | * sortedUniq([1, 1, 2]) 16 | * // => [1, 2] 17 | */ 18 | function sortedUniq(array) { 19 | return (array != null && array.length) 20 | ? baseSortedUniq(array) 21 | : [] 22 | } 23 | 24 | export default sortedUniq 25 | -------------------------------------------------------------------------------- /.internal/baseAssignValue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `assignValue` and `assignMergeValue` without 3 | * value checks. 4 | * 5 | * @private 6 | * @param {Object} object The object to modify. 7 | * @param {string} key The key of the property to assign. 8 | * @param {*} value The value to assign. 9 | */ 10 | function baseAssignValue(object, key, value) { 11 | if (key == '__proto__') { 12 | Object.defineProperty(object, key, { 13 | 'configurable': true, 14 | 'enumerable': true, 15 | 'value': value, 16 | 'writable': true 17 | }) 18 | } else { 19 | object[key] = value 20 | } 21 | } 22 | 23 | export default baseAssignValue 24 | -------------------------------------------------------------------------------- /.internal/baseAt.js: -------------------------------------------------------------------------------- 1 | import get from '../get.js' 2 | 3 | /** 4 | * The base implementation of `at` without support for individual paths. 5 | * 6 | * @private 7 | * @param {Object} object The object to iterate over. 8 | * @param {string[]} paths The property paths to pick. 9 | * @returns {Array} Returns the picked elements. 10 | */ 11 | function baseAt(object, paths) { 12 | let index = -1 13 | const length = paths.length 14 | const result = new Array(length) 15 | const skip = object == null 16 | 17 | while (++index < length) { 18 | result[index] = skip ? undefined : get(object, paths[index]) 19 | } 20 | return result 21 | } 22 | 23 | export default baseAt 24 | -------------------------------------------------------------------------------- /.internal/matchesStrictComparable.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `matchesProperty` for source values suitable 3 | * for strict equality comparisons, i.e. `===`. 4 | * 5 | * @private 6 | * @param {string} key The key of the property to get. 7 | * @param {*} srcValue The value to match. 8 | * @returns {Function} Returns the new spec function. 9 | */ 10 | function matchesStrictComparable(key, srcValue) { 11 | return (object) => { 12 | if (object == null) { 13 | return false 14 | } 15 | return object[key] === srcValue && 16 | (srcValue !== undefined || (key in Object(object))) 17 | } 18 | } 19 | 20 | export default matchesStrictComparable 21 | -------------------------------------------------------------------------------- /defaultTo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks `value` to determine whether a default value should be returned in 3 | * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, 4 | * or `undefined`. 5 | * 6 | * @since 4.14.0 7 | * @category Util 8 | * @param {*} value The value to check. 9 | * @param {*} defaultValue The default value. 10 | * @returns {*} Returns the resolved value. 11 | * @example 12 | * 13 | * defaultTo(1, 10) 14 | * // => 1 15 | * 16 | * defaultTo(undefined, 10) 17 | * // => 10 18 | */ 19 | function defaultTo(value, defaultValue) { 20 | return (value == null || value !== value) ? defaultValue : value 21 | } 22 | 23 | export default defaultTo 24 | -------------------------------------------------------------------------------- /.internal/assignMergeValue.js: -------------------------------------------------------------------------------- 1 | import baseAssignValue from './baseAssignValue.js' 2 | import eq from '../eq.js' 3 | 4 | /** 5 | * This function is like `assignValue` except that it doesn't assign 6 | * `undefined` values. 7 | * 8 | * @private 9 | * @param {Object} object The object to modify. 10 | * @param {string} key The key of the property to assign. 11 | * @param {*} value The value to assign. 12 | */ 13 | function assignMergeValue(object, key, value) { 14 | if ((value !== undefined && !eq(object[key], value)) || 15 | (value === undefined && !(key in object))) { 16 | baseAssignValue(object, key, value) 17 | } 18 | } 19 | 20 | export default assignMergeValue 21 | -------------------------------------------------------------------------------- /.internal/getMatchData.js: -------------------------------------------------------------------------------- 1 | import isStrictComparable from './isStrictComparable.js' 2 | import keys from '../keys.js' 3 | 4 | /** 5 | * Gets the property names, values, and compare flags of `object`. 6 | * 7 | * @private 8 | * @param {Object} object The object to query. 9 | * @returns {Array} Returns the match data of `object`. 10 | */ 11 | function getMatchData(object) { 12 | const result = keys(object) 13 | let length = result.length 14 | 15 | while (length--) { 16 | const key = result[length] 17 | const value = object[key] 18 | result[length] = [key, value, isStrictComparable(value)] 19 | } 20 | return result 21 | } 22 | 23 | export default getMatchData 24 | -------------------------------------------------------------------------------- /.internal/strictLastIndexOf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `lastIndexOf` which performs strict equality 3 | * comparisons of values, i.e. `===`. 4 | * 5 | * @private 6 | * @param {Array} array The array to inspect. 7 | * @param {*} value The value to search for. 8 | * @param {number} fromIndex The index to search from. 9 | * @returns {number} Returns the index of the matched value, else `-1`. 10 | */ 11 | function strictLastIndexOf(array, value, fromIndex) { 12 | let index = fromIndex + 1 13 | while (index--) { 14 | if (array[index] === value) { 15 | return index 16 | } 17 | } 18 | return index 19 | } 20 | 21 | export default strictLastIndexOf 22 | -------------------------------------------------------------------------------- /.internal/baseUpdate.js: -------------------------------------------------------------------------------- 1 | import baseGet from './baseGet.js' 2 | import baseSet from './baseSet.js' 3 | 4 | /** 5 | * The base implementation of `update`. 6 | * 7 | * @private 8 | * @param {Object} object The object to modify. 9 | * @param {Array|string} path The path of the property to update. 10 | * @param {Function} updater The function to produce the updated value. 11 | * @param {Function} [customizer] The function to customize path creation. 12 | * @returns {Object} Returns `object`. 13 | */ 14 | function baseUpdate(object, path, updater, customizer) { 15 | return baseSet(object, path, updater(baseGet(object, path)), customizer) 16 | } 17 | 18 | export default baseUpdate 19 | -------------------------------------------------------------------------------- /.internal/charsEndIndex.js: -------------------------------------------------------------------------------- 1 | import baseIndexOf from './baseIndexOf.js' 2 | 3 | /** 4 | * Used by `trim` and `trimEnd` to get the index of the last string symbol 5 | * that is not found in the character symbols. 6 | * 7 | * @private 8 | * @param {Array} strSymbols The string symbols to inspect. 9 | * @param {Array} chrSymbols The character symbols to find. 10 | * @returns {number} Returns the index of the last unmatched string symbol. 11 | */ 12 | function charsEndIndex(strSymbols, chrSymbols) { 13 | let index = strSymbols.length 14 | 15 | while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 16 | return index 17 | } 18 | 19 | export default charsEndIndex 20 | -------------------------------------------------------------------------------- /flip.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function that invokes `func` with arguments reversed. 3 | * 4 | * @since 4.0.0 5 | * @category Function 6 | * @param {Function} func The function to flip arguments for. 7 | * @returns {Function} Returns the new flipped function. 8 | * @see reverse 9 | * @example 10 | * 11 | * const flipped = flip((...args) => args) 12 | * 13 | * flipped('a', 'b', 'c', 'd') 14 | * // => ['d', 'c', 'b', 'a'] 15 | */ 16 | function flip(func) { 17 | if (typeof func != 'function') { 18 | throw new TypeError('Expected a function') 19 | } 20 | return function(...args) { 21 | return func.apply(this, args.reverse()) 22 | } 23 | } 24 | 25 | export default flip 26 | -------------------------------------------------------------------------------- /isBoolean.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | 4 | /** 5 | * Checks if `value` is classified as a boolean primitive or object. 6 | * 7 | * @since 0.1.0 8 | * @category Lang 9 | * @param {*} value The value to check. 10 | * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. 11 | * @example 12 | * 13 | * isBoolean(false) 14 | * // => true 15 | * 16 | * isBoolean(null) 17 | * // => false 18 | */ 19 | function isBoolean(value) { 20 | return value === true || value === false || 21 | (isObjectLike(value) && baseGetTag(value) == '[object Boolean]') 22 | } 23 | 24 | export default isBoolean 25 | -------------------------------------------------------------------------------- /lt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is less than `other`. 3 | * 4 | * @since 3.9.0 5 | * @category Lang 6 | * @param {*} value The value to compare. 7 | * @param {*} other The other value to compare. 8 | * @returns {boolean} Returns `true` if `value` is less than `other`, 9 | * else `false`. 10 | * @see gt, gte, lte 11 | * @example 12 | * 13 | * lt(1, 3) 14 | * // => true 15 | * 16 | * lt(3, 3) 17 | * // => false 18 | * 19 | * lt(3, 1) 20 | * // => false 21 | */ 22 | function lt(value, other) { 23 | if (!(typeof value == 'string' && typeof other == 'string')) { 24 | value = +value 25 | other = +other 26 | } 27 | return value < other 28 | } 29 | 30 | export default lt 31 | -------------------------------------------------------------------------------- /isObjectLike.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is object-like. A value is object-like if it's not `null` 3 | * and has a `typeof` result of "object". 4 | * 5 | * @since 4.0.0 6 | * @category Lang 7 | * @param {*} value The value to check. 8 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`. 9 | * @example 10 | * 11 | * isObjectLike({}) 12 | * // => true 13 | * 14 | * isObjectLike([1, 2, 3]) 15 | * // => true 16 | * 17 | * isObjectLike(Function) 18 | * // => false 19 | * 20 | * isObjectLike(null) 21 | * // => false 22 | */ 23 | function isObjectLike(value) { 24 | return typeof value == 'object' && value !== null 25 | } 26 | 27 | export default isObjectLike 28 | -------------------------------------------------------------------------------- /sortedIndex.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndex from './.internal/baseSortedIndex.js' 2 | 3 | /** 4 | * Uses a binary search to determine the lowest index at which `value` 5 | * should be inserted into `array` in order to maintain its sort order. 6 | * 7 | * @since 0.1.0 8 | * @category Array 9 | * @param {Array} array The sorted array to inspect. 10 | * @param {*} value The value to evaluate. 11 | * @returns {number} Returns the index at which `value` should be inserted 12 | * into `array`. 13 | * @example 14 | * 15 | * sortedIndex([30, 50], 40) 16 | * // => 1 17 | */ 18 | function sortedIndex(array, value) { 19 | return baseSortedIndex(array, value) 20 | } 21 | 22 | export default sortedIndex 23 | -------------------------------------------------------------------------------- /.internal/arrayIncludesWith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This function is like `arrayIncludes` except that it accepts a comparator. 3 | * 4 | * @private 5 | * @param {Array} [array] The array to inspect. 6 | * @param {*} target The value to search for. 7 | * @param {Function} comparator The comparator invoked per element. 8 | * @returns {boolean} Returns `true` if `target` is found, else `false`. 9 | */ 10 | function arrayIncludesWith(array, target, comparator) { 11 | if (array == null) { 12 | return false 13 | } 14 | 15 | for (const value of array) { 16 | if (comparator(target, value)) { 17 | return true 18 | } 19 | } 20 | return false 21 | } 22 | 23 | export default arrayIncludesWith 24 | -------------------------------------------------------------------------------- /.internal/strictIndexOf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `indexOf` which performs strict equality 3 | * comparisons of values, i.e. `===`. 4 | * 5 | * @private 6 | * @param {Array} array The array to inspect. 7 | * @param {*} value The value to search for. 8 | * @param {number} fromIndex The index to search from. 9 | * @returns {number} Returns the index of the matched value, else `-1`. 10 | */ 11 | function strictIndexOf(array, value, fromIndex) { 12 | let index = fromIndex - 1 13 | const { length } = array 14 | 15 | while (++index < length) { 16 | if (array[index] === value) { 17 | return index 18 | } 19 | } 20 | return -1 21 | } 22 | 23 | export default strictIndexOf 24 | -------------------------------------------------------------------------------- /gt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is greater than `other`. 3 | * 4 | * @since 3.9.0 5 | * @category Lang 6 | * @param {*} value The value to compare. 7 | * @param {*} other The other value to compare. 8 | * @returns {boolean} Returns `true` if `value` is greater than `other`, 9 | * else `false`. 10 | * @see gte, lt, lte 11 | * @example 12 | * 13 | * gt(3, 1) 14 | * // => true 15 | * 16 | * gt(3, 3) 17 | * // => false 18 | * 19 | * gt(1, 3) 20 | * // => false 21 | */ 22 | function gt(value, other) { 23 | if (!(typeof value == 'string' && typeof other == 'string')) { 24 | value = +value 25 | other = +other 26 | } 27 | return value > other 28 | } 29 | 30 | export default gt 31 | -------------------------------------------------------------------------------- /zip.js: -------------------------------------------------------------------------------- 1 | import unzip from './unzip.js' 2 | 3 | /** 4 | * Creates an array of grouped elements, the first of which contains the 5 | * first elements of the given arrays, the second of which contains the 6 | * second elements of the given arrays, and so on. 7 | * 8 | * @since 0.1.0 9 | * @category Array 10 | * @param {...Array} [arrays] The arrays to process. 11 | * @returns {Array} Returns the new array of grouped elements. 12 | * @see unzip, unzipWith, zipObject, zipObjectDeep, zipWith 13 | * @example 14 | * 15 | * zip(['a', 'b'], [1, 2], [true, false]) 16 | * // => [['a', 1, true], ['b', 2, false]] 17 | */ 18 | function zip(...arrays) { 19 | return unzip(arrays) 20 | } 21 | 22 | export default zip 23 | -------------------------------------------------------------------------------- /.internal/baseGet.js: -------------------------------------------------------------------------------- 1 | import castPath from './castPath.js' 2 | import toKey from './toKey.js' 3 | 4 | /** 5 | * The base implementation of `get` without support for default values. 6 | * 7 | * @private 8 | * @param {Object} object The object to query. 9 | * @param {Array|string} path The path of the property to get. 10 | * @returns {*} Returns the resolved value. 11 | */ 12 | function baseGet(object, path) { 13 | path = castPath(path, object) 14 | 15 | let index = 0 16 | const length = path.length 17 | 18 | while (object != null && index < length) { 19 | object = object[toKey(path[index++])] 20 | } 21 | return (index && index == length) ? object : undefined 22 | } 23 | 24 | export default baseGet 25 | -------------------------------------------------------------------------------- /sortedUniqBy.js: -------------------------------------------------------------------------------- 1 | import baseSortedUniq from './.internal/baseSortedUniq.js' 2 | 3 | /** 4 | * This method is like `uniqBy` except that it's designed and optimized 5 | * for sorted arrays. 6 | * 7 | * @since 4.0.0 8 | * @category Array 9 | * @param {Array} array The array to inspect. 10 | * @param {Function} iteratee The iteratee invoked per element. 11 | * @returns {Array} Returns the new duplicate free array. 12 | * @example 13 | * 14 | * sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor) 15 | * // => [1.1, 2.3] 16 | */ 17 | function sortedUniqBy(array, iteratee) { 18 | return (array != null && array.length) 19 | ? baseSortedUniq(array, iteratee) 20 | : [] 21 | } 22 | 23 | export default sortedUniqBy 24 | -------------------------------------------------------------------------------- /lte.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is less than or equal to `other`. 3 | * 4 | * @since 3.9.0 5 | * @category Lang 6 | * @param {*} value The value to compare. 7 | * @param {*} other The other value to compare. 8 | * @returns {boolean} Returns `true` if `value` is less than or equal to 9 | * `other`, else `false`. 10 | * @see gt, gte, lt 11 | * @example 12 | * 13 | * lte(1, 3) 14 | * // => true 15 | * 16 | * lte(3, 3) 17 | * // => true 18 | * 19 | * lte(3, 1) 20 | * // => false 21 | */ 22 | function lte(value, other) { 23 | if (!(typeof value == 'string' && typeof other == 'string')) { 24 | value = +value 25 | other = +other 26 | } 27 | return value <= other 28 | } 29 | 30 | export default lte 31 | -------------------------------------------------------------------------------- /.internal/charsStartIndex.js: -------------------------------------------------------------------------------- 1 | import baseIndexOf from './baseIndexOf.js' 2 | 3 | /** 4 | * Used by `trim` and `trimStart` to get the index of the first string symbol 5 | * that is not found in the character symbols. 6 | * 7 | * @private 8 | * @param {Array} strSymbols The string symbols to inspect. 9 | * @param {Array} chrSymbols The character symbols to find. 10 | * @returns {number} Returns the index of the first unmatched string symbol. 11 | */ 12 | function charsStartIndex(strSymbols, chrSymbols) { 13 | let index = -1 14 | const length = strSymbols.length 15 | 16 | while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} 17 | return index 18 | } 19 | 20 | export default charsStartIndex 21 | -------------------------------------------------------------------------------- /defer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Defers invoking the `func` until the current call stack has cleared. Any 3 | * additional arguments are provided to `func` when it's invoked. 4 | * 5 | * @since 0.1.0 6 | * @category Function 7 | * @param {Function} func The function to defer. 8 | * @param {...*} [args] The arguments to invoke `func` with. 9 | * @returns {number} Returns the timer id. 10 | * @example 11 | * 12 | * defer(text => console.log(text), 'deferred') 13 | * // => Logs 'deferred' after one millisecond. 14 | */ 15 | function defer(func, ...args) { 16 | if (typeof func != 'function') { 17 | throw new TypeError('Expected a function') 18 | } 19 | return setTimeout(func, 1, ...args) 20 | } 21 | 22 | export default defer 23 | -------------------------------------------------------------------------------- /flattenDeep.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const INFINITY = 1 / 0 5 | 6 | /** 7 | * Recursively flattens `array`. 8 | * 9 | * @since 3.0.0 10 | * @category Array 11 | * @param {Array} array The array to flatten. 12 | * @returns {Array} Returns the new flattened array. 13 | * @see flatMap, flatMapDeep, flatMapDepth, flatten, flattenDepth 14 | * @example 15 | * 16 | * flattenDeep([1, [2, [3, [4]], 5]]) 17 | * // => [1, 2, 3, 4, 5] 18 | */ 19 | function flattenDeep(array) { 20 | const length = array == null ? 0 : array.length 21 | return length ? baseFlatten(array, INFINITY) : [] 22 | } 23 | 24 | export default flattenDeep 25 | -------------------------------------------------------------------------------- /gte.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is greater than or equal to `other`. 3 | * 4 | * @since 3.9.0 5 | * @category Lang 6 | * @param {*} value The value to compare. 7 | * @param {*} other The other value to compare. 8 | * @returns {boolean} Returns `true` if `value` is greater than or equal to 9 | * `other`, else `false`. 10 | * @see gt, lt, lte 11 | * @example 12 | * 13 | * gte(3, 1) 14 | * // => true 15 | * 16 | * gte(3, 3) 17 | * // => true 18 | * 19 | * gte(1, 3) 20 | * // => false 21 | */ 22 | function gte(value, other) { 23 | if (!(typeof value == 'string' && typeof other == 'string')) { 24 | value = +value 25 | other = +other 26 | } 27 | return value >= other 28 | } 29 | 30 | export default gte 31 | -------------------------------------------------------------------------------- /once.js: -------------------------------------------------------------------------------- 1 | import before from './before.js' 2 | 3 | /** 4 | * Creates a function that is restricted to invoking `func` once. Repeat calls 5 | * to the function return the value of the first invocation. The `func` is 6 | * invoked with the `this` binding and arguments of the created function. 7 | * 8 | * @since 0.1.0 9 | * @category Function 10 | * @param {Function} func The function to restrict. 11 | * @returns {Function} Returns the new restricted function. 12 | * @example 13 | * 14 | * const initialize = once(createApplication) 15 | * initialize() 16 | * initialize() 17 | * // => `createApplication` is invoked once 18 | */ 19 | function once(func) { 20 | return before(2, func) 21 | } 22 | 23 | export default once 24 | -------------------------------------------------------------------------------- /compact.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an array with all falsey values removed. The values `false`, `null`, 3 | * `0`, `""`, `undefined`, and `NaN` are falsey. 4 | * 5 | * @since 0.1.0 6 | * @category Array 7 | * @param {Array} array The array to compact. 8 | * @returns {Array} Returns the new array of filtered values. 9 | * @example 10 | * 11 | * compact([0, 1, false, 2, '', 3]) 12 | * // => [1, 2, 3] 13 | */ 14 | function compact(array) { 15 | let resIndex = 0 16 | const result = [] 17 | 18 | if (array == null) { 19 | return result 20 | } 21 | 22 | for (const value of array) { 23 | if (value) { 24 | result[resIndex++] = value 25 | } 26 | } 27 | return result 28 | } 29 | 30 | export default compact 31 | -------------------------------------------------------------------------------- /functions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an array of function property names from own enumerable properties 3 | * of `object`. 4 | * 5 | * @since 0.1.0 6 | * @category Object 7 | * @param {Object} object The object to inspect. 8 | * @returns {Array} Returns the function names. 9 | * @see functionsIn 10 | * @example 11 | * 12 | * function Foo() { 13 | * this.a = () => 'a' 14 | * this.b = () => 'b' 15 | * } 16 | * 17 | * Foo.prototype.c = () => 'c' 18 | * 19 | * functions(new Foo) 20 | * // => ['a', 'b'] 21 | */ 22 | function functions(object) { 23 | if (object == null) { 24 | return [] 25 | } 26 | return Object.keys(object).filter((key) => typeof object[key] == 'function') 27 | } 28 | 29 | export default functions 30 | -------------------------------------------------------------------------------- /.internal/getSymbolsIn.js: -------------------------------------------------------------------------------- 1 | import getSymbols from './getSymbols.js' 2 | 3 | /* Built-in method references for those with the same name as other `lodash` methods. */ 4 | const nativeGetSymbols = Object.getOwnPropertySymbols 5 | 6 | /** 7 | * Creates an array of the own and inherited enumerable symbols of `object`. 8 | * 9 | * @private 10 | * @param {Object} object The object to query. 11 | * @returns {Array} Returns the array of symbols. 12 | */ 13 | const getSymbolsIn = !nativeGetSymbols ? () => [] : (object) => { 14 | const result = [] 15 | while (object) { 16 | result.push(...getSymbols(object)) 17 | object = Object.getPrototypeOf(Object(object)) 18 | } 19 | return result 20 | } 21 | 22 | export default getSymbolsIn 23 | -------------------------------------------------------------------------------- /.internal/baseIndexOf.js: -------------------------------------------------------------------------------- 1 | import baseFindIndex from './baseFindIndex.js' 2 | import baseIsNaN from './baseIsNaN.js' 3 | import strictIndexOf from './strictIndexOf.js' 4 | 5 | /** 6 | * The base implementation of `indexOf` without `fromIndex` bounds checks. 7 | * 8 | * @private 9 | * @param {Array} array The array to inspect. 10 | * @param {*} value The value to search for. 11 | * @param {number} fromIndex The index to search from. 12 | * @returns {number} Returns the index of the matched value, else `-1`. 13 | */ 14 | function baseIndexOf(array, value, fromIndex) { 15 | return value === value 16 | ? strictIndexOf(array, value, fromIndex) 17 | : baseFindIndex(array, baseIsNaN, fromIndex) 18 | } 19 | 20 | export default baseIndexOf 21 | -------------------------------------------------------------------------------- /isSet.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | import nodeUtil from './.internal/nodeUtil.js' 3 | 4 | /* Node.js helper references. */ 5 | const nodeIsSet = nodeUtil && nodeUtil.isSet 6 | 7 | /** 8 | * Checks if `value` is classified as a `Set` object. 9 | * 10 | * @since 4.3.0 11 | * @category Lang 12 | * @param {*} value The value to check. 13 | * @returns {boolean} Returns `true` if `value` is a set, else `false`. 14 | * @example 15 | * 16 | * isSet(new Set) 17 | * // => true 18 | * 19 | * isSet(new WeakSet) 20 | * // => false 21 | */ 22 | const isSet = nodeIsSet 23 | ? (value) => nodeIsSet(value) 24 | : (value) => typeof value == 'object' && value !== null && getTag(value) == '[object Set]' 25 | 26 | export default isSet 27 | -------------------------------------------------------------------------------- /.internal/memoizeCapped.js: -------------------------------------------------------------------------------- 1 | import memoize from '../memoize.js' 2 | 3 | /** Used as the maximum memoize cache size. */ 4 | const MAX_MEMOIZE_SIZE = 500 5 | 6 | /** 7 | * A specialized version of `memoize` which clears the memoized function's 8 | * cache when it exceeds `MAX_MEMOIZE_SIZE`. 9 | * 10 | * @private 11 | * @param {Function} func The function to have its output memoized. 12 | * @returns {Function} Returns the new memoized function. 13 | */ 14 | function memoizeCapped(func) { 15 | const result = memoize(func, (key) => { 16 | const { cache } = result 17 | if (cache.size === MAX_MEMOIZE_SIZE) { 18 | cache.clear() 19 | } 20 | return key 21 | }) 22 | 23 | return result 24 | } 25 | 26 | export default memoizeCapped 27 | -------------------------------------------------------------------------------- /sortedLastIndex.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndex from './.internal/baseSortedIndex.js' 2 | 3 | /** 4 | * This method is like `sortedIndex` except that it returns the highest 5 | * index at which `value` should be inserted into `array` in order to 6 | * maintain its sort order. 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The sorted array to inspect. 11 | * @param {*} value The value to evaluate. 12 | * @returns {number} Returns the index at which `value` should be inserted 13 | * into `array`. 14 | * @example 15 | * 16 | * sortedLastIndex([4, 5, 5, 5, 6], 5) 17 | * // => 4 18 | */ 19 | function sortedLastIndex(array, value) { 20 | return baseSortedIndex(array, value, true) 21 | } 22 | 23 | export default sortedLastIndex 24 | -------------------------------------------------------------------------------- /take.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Creates a slice of `array` with `n` elements taken from the beginning. 5 | * 6 | * @since 0.1.0 7 | * @category Array 8 | * @param {Array} array The array to query. 9 | * @param {number} [n=1] The number of elements to take. 10 | * @returns {Array} Returns the slice of `array`. 11 | * @example 12 | * 13 | * take([1, 2, 3]) 14 | * // => [1] 15 | * 16 | * take([1, 2, 3], 2) 17 | * // => [1, 2] 18 | * 19 | * take([1, 2, 3], 5) 20 | * // => [1, 2, 3] 21 | * 22 | * take([1, 2, 3], 0) 23 | * // => [] 24 | */ 25 | function take(array, n=1) { 26 | if (!(array != null && array.length)) { 27 | return [] 28 | } 29 | return slice(array, 0, n < 0 ? 0 : n) 30 | } 31 | 32 | export default take 33 | -------------------------------------------------------------------------------- /.internal/baseIndexOfWith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This function is like `baseIndexOf` except that it accepts a comparator. 3 | * 4 | * @private 5 | * @param {Array} array The array to inspect. 6 | * @param {*} value The value to search for. 7 | * @param {number} fromIndex The index to search from. 8 | * @param {Function} comparator The comparator invoked per element. 9 | * @returns {number} Returns the index of the matched value, else `-1`. 10 | */ 11 | function baseIndexOfWith(array, value, fromIndex, comparator) { 12 | let index = fromIndex - 1 13 | const { length } = array 14 | 15 | while (++index < length) { 16 | if (comparator(array[index], value)) { 17 | return index 18 | } 19 | } 20 | return -1 21 | } 22 | 23 | export default baseIndexOfWith 24 | -------------------------------------------------------------------------------- /.internal/baseZipObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This base implementation of `zipObject` which assigns values using `assignFunc`. 3 | * 4 | * @private 5 | * @param {Array} props The property identifiers. 6 | * @param {Array} values The property values. 7 | * @param {Function} assignFunc The function to assign values. 8 | * @returns {Object} Returns the new object. 9 | */ 10 | function baseZipObject(props, values, assignFunc) { 11 | let index = -1 12 | const length = props.length 13 | const valsLength = values.length 14 | const result = {} 15 | 16 | while (++index < length) { 17 | const value = index < valsLength ? values[index] : undefined 18 | assignFunc(result, props[index], value) 19 | } 20 | return result 21 | } 22 | 23 | export default baseZipObject 24 | -------------------------------------------------------------------------------- /.internal/baseMatches.js: -------------------------------------------------------------------------------- 1 | import baseIsMatch from './baseIsMatch.js' 2 | import getMatchData from './getMatchData.js' 3 | import matchesStrictComparable from './matchesStrictComparable.js' 4 | 5 | /** 6 | * The base implementation of `matches` which doesn't clone `source`. 7 | * 8 | * @private 9 | * @param {Object} source The object of property values to match. 10 | * @returns {Function} Returns the new spec function. 11 | */ 12 | function baseMatches(source) { 13 | const matchData = getMatchData(source) 14 | if (matchData.length == 1 && matchData[0][2]) { 15 | return matchesStrictComparable(matchData[0][0], matchData[0][1]) 16 | } 17 | return (object) => object === source || baseIsMatch(object, source, matchData) 18 | } 19 | 20 | export default baseMatches 21 | -------------------------------------------------------------------------------- /cloneDeep.js: -------------------------------------------------------------------------------- 1 | import baseClone from './.internal/baseClone.js' 2 | 3 | /** Used to compose bitmasks for cloning. */ 4 | const CLONE_DEEP_FLAG = 1 5 | const CLONE_SYMBOLS_FLAG = 4 6 | 7 | /** 8 | * This method is like `clone` except that it recursively clones `value`. 9 | * 10 | * @since 1.0.0 11 | * @category Lang 12 | * @param {*} value The value to recursively clone. 13 | * @returns {*} Returns the deep cloned value. 14 | * @see clone 15 | * @example 16 | * 17 | * const objects = [{ 'a': 1 }, { 'b': 2 }] 18 | * 19 | * const deep = cloneDeep(objects) 20 | * console.log(deep[0] === objects[0]) 21 | * // => false 22 | */ 23 | function cloneDeep(value) { 24 | return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG) 25 | } 26 | 27 | export default cloneDeep 28 | -------------------------------------------------------------------------------- /zipObjectDeep.js: -------------------------------------------------------------------------------- 1 | import baseSet from './.internal/baseSet.js' 2 | import baseZipObject from './.internal/baseZipObject.js' 3 | 4 | /** 5 | * This method is like `zipObject` except that it supports property paths. 6 | * 7 | * @since 4.1.0 8 | * @category Array 9 | * @param {Array} [props=[]] The property identifiers. 10 | * @param {Array} [values=[]] The property values. 11 | * @returns {Object} Returns the new object. 12 | * @see unzip, unzipWith, zip, zipObject, zipWith 13 | * @example 14 | * 15 | * zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]) 16 | * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } 17 | */ 18 | function zipObjectDeep(props, values) { 19 | return baseZipObject(props || [], values || [], baseSet) 20 | } 21 | 22 | export default zipObjectDeep 23 | -------------------------------------------------------------------------------- /isMap.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | import nodeUtil from './.internal/nodeUtil.js' 4 | 5 | /* Node.js helper references. */ 6 | const nodeIsMap = nodeUtil && nodeUtil.isMap 7 | 8 | /** 9 | * Checks if `value` is classified as a `Map` object. 10 | * 11 | * @since 4.3.0 12 | * @category Lang 13 | * @param {*} value The value to check. 14 | * @returns {boolean} Returns `true` if `value` is a map, else `false`. 15 | * @example 16 | * 17 | * isMap(new Map) 18 | * // => true 19 | * 20 | * isMap(new WeakMap) 21 | * // => false 22 | */ 23 | const isMap = nodeIsMap 24 | ? (value) => nodeIsMap(value) 25 | : (value) => isObjectLike(value) && getTag(value) == '[object Map]' 26 | 27 | export default isMap 28 | -------------------------------------------------------------------------------- /overSome.js: -------------------------------------------------------------------------------- 1 | import some from './some.js' 2 | 3 | /** 4 | * Creates a function that checks if **any** of the `predicates` return 5 | * truthy when invoked with the arguments it receives. 6 | * 7 | * @since 4.0.0 8 | * @category Util 9 | * @param {Function[]} [predicates=[identity]] 10 | * The predicates to check. 11 | * @returns {Function} Returns the new function. 12 | * @example 13 | * 14 | * const func = overSome([Boolean, isFinite]) 15 | * 16 | * func('1') 17 | * // => true 18 | * 19 | * func(null) 20 | * // => true 21 | * 22 | * func(NaN) 23 | * // => false 24 | */ 25 | function overSome(iteratees) { 26 | return function(...args) { 27 | return some(iteratees, (iteratee) => iteratee.apply(this, args)) 28 | } 29 | } 30 | 31 | export default overSome 32 | -------------------------------------------------------------------------------- /drop.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Creates a slice of `array` with `n` elements dropped from the beginning. 5 | * 6 | * @since 0.5.0 7 | * @category Array 8 | * @param {Array} array The array to query. 9 | * @param {number} [n=1] The number of elements to drop. 10 | * @returns {Array} Returns the slice of `array`. 11 | * @example 12 | * 13 | * drop([1, 2, 3]) 14 | * // => [2, 3] 15 | * 16 | * drop([1, 2, 3], 2) 17 | * // => [3] 18 | * 19 | * drop([1, 2, 3], 5) 20 | * // => [] 21 | * 22 | * drop([1, 2, 3], 0) 23 | * // => [1, 2, 3] 24 | */ 25 | function drop(array, n=1) { 26 | const length = array == null ? 0 : array.length 27 | return length 28 | ? slice(array, n < 0 ? 0 : n, length) 29 | : [] 30 | } 31 | 32 | export default drop 33 | -------------------------------------------------------------------------------- /delay.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Invokes `func` after `wait` milliseconds. Any additional arguments are 3 | * provided to `func` when it's invoked. 4 | * 5 | * @since 0.1.0 6 | * @category Function 7 | * @param {Function} func The function to delay. 8 | * @param {number} wait The number of milliseconds to delay invocation. 9 | * @param {...*} [args] The arguments to invoke `func` with. 10 | * @returns {number} Returns the timer id. 11 | * @example 12 | * 13 | * delay(text => console.log(text), 1000, 'later') 14 | * // => Logs 'later' after one second. 15 | */ 16 | function delay(func, wait, ...args) { 17 | if (typeof func != 'function') { 18 | throw new TypeError('Expected a function') 19 | } 20 | return setTimeout(func, +wait || 0, ...args) 21 | } 22 | 23 | export default delay 24 | -------------------------------------------------------------------------------- /overEvery.js: -------------------------------------------------------------------------------- 1 | import every from './every.js' 2 | 3 | /** 4 | * Creates a function that checks if **all** of the `predicates` return 5 | * truthy when invoked with the arguments it receives. 6 | * 7 | * @since 4.0.0 8 | * @category Util 9 | * @param {Function[]} [predicates=[identity]] 10 | * The predicates to check. 11 | * @returns {Function} Returns the new function. 12 | * @example 13 | * 14 | * const func = overEvery([Boolean, isFinite]) 15 | * 16 | * func('1') 17 | * // => true 18 | * 19 | * func(null) 20 | * // => false 21 | * 22 | * func(NaN) 23 | * // => false 24 | */ 25 | function overEvery(iteratees) { 26 | return function(...args) { 27 | return every(iteratees, (iteratee) => iteratee.apply(this, args)) 28 | } 29 | } 30 | 31 | export default overEvery 32 | -------------------------------------------------------------------------------- /propertyOf.js: -------------------------------------------------------------------------------- 1 | import baseGet from './.internal/baseGet.js' 2 | 3 | /** 4 | * The opposite of `property`s method creates a function that returns 5 | * the value at a given path of `object`. 6 | * 7 | * @since 3.0.0 8 | * @category Util 9 | * @param {Object} object The object to query. 10 | * @returns {Function} Returns the new accessor function. 11 | * @example 12 | * 13 | * const array = [0, 1, 2] 14 | * const object = { 'a': array, 'b': array, 'c': array } 15 | * 16 | * map(['a[2]', 'c[0]'], propertyOf(object)) 17 | * // => [2, 0] 18 | * 19 | * map([['a', '2'], ['c', '0']], propertyOf(object)) 20 | * // => [2, 0] 21 | */ 22 | function propertyOf(object) { 23 | return (path) => object == null ? undefined : baseGet(object, path) 24 | } 25 | 26 | export default propertyOf 27 | -------------------------------------------------------------------------------- /replace.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Replaces matches for `pattern` in `string` with `replacement`. 3 | * 4 | * **Note:** This method is based on 5 | * [`String#replace`](https://mdn.io/String/replace). 6 | * 7 | * @since 4.0.0 8 | * @category String 9 | * @param {string} [string=''] The string to modify. 10 | * @param {RegExp|string} pattern The pattern to replace. 11 | * @param {Function|string} replacement The match replacement. 12 | * @returns {string} Returns the modified string. 13 | * @see truncate, trim 14 | * @example 15 | * 16 | * replace('Hi Fred', 'Fred', 'Barney') 17 | * // => 'Hi Barney' 18 | */ 19 | function replace(...args) { 20 | const string = `${args[0]}` 21 | return args.length < 3 ? string : string.replace(args[1], args[2]) 22 | } 23 | 24 | export default replace 25 | -------------------------------------------------------------------------------- /.internal/baseFindKey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of methods like `findKey` and `findLastKey` 3 | * which iterates over `collection` using `eachFunc`. 4 | * 5 | * @private 6 | * @param {Array|Object} collection The collection to inspect. 7 | * @param {Function} predicate The function invoked per iteration. 8 | * @param {Function} eachFunc The function to iterate over `collection`. 9 | * @returns {*} Returns the found element or its key, else `undefined`. 10 | */ 11 | function baseFindKey(collection, predicate, eachFunc) { 12 | let result 13 | eachFunc(collection, (value, key, collection) => { 14 | if (predicate(value, key, collection)) { 15 | result = key 16 | return false 17 | } 18 | }) 19 | return result 20 | } 21 | 22 | export default baseFindKey 23 | -------------------------------------------------------------------------------- /dropRight.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Creates a slice of `array` with `n` elements dropped from the end. 5 | * 6 | * @since 3.0.0 7 | * @category Array 8 | * @param {Array} array The array to query. 9 | * @param {number} [n=1] The number of elements to drop. 10 | * @returns {Array} Returns the slice of `array`. 11 | * @example 12 | * 13 | * dropRight([1, 2, 3]) 14 | * // => [1, 2] 15 | * 16 | * dropRight([1, 2, 3], 2) 17 | * // => [1] 18 | * 19 | * dropRight([1, 2, 3], 5) 20 | * // => [] 21 | * 22 | * dropRight([1, 2, 3], 0) 23 | * // => [1, 2, 3] 24 | */ 25 | function dropRight(array, n=1) { 26 | const length = array == null ? 0 : array.length; 27 | return length ? slice(array, 0, n < 0 ? 0 : -n) : []; 28 | } 29 | 30 | export default dropRight 31 | -------------------------------------------------------------------------------- /zipObject.js: -------------------------------------------------------------------------------- 1 | import assignValue from './.internal/assignValue.js' 2 | import baseZipObject from './.internal/baseZipObject.js' 3 | 4 | /** 5 | * This method is like `fromPairs` except that it accepts two arrays, 6 | * one of property identifiers and one of corresponding values. 7 | * 8 | * @since 0.4.0 9 | * @category Array 10 | * @param {Array} [props=[]] The property identifiers. 11 | * @param {Array} [values=[]] The property values. 12 | * @returns {Object} Returns the new object. 13 | * @see unzip, unzipWith, zip, zipObjectDeep, zipWith 14 | * @example 15 | * 16 | * zipObject(['a', 'b'], [1, 2]) 17 | * // => { 'a': 1, 'b': 2 } 18 | */ 19 | function zipObject(props, values) { 20 | return baseZipObject(props || [], values || [], assignValue) 21 | } 22 | 23 | export default zipObject 24 | -------------------------------------------------------------------------------- /.internal/baseForRight.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This function is like `baseFor` except that it iterates over properties 3 | * in the opposite order. 4 | * 5 | * @private 6 | * @param {Object} object The object to iterate over. 7 | * @param {Function} iteratee The function invoked per iteration. 8 | * @param {Function} keysFunc The function to get the keys of `object`. 9 | * @returns {Object} Returns `object`. 10 | */ 11 | function baseForRight(object, iteratee, keysFunc) { 12 | const iterable = Object(object) 13 | const props = keysFunc(object) 14 | let { length } = props 15 | 16 | while (length--) { 17 | const key = props[length] 18 | if (iteratee(iterable[key], key, iterable) === false) { 19 | break 20 | } 21 | } 22 | return object 23 | } 24 | 25 | export default baseForRight 26 | -------------------------------------------------------------------------------- /.internal/createRange.js: -------------------------------------------------------------------------------- 1 | import baseRange from './baseRange.js' 2 | import toFinite from '../toFinite.js' 3 | 4 | /** 5 | * Creates a `range` or `rangeRight` function. 6 | * 7 | * @private 8 | * @param {boolean} [fromRight] Specify iterating from right to left. 9 | * @returns {Function} Returns the new range function. 10 | */ 11 | function createRange(fromRight) { 12 | return (start, end, step) => { 13 | // Ensure the sign of `-0` is preserved. 14 | start = toFinite(start) 15 | if (end === undefined) { 16 | end = start 17 | start = 0 18 | } else { 19 | end = toFinite(end) 20 | } 21 | step = step === undefined ? (start < end ? 1 : -1) : toFinite(step) 22 | return baseRange(start, end, step, fromRight) 23 | } 24 | } 25 | 26 | export default createRange 27 | -------------------------------------------------------------------------------- /has.js: -------------------------------------------------------------------------------- 1 | /** Used to check objects for own properties. */ 2 | const hasOwnProperty = Object.prototype.hasOwnProperty 3 | 4 | /** 5 | * Checks if `key` is a direct property of `object`. 6 | * 7 | * @since 0.1.0 8 | * @category Object 9 | * @param {Object} object The object to query. 10 | * @param {string} key The key to check. 11 | * @returns {boolean} Returns `true` if `key` exists, else `false`. 12 | * @see hasIn, hasPath, hasPathIn 13 | * @example 14 | * 15 | * const object = { 'a': { 'b': 2 } } 16 | * const other = create({ 'a': create({ 'b': 2 }) }) 17 | * 18 | * has(object, 'a') 19 | * // => true 20 | * 21 | * has(other, 'a') 22 | * // => false 23 | */ 24 | function has(object, key) { 25 | return object != null && hasOwnProperty.call(object, key) 26 | } 27 | 28 | export default has 29 | -------------------------------------------------------------------------------- /lowerCase.js: -------------------------------------------------------------------------------- 1 | import words from './words.js' 2 | 3 | /** 4 | * Converts `string`, as space separated words, to lower case. 5 | * 6 | * @since 4.0.0 7 | * @category String 8 | * @param {string} [string=''] The string to convert. 9 | * @returns {string} Returns the lower cased string. 10 | * @see camelCase, kebabCase, snakeCase, startCase, upperCase, upperFirst 11 | * @example 12 | * 13 | * lowerCase('--Foo-Bar--') 14 | * // => 'foo bar' 15 | * 16 | * lowerCase('fooBar') 17 | * // => 'foo bar' 18 | * 19 | * lowerCase('__FOO_BAR__') 20 | * // => 'foo bar' 21 | */ 22 | const lowerCase = (string) => ( 23 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( 24 | result + (index ? ' ' : '') + word.toLowerCase() 25 | ), '') 26 | ) 27 | 28 | export default lowerCase 29 | -------------------------------------------------------------------------------- /negate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function that negates the result of the predicate `func`. The 3 | * `func` predicate is invoked with the `this` binding and arguments of the 4 | * created function. 5 | * 6 | * @since 3.0.0 7 | * @category Function 8 | * @param {Function} predicate The predicate to negate. 9 | * @returns {Function} Returns the new negated function. 10 | * @example 11 | * 12 | * function isEven(n) { 13 | * return n % 2 == 0 14 | * } 15 | * 16 | * filter([1, 2, 3, 4, 5, 6], negate(isEven)) 17 | * // => [1, 3, 5] 18 | */ 19 | function negate(predicate) { 20 | if (typeof predicate != 'function') { 21 | throw new TypeError('Expected a function') 22 | } 23 | return function(...args) { 24 | return !predicate.apply(this, args) 25 | } 26 | } 27 | 28 | export default negate 29 | -------------------------------------------------------------------------------- /upperCase.js: -------------------------------------------------------------------------------- 1 | import words from './words.js' 2 | 3 | /** 4 | * Converts `string`, as space separated words, to upper case. 5 | * 6 | * @since 4.0.0 7 | * @category String 8 | * @param {string} [string=''] The string to convert. 9 | * @returns {string} Returns the upper cased string. 10 | * @see camelCase, kebabCase, lowerCase, snakeCase, startCase, upperFirst 11 | * @example 12 | * 13 | * upperCase('--foo-bar') 14 | * // => 'FOO BAR' 15 | * 16 | * upperCase('fooBar') 17 | * // => 'FOO BAR' 18 | * 19 | * upperCase('__foo_bar__') 20 | * // => 'FOO BAR' 21 | */ 22 | const upperCase = (string) => ( 23 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( 24 | result + (index ? ' ' : '') + word.toUpperCase() 25 | ), '') 26 | ) 27 | 28 | export default upperCase 29 | -------------------------------------------------------------------------------- /.internal/baseRange.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `range` and `rangeRight` which doesn't 3 | * coerce arguments. 4 | * 5 | * @private 6 | * @param {number} start The start of the range. 7 | * @param {number} end The end of the range. 8 | * @param {number} step The value to increment or decrement by. 9 | * @param {boolean} [fromRight] Specify iterating from right to left. 10 | * @returns {Array} Returns the range of numbers. 11 | */ 12 | function baseRange(start, end, step, fromRight) { 13 | let index = -1 14 | let length = Math.max(Math.ceil((end - start) / (step || 1)), 0) 15 | const result = new Array(length) 16 | 17 | while (length--) { 18 | result[fromRight ? length : ++index] = start 19 | start += step 20 | } 21 | return result 22 | } 23 | 24 | export default baseRange 25 | -------------------------------------------------------------------------------- /uniq.js: -------------------------------------------------------------------------------- 1 | import baseUniq from './.internal/baseUniq.js' 2 | 3 | /** 4 | * Creates a duplicate-free version of an array, using 5 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 6 | * for equality comparisons, in which only the first occurrence of each element 7 | * is kept. The order of result values is determined by the order they occur 8 | * in the array. 9 | * 10 | * @since 0.1.0 11 | * @category Array 12 | * @param {Array} array The array to inspect. 13 | * @returns {Array} Returns the new duplicate free array. 14 | * @see uniqBy, uniqWith 15 | * @example 16 | * 17 | * uniq([2, 1, 2]) 18 | * // => [2, 1] 19 | */ 20 | function uniq(array) { 21 | return (array != null && array.length) 22 | ? baseUniq(array) 23 | : [] 24 | } 25 | 26 | export default uniq 27 | -------------------------------------------------------------------------------- /ary.js: -------------------------------------------------------------------------------- 1 | import createWrap from './.internal/createWrap.js' 2 | 3 | /** Used to compose bitmasks for function metadata. */ 4 | const WRAP_ARY_FLAG = 128 5 | 6 | /** 7 | * Creates a function that invokes `func`, with up to `n` arguments, 8 | * ignoring any additional arguments. 9 | * 10 | * @since 3.0.0 11 | * @category Function 12 | * @param {Function} func The function to cap arguments for. 13 | * @param {number} [n=func.length] The arity cap. 14 | * @returns {Function} Returns the new capped function. 15 | * @example 16 | * 17 | * map(['6', '8', '10'], ary(parseInt, 1)) 18 | * // => [6, 8, 10] 19 | */ 20 | function ary(func, n) { 21 | n = (func && n == null) ? func.length : n 22 | return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n) 23 | } 24 | 25 | export default ary 26 | -------------------------------------------------------------------------------- /findLast.js: -------------------------------------------------------------------------------- 1 | import createFind from './.internal/createFind.js' 2 | import findLastIndex from './findLastIndex.js' 3 | 4 | /** 5 | * This method is like `find` except that it iterates over elements of 6 | * `collection` from right to left. 7 | * 8 | * @since 2.0.0 9 | * @category Collection 10 | * @param {Array|Object} collection The collection to inspect. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @param {number} [fromIndex=collection.length-1] The index to search from. 13 | * @returns {*} Returns the matched element, else `undefined`. 14 | * @see find, findIndex, findKey, findLastIndex, findLastKey 15 | * @example 16 | * 17 | * findLast([1, 2, 3, 4], n => n % 2 == 1) 18 | * // => 3 19 | */ 20 | const findLast = createFind(findLastIndex) 21 | 22 | export default findLast 23 | -------------------------------------------------------------------------------- /isDate.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | import nodeUtil from './.internal/nodeUtil.js' 4 | 5 | /* Node.js helper references. */ 6 | const nodeIsDate = nodeUtil && nodeUtil.isDate 7 | 8 | /** 9 | * Checks if `value` is classified as a `Date` object. 10 | * 11 | * @since 0.1.0 12 | * @category Lang 13 | * @param {*} value The value to check. 14 | * @returns {boolean} Returns `true` if `value` is a date object, else `false`. 15 | * @example 16 | * 17 | * isDate(new Date) 18 | * // => true 19 | * 20 | * isDate('Mon April 23 2012') 21 | * // => false 22 | */ 23 | const isDate = nodeIsDate 24 | ? (value) => nodeIsDate(value) 25 | : (value) => isObjectLike(value) && baseGetTag(value) == '[object Date]' 26 | 27 | export default isDate 28 | -------------------------------------------------------------------------------- /isRegExp.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | import nodeUtil from './.internal/nodeUtil.js' 4 | 5 | /* Node.js helper references. */ 6 | const nodeIsRegExp = nodeUtil && nodeUtil.isRegExp 7 | 8 | /** 9 | * Checks if `value` is classified as a `RegExp` object. 10 | * 11 | * @since 0.1.0 12 | * @category Lang 13 | * @param {*} value The value to check. 14 | * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. 15 | * @example 16 | * 17 | * isRegExp(/abc/) 18 | * // => true 19 | * 20 | * isRegExp('/abc/') 21 | * // => false 22 | */ 23 | const isRegExp = nodeIsRegExp 24 | ? (value) => nodeIsRegExp(value) 25 | : (value) => isObjectLike(value) && baseGetTag(value) == '[object RegExp]' 26 | 27 | export default isRegExp 28 | -------------------------------------------------------------------------------- /nth.js: -------------------------------------------------------------------------------- 1 | import isIndex from './.internal/isIndex.js' 2 | 3 | /** 4 | * Gets the element at index `n` of `array`. If `n` is negative, the nth 5 | * element from the end is returned. 6 | * 7 | * @since 4.11.0 8 | * @category Array 9 | * @param {Array} array The array to query. 10 | * @param {number} [n=0] The index of the element to return. 11 | * @returns {*} Returns the nth element of `array`. 12 | * @example 13 | * 14 | * const array = ['a', 'b', 'c', 'd'] 15 | * 16 | * nth(array, 1) 17 | * // => 'b' 18 | * 19 | * nth(array, -2) 20 | * // => 'c' 21 | */ 22 | function nth(array, n) { 23 | const length = array == null ? 0 : array.length 24 | if (!length) { 25 | return 26 | } 27 | n += n < 0 ? length : 0 28 | return isIndex(n, length) ? array[n] : undefined 29 | } 30 | 31 | export default nth 32 | -------------------------------------------------------------------------------- /.internal/baseFindIndex.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `findIndex` and `findLastIndex`. 3 | * 4 | * @private 5 | * @param {Array} array The array to inspect. 6 | * @param {Function} predicate The function invoked per iteration. 7 | * @param {number} fromIndex The index to search from. 8 | * @param {boolean} [fromRight] Specify iterating from right to left. 9 | * @returns {number} Returns the index of the matched value, else `-1`. 10 | */ 11 | function baseFindIndex(array, predicate, fromIndex, fromRight) { 12 | const { length } = array 13 | let index = fromIndex + (fromRight ? 1 : -1) 14 | 15 | while ((fromRight ? index-- : ++index < length)) { 16 | if (predicate(array[index], index, array)) { 17 | return index 18 | } 19 | } 20 | return -1 21 | } 22 | 23 | export default baseFindIndex 24 | -------------------------------------------------------------------------------- /isObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `value` is the 3 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) 4 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) 5 | * 6 | * @since 0.1.0 7 | * @category Lang 8 | * @param {*} value The value to check. 9 | * @returns {boolean} Returns `true` if `value` is an object, else `false`. 10 | * @example 11 | * 12 | * isObject({}) 13 | * // => true 14 | * 15 | * isObject([1, 2, 3]) 16 | * // => true 17 | * 18 | * isObject(Function) 19 | * // => true 20 | * 21 | * isObject(null) 22 | * // => false 23 | */ 24 | function isObject(value) { 25 | const type = typeof value 26 | return value != null && (type == 'object' || type == 'function') 27 | } 28 | 29 | export default isObject 30 | -------------------------------------------------------------------------------- /sumBy.js: -------------------------------------------------------------------------------- 1 | import baseSum from './.internal/baseSum.js' 2 | 3 | /** 4 | * This method is like `sum` except that it accepts `iteratee` which is 5 | * invoked for each element in `array` to generate the value to be summed. 6 | * The iteratee is invoked with one argument: (value). 7 | * 8 | * @since 4.0.0 9 | * @category Math 10 | * @param {Array} array The array to iterate over. 11 | * @param {Function} iteratee The iteratee invoked per element. 12 | * @returns {number} Returns the sum. 13 | * @example 14 | * 15 | * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }] 16 | * 17 | * sumBy(objects, ({ n }) => n) 18 | * // => 20 19 | */ 20 | function sumBy(array, iteratee) { 21 | return (array != null && array.length) 22 | ? baseSum(array, iteratee) 23 | : 0 24 | } 25 | 26 | export default sumBy 27 | -------------------------------------------------------------------------------- /toPath.js: -------------------------------------------------------------------------------- 1 | import map from './map.js' 2 | import copyArray from './.internal/copyArray.js' 3 | import isSymbol from './isSymbol.js' 4 | import stringToPath from './.internal/stringToPath.js' 5 | import toKey from './.internal/toKey.js' 6 | 7 | /** 8 | * Converts `value` to a property path array. 9 | * 10 | * @since 4.0.0 11 | * @category Util 12 | * @param {*} value The value to convert. 13 | * @returns {Array} Returns the new property path array. 14 | * @example 15 | * 16 | * toPath('a.b.c') 17 | * // => ['a', 'b', 'c'] 18 | * 19 | * toPath('a[0].b.c') 20 | * // => ['a', '0', 'b', 'c'] 21 | */ 22 | function toPath(value) { 23 | if (Array.isArray(value)) { 24 | return map(value, toKey) 25 | } 26 | return isSymbol(value) ? [value] : copyArray(stringToPath(value)) 27 | } 28 | 29 | export default toPath 30 | -------------------------------------------------------------------------------- /snakeCase.js: -------------------------------------------------------------------------------- 1 | import words from './words.js' 2 | 3 | /** 4 | * Converts `string` to 5 | * [snake case](https://en.wikipedia.org/wiki/Snake_case). 6 | * 7 | * @since 3.0.0 8 | * @category String 9 | * @param {string} [string=''] The string to convert. 10 | * @returns {string} Returns the snake cased string. 11 | * @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst 12 | * @example 13 | * 14 | * snakeCase('Foo Bar') 15 | * // => 'foo_bar' 16 | * 17 | * snakeCase('fooBar') 18 | * // => 'foo_bar' 19 | * 20 | * snakeCase('--FOO-BAR--') 21 | * // => 'foo_bar' 22 | */ 23 | const snakeCase = (string) => ( 24 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( 25 | result + (index ? '_' : '') + word.toLowerCase() 26 | ), '') 27 | ) 28 | 29 | export default snakeCase 30 | -------------------------------------------------------------------------------- /.internal/getSymbols.js: -------------------------------------------------------------------------------- 1 | import filter from '../filter.js' 2 | 3 | /** Built-in value references. */ 4 | const propertyIsEnumerable = Object.prototype.propertyIsEnumerable 5 | 6 | /* Built-in method references for those with the same name as other `lodash` methods. */ 7 | const nativeGetSymbols = Object.getOwnPropertySymbols 8 | 9 | /** 10 | * Creates an array of the own enumerable symbols of `object`. 11 | * 12 | * @private 13 | * @param {Object} object The object to query. 14 | * @returns {Array} Returns the array of symbols. 15 | */ 16 | const getSymbols = !nativeGetSymbols ? () => [] : (object) => { 17 | if (object == null) { 18 | return [] 19 | } 20 | object = Object(object) 21 | return filter(nativeGetSymbols(object), (symbol) => propertyIsEnumerable.call(object, symbol)) 22 | } 23 | 24 | export default getSymbols 25 | -------------------------------------------------------------------------------- /defaultsDeep.js: -------------------------------------------------------------------------------- 1 | import customDefaultsMerge from './.internal/customDefaultsMerge.js' 2 | import mergeWith from './mergeWith.js' 3 | 4 | /** 5 | * This method is like `defaults` except that it recursively assigns 6 | * default properties. 7 | * 8 | * **Note:** This method mutates `object`. 9 | * 10 | * @since 3.10.0 11 | * @category Object 12 | * @param {Object} object The destination object. 13 | * @param {...Object} [sources] The source objects. 14 | * @returns {Object} Returns `object`. 15 | * @see defaults 16 | * @example 17 | * 18 | * defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }) 19 | * // => { 'a': { 'b': 2, 'c': 3 } } 20 | */ 21 | function defaultsDeep(...args) { 22 | args.push(undefined, customDefaultsMerge) 23 | return mergeWith.apply(undefined, args) 24 | } 25 | 26 | export default defaultsDeep 27 | -------------------------------------------------------------------------------- /union.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | import baseUniq from './.internal/baseUniq.js' 3 | import isArrayLikeObject from './isArrayLikeObject.js' 4 | 5 | /** 6 | * Creates an array of unique values, in order, from all given arrays using 7 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 8 | * for equality comparisons. 9 | * 10 | * @since 0.1.0 11 | * @category Array 12 | * @param {...Array} [arrays] The arrays to inspect. 13 | * @returns {Array} Returns the new array of combined values. 14 | * @see difference, unionBy, unionWith, without, xor, xorBy 15 | * @example 16 | * 17 | * union([2], [1, 2]) 18 | * // => [2, 1] 19 | */ 20 | function union(...arrays) { 21 | return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)) 22 | } 23 | 24 | export default union 25 | -------------------------------------------------------------------------------- /.internal/arrayReduceRight.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `reduceRight` for arrays. 3 | * 4 | * @private 5 | * @param {Array} [array] The array to iterate over. 6 | * @param {Function} iteratee The function invoked per iteration. 7 | * @param {*} [accumulator] The initial value. 8 | * @param {boolean} [initAccum] Specify using the last element of `array` as 9 | * the initial value. 10 | * @returns {*} Returns the accumulated value. 11 | */ 12 | function arrayReduceRight(array, iteratee, accumulator, initAccum) { 13 | let length = array == null ? 0 : array.length 14 | if (initAccum && length) { 15 | accumulator = array[--length] 16 | } 17 | while (length--) { 18 | accumulator = iteratee(accumulator, array[length], length, array) 19 | } 20 | return accumulator 21 | } 22 | 23 | export default arrayReduceRight 24 | -------------------------------------------------------------------------------- /clamp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Clamps `number` within the inclusive `lower` and `upper` bounds. 3 | * 4 | * @since 4.0.0 5 | * @category Number 6 | * @param {number} number The number to clamp. 7 | * @param {number} lower The lower bound. 8 | * @param {number} upper The upper bound. 9 | * @returns {number} Returns the clamped number. 10 | * @example 11 | * 12 | * clamp(-10, -5, 5) 13 | * // => -5 14 | * 15 | * clamp(10, -5, 5) 16 | * // => 5 17 | */ 18 | function clamp(number, lower, upper) { 19 | number = +number 20 | lower = +lower 21 | upper = +upper 22 | lower = lower === lower ? lower : 0 23 | upper = upper === upper ? upper : 0 24 | if (number === number) { 25 | number = number <= upper ? number : upper 26 | number = number >= lower ? number : lower 27 | } 28 | return number 29 | } 30 | 31 | export default clamp 32 | -------------------------------------------------------------------------------- /method.js: -------------------------------------------------------------------------------- 1 | import invoke from './invoke.js' 2 | 3 | /** 4 | * Creates a function that invokes the method at `path` of a given object. 5 | * Any additional arguments are provided to the invoked method. 6 | * 7 | * @since 3.7.0 8 | * @category Util 9 | * @param {Array|string} path The path of the method to invoke. 10 | * @param {Array} [args] The arguments to invoke the method with. 11 | * @returns {Function} Returns the new invoker function. 12 | * @example 13 | * 14 | * const objects = [ 15 | * { 'a': { 'b': () => 2 } }, 16 | * { 'a': { 'b': () => 1 } } 17 | * ] 18 | * 19 | * map(objects, method('a.b')) 20 | * // => [2, 1] 21 | * 22 | * map(objects, method(['a', 'b'])) 23 | * // => [2, 1] 24 | */ 25 | function method(path, args) { 26 | return (object) => invoke(object, path, args) 27 | } 28 | 29 | export default method 30 | -------------------------------------------------------------------------------- /.internal/baseConformsTo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `conformsTo` which accepts `props` to check. 3 | * 4 | * @private 5 | * @param {Object} object The object to inspect. 6 | * @param {Object} source The object of property predicates to conform to. 7 | * @returns {boolean} Returns `true` if `object` conforms, else `false`. 8 | */ 9 | function baseConformsTo(object, source, props) { 10 | let length = props.length 11 | if (object == null) { 12 | return !length 13 | } 14 | object = Object(object) 15 | while (length--) { 16 | const key = props[length] 17 | const predicate = source[key] 18 | const value = object[key] 19 | 20 | if ((value === undefined && !(key in object)) || !predicate(value)) { 21 | return false 22 | } 23 | } 24 | return true 25 | } 26 | 27 | export default baseConformsTo 28 | -------------------------------------------------------------------------------- /.internal/baseSortedUniq.js: -------------------------------------------------------------------------------- 1 | import eq from '../eq.js' 2 | 3 | /** 4 | * The base implementation of `sortedUniq` and `sortedUniqBy`. 5 | * 6 | * @private 7 | * @param {Array} array The array to inspect. 8 | * @param {Function} [iteratee] The iteratee invoked per element. 9 | * @returns {Array} Returns the new duplicate free array. 10 | */ 11 | function baseSortedUniq(array, iteratee) { 12 | let seen 13 | let index = -1 14 | let resIndex = 0 15 | 16 | const { length } = array 17 | const result = [] 18 | 19 | while (++index < length) { 20 | const value = array[index], computed = iteratee ? iteratee(value) : value 21 | if (!index || !eq(computed, seen)) { 22 | seen = computed 23 | result[resIndex++] = value === 0 ? 0 : value 24 | } 25 | } 26 | return result 27 | } 28 | 29 | export default baseSortedUniq 30 | -------------------------------------------------------------------------------- /isArrayLikeObject.js: -------------------------------------------------------------------------------- 1 | import isArrayLike from './isArrayLike.js' 2 | import isObjectLike from './isObjectLike.js' 3 | 4 | /** 5 | * This method is like `isArrayLike` except that it also checks if `value` 6 | * is an object. 7 | * 8 | * @since 4.0.0 9 | * @category Lang 10 | * @param {*} value The value to check. 11 | * @returns {boolean} Returns `true` if `value` is an array-like object, 12 | * else `false`. 13 | * @example 14 | * 15 | * isArrayLikeObject([1, 2, 3]) 16 | * // => true 17 | * 18 | * isArrayLikeObject(document.body.children) 19 | * // => true 20 | * 21 | * isArrayLikeObject('abc') 22 | * // => false 23 | * 24 | * isArrayLikeObject(Function) 25 | * // => false 26 | */ 27 | function isArrayLikeObject(value) { 28 | return isObjectLike(value) && isArrayLike(value) 29 | } 30 | 31 | export default isArrayLikeObject 32 | -------------------------------------------------------------------------------- /kebabCase.js: -------------------------------------------------------------------------------- 1 | import words from './words.js' 2 | 3 | /** 4 | * Converts `string` to 5 | * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). 6 | * 7 | * @since 3.0.0 8 | * @category String 9 | * @param {string} [string=''] The string to convert. 10 | * @returns {string} Returns the kebab cased string. 11 | * @see camelCase, lowerCase, snakeCase, startCase, upperCase, upperFirst 12 | * @example 13 | * 14 | * kebabCase('Foo Bar') 15 | * // => 'foo-bar' 16 | * 17 | * kebabCase('fooBar') 18 | * // => 'foo-bar' 19 | * 20 | * kebabCase('__FOO_BAR__') 21 | * // => 'foo-bar' 22 | */ 23 | const kebabCase = (string) => ( 24 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( 25 | result + (index ? '-' : '') + word.toLowerCase() 26 | ), '') 27 | ) 28 | 29 | export default kebabCase 30 | -------------------------------------------------------------------------------- /takeRight.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Creates a slice of `array` with `n` elements taken from the end. 5 | * 6 | * @since 3.0.0 7 | * @category Array 8 | * @param {Array} array The array to query. 9 | * @param {number} [n=1] The number of elements to take. 10 | * @returns {Array} Returns the slice of `array`. 11 | * @example 12 | * 13 | * takeRight([1, 2, 3]) 14 | * // => [3] 15 | * 16 | * takeRight([1, 2, 3], 2) 17 | * // => [2, 3] 18 | * 19 | * takeRight([1, 2, 3], 5) 20 | * // => [1, 2, 3] 21 | * 22 | * takeRight([1, 2, 3], 0) 23 | * // => [] 24 | */ 25 | function takeRight(array, n=1) { 26 | const length = array == null ? 0 : array.length 27 | if (!length) { 28 | return [] 29 | } 30 | n = length - n 31 | return slice(array, n < 0 ? 0 : n, length) 32 | } 33 | 34 | export default takeRight 35 | -------------------------------------------------------------------------------- /.internal/arrayReduce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A specialized version of `reduce` for arrays. 3 | * 4 | * @private 5 | * @param {Array} [array] The array to iterate over. 6 | * @param {Function} iteratee The function invoked per iteration. 7 | * @param {*} [accumulator] The initial value. 8 | * @param {boolean} [initAccum] Specify using the first element of `array` as 9 | * the initial value. 10 | * @returns {*} Returns the accumulated value. 11 | */ 12 | function arrayReduce(array, iteratee, accumulator, initAccum) { 13 | let index = -1 14 | const length = array == null ? 0 : array.length 15 | 16 | if (initAccum && length) { 17 | accumulator = array[++index] 18 | } 19 | while (++index < length) { 20 | accumulator = iteratee(accumulator, array[index], index, array) 21 | } 22 | return accumulator 23 | } 24 | 25 | export default arrayReduce 26 | -------------------------------------------------------------------------------- /toPlainObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts `value` to a plain object flattening inherited enumerable string 3 | * keyed properties of `value` to own properties of the plain object. 4 | * 5 | * @since 3.0.0 6 | * @category Lang 7 | * @param {*} value The value to convert. 8 | * @returns {Object} Returns the converted plain object. 9 | * @example 10 | * 11 | * function Foo() { 12 | * this.b = 2 13 | * } 14 | * 15 | * Foo.prototype.c = 3 16 | * 17 | * assign({ 'a': 1 }, new Foo) 18 | * // => { 'a': 1, 'b': 2 } 19 | * 20 | * assign({ 'a': 1 }, toPlainObject(new Foo)) 21 | * // => { 'a': 1, 'b': 2, 'c': 3 } 22 | */ 23 | function toPlainObject(value) { 24 | value = Object(value) 25 | const result = {} 26 | for (const key in value) { 27 | result[key] = value[value] 28 | } 29 | return result 30 | } 31 | 32 | export default toPlainObject 33 | -------------------------------------------------------------------------------- /xor.js: -------------------------------------------------------------------------------- 1 | import filter from './filter.js' 2 | import baseXor from './.internal/baseXor.js' 3 | import isArrayLikeObject from './isArrayLikeObject.js' 4 | 5 | /** 6 | * Creates an array of unique values that is the 7 | * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) 8 | * of the given arrays. The order of result values is determined by the order 9 | * they occur in the arrays. 10 | * 11 | * @since 2.4.0 12 | * @category Array 13 | * @param {...Array} [arrays] The arrays to inspect. 14 | * @returns {Array} Returns the new array of filtered values. 15 | * @see difference, union, unionBy, unionWith, without, xorBy, xorWith 16 | * @example 17 | * 18 | * xor([2, 1], [2, 3]) 19 | * // => [1, 3] 20 | */ 21 | function xor(...arrays) { 22 | return baseXor(filter(arrays, isArrayLikeObject)) 23 | } 24 | 25 | export default xor 26 | -------------------------------------------------------------------------------- /map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an array of values by running each element of `array` thru `iteratee`. 3 | * The iteratee is invoked with three arguments: (value, index, array). 4 | * 5 | * @since 5.0.0 6 | * @category Array 7 | * @param {Array} array The array to iterate over. 8 | * @param {Function} iteratee The function invoked per iteration. 9 | * @returns {Array} Returns the new mapped array. 10 | * @example 11 | * 12 | * function square(n) { 13 | * return n * n 14 | * } 15 | * 16 | * map([4, 8], square) 17 | * // => [16, 64] 18 | */ 19 | function map(array, iteratee) { 20 | let index = -1 21 | const length = array == null ? 0 : array.length 22 | const result = new Array(length) 23 | 24 | while (++index < length) { 25 | result[index] = iteratee(array[index], index, array) 26 | } 27 | return result 28 | } 29 | 30 | export default map 31 | -------------------------------------------------------------------------------- /.internal/createCaseFirst.js: -------------------------------------------------------------------------------- 1 | import castSlice from './castSlice.js' 2 | import hasUnicode from './hasUnicode.js' 3 | import stringToArray from './stringToArray.js' 4 | 5 | /** 6 | * Creates a function like `lowerFirst`. 7 | * 8 | * @private 9 | * @param {string} methodName The name of the `String` case method to use. 10 | * @returns {Function} Returns the new case function. 11 | */ 12 | function createCaseFirst(methodName) { 13 | return (string) => { 14 | const strSymbols = hasUnicode(string) 15 | ? stringToArray(string) 16 | : undefined 17 | 18 | const chr = strSymbols 19 | ? strSymbols[0] 20 | : string[0] 21 | 22 | const trailing = strSymbols 23 | ? castSlice(strSymbols, 1).join('') 24 | : string.slice(1) 25 | 26 | return chr[methodName]() + trailing 27 | } 28 | } 29 | 30 | export default createCaseFirst 31 | -------------------------------------------------------------------------------- /sortedIndexOf.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndex from './.internal/baseSortedIndex.js' 2 | import eq from './eq.js' 3 | 4 | /** 5 | * This method is like `indexOf` except that it performs a binary 6 | * search on a sorted `array`. 7 | * 8 | * @since 4.0.0 9 | * @category Array 10 | * @param {Array} array The array to inspect. 11 | * @param {*} value The value to search for. 12 | * @returns {number} Returns the index of the matched value, else `-1`. 13 | * @example 14 | * 15 | * sortedIndexOf([4, 5, 5, 5, 6], 5) 16 | * // => 1 17 | */ 18 | function sortedIndexOf(array, value) { 19 | const length = array == null ? 0 : array.length 20 | if (length) { 21 | const index = baseSortedIndex(array, value) 22 | if (index < length && eq(array[index], value)) { 23 | return index 24 | } 25 | } 26 | return -1 27 | } 28 | 29 | export default sortedIndexOf 30 | -------------------------------------------------------------------------------- /.internal/isIndex.js: -------------------------------------------------------------------------------- 1 | /** Used as references for various `Number` constants. */ 2 | const MAX_SAFE_INTEGER = 9007199254740991 3 | 4 | /** Used to detect unsigned integer values. */ 5 | const reIsUint = /^(?:0|[1-9]\d*)$/ 6 | 7 | /** 8 | * Checks if `value` is a valid array-like index. 9 | * 10 | * @private 11 | * @param {*} value The value to check. 12 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. 13 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. 14 | */ 15 | function isIndex(value, length) { 16 | const type = typeof value 17 | length = length == null ? MAX_SAFE_INTEGER : length 18 | 19 | return !!length && 20 | (type == 'number' || 21 | (type != 'symbol' && reIsUint.test(value))) && 22 | (value > -1 && value % 1 == 0 && value < length) 23 | } 24 | 25 | export default isIndex 26 | -------------------------------------------------------------------------------- /castArray.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Casts `value` as an array if it's not one. 4 | * 5 | * @since 4.4.0 6 | * @category Lang 7 | * @param {*} value The value to inspect. 8 | * @returns {Array} Returns the cast array. 9 | * @example 10 | * 11 | * castArray(1) 12 | * // => [1] 13 | * 14 | * castArray({ 'a': 1 }) 15 | * // => [{ 'a': 1 }] 16 | * 17 | * castArray('abc') 18 | * // => ['abc'] 19 | * 20 | * castArray(null) 21 | * // => [null] 22 | * 23 | * castArray(undefined) 24 | * // => [undefined] 25 | * 26 | * castArray() 27 | * // => [] 28 | * 29 | * const array = [1, 2, 3] 30 | * console.log(castArray(array) === array) 31 | * // => true 32 | */ 33 | function castArray(...args) { 34 | if (!args.length) { 35 | return [] 36 | } 37 | const value = args[0] 38 | return Array.isArray(value) ? value : [value] 39 | } 40 | 41 | export default castArray 42 | -------------------------------------------------------------------------------- /values.js: -------------------------------------------------------------------------------- 1 | import baseValues from './.internal/baseValues.js' 2 | import keys from './keys.js' 3 | 4 | /** 5 | * Creates an array of the own enumerable string keyed property values of `object`. 6 | * 7 | * **Note:** Non-object values are coerced to objects. 8 | * 9 | * @since 0.1.0 10 | * @category Object 11 | * @param {Object} object The object to query. 12 | * @returns {Array} Returns the array of property values. 13 | * @see keys, valuesIn 14 | * @example 15 | * 16 | * function Foo() { 17 | * this.a = 1 18 | * this.b = 2 19 | * } 20 | * 21 | * Foo.prototype.c = 3 22 | * 23 | * values(new Foo) 24 | * // => [1, 2] (iteration order is not guaranteed) 25 | * 26 | * values('hi') 27 | * // => ['h', 'i'] 28 | */ 29 | function values(object) { 30 | return object == null ? [] : baseValues(object, keys(object)) 31 | } 32 | 33 | export default values 34 | -------------------------------------------------------------------------------- /.internal/basePickBy.js: -------------------------------------------------------------------------------- 1 | import baseGet from './baseGet.js' 2 | import baseSet from './baseSet.js' 3 | import castPath from './castPath.js' 4 | 5 | /** 6 | * The base implementation of `pickBy`. 7 | * 8 | * @private 9 | * @param {Object} object The source object. 10 | * @param {string[]} paths The property paths to pick. 11 | * @param {Function} predicate The function invoked per property. 12 | * @returns {Object} Returns the new object. 13 | */ 14 | function basePickBy(object, paths, predicate) { 15 | let index = -1 16 | const length = paths.length 17 | const result = {} 18 | 19 | while (++index < length) { 20 | const path = paths[index] 21 | const value = baseGet(object, path) 22 | if (predicate(value, path)) { 23 | baseSet(result, castPath(path, object), value) 24 | } 25 | } 26 | return result 27 | } 28 | 29 | export default basePickBy 30 | -------------------------------------------------------------------------------- /.internal/nodeUtil.js: -------------------------------------------------------------------------------- 1 | import freeGlobal from './freeGlobal.js' 2 | 3 | /** Detect free variable `exports`. */ 4 | const freeExports = typeof exports == 'object' && exports !== null && !exports.nodeType && exports 5 | 6 | /** Detect free variable `module`. */ 7 | const freeModule = freeExports && typeof module == 'object' && module !== null && !module.nodeType && module 8 | 9 | /** Detect the popular CommonJS extension `module.exports`. */ 10 | const moduleExports = freeModule && freeModule.exports === freeExports 11 | 12 | /** Detect free variable `process` from Node.js. */ 13 | const freeProcess = moduleExports && freeGlobal.process 14 | 15 | /** Used to access faster Node.js helpers. */ 16 | const nodeUtil = ((() => { 17 | try { 18 | return freeProcess && freeProcess.binding && freeProcess.binding('util') 19 | } catch (e) {} 20 | })()) 21 | 22 | export default nodeUtil 23 | -------------------------------------------------------------------------------- /pullAll.js: -------------------------------------------------------------------------------- 1 | import basePullAll from './.internal/basePullAll.js' 2 | 3 | /** 4 | * This method is like `pull` except that it accepts an array of values to remove. 5 | * 6 | * **Note:** Unlike `difference`, this method mutates `array`. 7 | * 8 | * @since 4.0.0 9 | * @category Array 10 | * @param {Array} array The array to modify. 11 | * @param {Array} values The values to remove. 12 | * @returns {Array} Returns `array`. 13 | * @see pull, pullAllBy, pullAllWith, pullAt, remove, reject 14 | * @example 15 | * 16 | * const array = ['a', 'b', 'c', 'a', 'b', 'c'] 17 | * 18 | * pullAll(array, ['a', 'c']) 19 | * console.log(array) 20 | * // => ['b', 'b'] 21 | */ 22 | function pullAll(array, values) { 23 | return (array != null && array.length && values != null && values.length) 24 | ? basePullAll(array, values) 25 | : array 26 | } 27 | 28 | export default pullAll 29 | -------------------------------------------------------------------------------- /sortedLastIndexOf.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndex from './.internal/baseSortedIndex.js' 2 | import eq from './eq.js' 3 | 4 | /** 5 | * This method is like `lastIndexOf` except that it performs a binary 6 | * search on a sorted `array`. 7 | * 8 | * @since 4.0.0 9 | * @category Array 10 | * @param {Array} array The array to inspect. 11 | * @param {*} value The value to search for. 12 | * @returns {number} Returns the index of the matched value, else `-1`. 13 | * @example 14 | * 15 | * sortedLastIndexOf([4, 5, 5, 5, 6], 5) 16 | * // => 3 17 | */ 18 | function sortedLastIndexOf(array, value) { 19 | const length = array == null ? 0 : array.length 20 | if (length) { 21 | const index = baseSortedIndex(array, value, true) - 1 22 | if (eq(array[index], value)) { 23 | return index 24 | } 25 | } 26 | return -1 27 | } 28 | 29 | export default sortedLastIndexOf 30 | -------------------------------------------------------------------------------- /isArrayLike.js: -------------------------------------------------------------------------------- 1 | import isLength from './isLength.js' 2 | 3 | /** 4 | * Checks if `value` is array-like. A value is considered array-like if it's 5 | * not a function and has a `value.length` that's an integer greater than or 6 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. 7 | * 8 | * @since 4.0.0 9 | * @category Lang 10 | * @param {*} value The value to check. 11 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`. 12 | * @example 13 | * 14 | * isArrayLike([1, 2, 3]) 15 | * // => true 16 | * 17 | * isArrayLike(document.body.children) 18 | * // => true 19 | * 20 | * isArrayLike('abc') 21 | * // => true 22 | * 23 | * isArrayLike(Function) 24 | * // => false 25 | */ 26 | function isArrayLike(value) { 27 | return value != null && typeof value != 'function' && isLength(value.length) 28 | } 29 | 30 | export default isArrayLike 31 | -------------------------------------------------------------------------------- /isArrayBuffer.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | import nodeUtil from './.internal/nodeUtil.js' 4 | 5 | /* Node.js helper references. */ 6 | const nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer 7 | 8 | /** 9 | * Checks if `value` is classified as an `ArrayBuffer` object. 10 | * 11 | * @since 4.3.0 12 | * @category Lang 13 | * @param {*} value The value to check. 14 | * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. 15 | * @example 16 | * 17 | * isArrayBuffer(new ArrayBuffer(2)) 18 | * // => true 19 | * 20 | * isArrayBuffer(new Array(2)) 21 | * // => false 22 | */ 23 | const isArrayBuffer = nodeIsArrayBuffer 24 | ? (value) => nodeIsArrayBuffer(value) 25 | : (value) => isObjectLike(value) && baseGetTag(value) == '[object ArrayBuffer]' 26 | 27 | export default isArrayBuffer 28 | -------------------------------------------------------------------------------- /.internal/createRound.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function like `round`. 3 | * 4 | * @private 5 | * @param {string} methodName The name of the `Math` method to use when rounding. 6 | * @returns {Function} Returns the new round function. 7 | */ 8 | function createRound(methodName) { 9 | const func = Math[methodName] 10 | return (number, precision) => { 11 | precision = precision == null ? 0 : Math.min(precision, 292) 12 | if (precision) { 13 | // Shift with exponential notation to avoid floating-point issues. 14 | // See [MDN](https://mdn.io/round#Examples) for more details. 15 | let pair = `${number}e`.split('e') 16 | const value = func(`${pair[0]}e${+pair[1] + precision}`) 17 | 18 | pair = `${value}e`.split('e') 19 | return +`${pair[0]}e${+pair[1] - precision}` 20 | } 21 | return func(number) 22 | } 23 | } 24 | 25 | export default createRound 26 | -------------------------------------------------------------------------------- /camelCase.js: -------------------------------------------------------------------------------- 1 | import capitalize from './capitalize.js' 2 | import words from './words.js' 3 | 4 | /** 5 | * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). 6 | * 7 | * @since 3.0.0 8 | * @category String 9 | * @param {string} [string=''] The string to convert. 10 | * @returns {string} Returns the camel cased string. 11 | * @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst 12 | * @example 13 | * 14 | * camelCase('Foo Bar') 15 | * // => 'fooBar' 16 | * 17 | * camelCase('--foo-bar--') 18 | * // => 'fooBar' 19 | * 20 | * camelCase('__FOO_BAR__') 21 | * // => 'fooBar' 22 | */ 23 | const camelCase = (string) => ( 24 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => { 25 | word = word.toLowerCase() 26 | return result + (index ? capitalize(word) : word) 27 | }, '') 28 | ) 29 | 30 | export default camelCase 31 | -------------------------------------------------------------------------------- /methodOf.js: -------------------------------------------------------------------------------- 1 | import invoke from './invoke.js' 2 | 3 | /** 4 | * The opposite of `method` this method creates a function that invokes 5 | * the method at a given path of `object`. Any additional arguments are 6 | * provided to the invoked method. 7 | * 8 | * @since 3.7.0 9 | * @category Util 10 | * @param {Object} object The object to query. 11 | * @param {Array} [args] The arguments to invoke the method with. 12 | * @returns {Function} Returns the new invoker function. 13 | * @example 14 | * 15 | * const array = times(3, i => () => i) 16 | * const object = { 'a': array, 'b': array, 'c': array } 17 | * 18 | * map(['a[2]', 'c[0]'], methodOf(object)) 19 | * // => [2, 0] 20 | * 21 | * map([['a', '2'], ['c', '0']], methodOf(object)) 22 | * // => [2, 0]f 23 | */ 24 | function methodOf(object, args) { 25 | return (path) => invoke(object, path, args) 26 | } 27 | 28 | export default methodOf 29 | -------------------------------------------------------------------------------- /eq.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Performs a 3 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 4 | * comparison between two values to determine if they are equivalent. 5 | * 6 | * @since 4.0.0 7 | * @category Lang 8 | * @param {*} value The value to compare. 9 | * @param {*} other The other value to compare. 10 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`. 11 | * @example 12 | * 13 | * const object = { 'a': 1 } 14 | * const other = { 'a': 1 } 15 | * 16 | * eq(object, object) 17 | * // => true 18 | * 19 | * eq(object, other) 20 | * // => false 21 | * 22 | * eq('a', 'a') 23 | * // => true 24 | * 25 | * eq('a', Object('a')) 26 | * // => false 27 | * 28 | * eq(NaN, NaN) 29 | * // => true 30 | */ 31 | function eq(value, other) { 32 | return value === other || (value !== value && other !== other) 33 | } 34 | 35 | export default eq 36 | -------------------------------------------------------------------------------- /flattenDepth.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | 3 | /** 4 | * Recursively flatten `array` up to `depth` times. 5 | * 6 | * @since 4.4.0 7 | * @category Array 8 | * @param {Array} array The array to flatten. 9 | * @param {number} [depth=1] The maximum recursion depth. 10 | * @returns {Array} Returns the new flattened array. 11 | * @see flatMap, flatMapDeep, flatMapDepth, flattenDeep 12 | * @example 13 | * 14 | * const array = [1, [2, [3, [4]], 5]] 15 | * 16 | * flattenDepth(array, 1) 17 | * // => [1, 2, [3, [4]], 5] 18 | * 19 | * flattenDepth(array, 2) 20 | * // => [1, 2, 3, [4], 5] 21 | */ 22 | function flattenDepth(array, depth) { 23 | const length = array == null ? 0 : array.length 24 | if (!length) { 25 | return [] 26 | } 27 | depth = depth === undefined ? 1 : +depth 28 | return baseFlatten(array, depth) 29 | } 30 | 31 | export default flattenDepth 32 | -------------------------------------------------------------------------------- /isLength.js: -------------------------------------------------------------------------------- 1 | /** Used as references for various `Number` constants. */ 2 | const MAX_SAFE_INTEGER = 9007199254740991 3 | 4 | /** 5 | * Checks if `value` is a valid array-like length. 6 | * 7 | * **Note:** This method is loosely based on 8 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 9 | * 10 | * @since 4.0.0 11 | * @category Lang 12 | * @param {*} value The value to check. 13 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. 14 | * @example 15 | * 16 | * isLength(3) 17 | * // => true 18 | * 19 | * isLength(Number.MIN_VALUE) 20 | * // => false 21 | * 22 | * isLength(Infinity) 23 | * // => false 24 | * 25 | * isLength('3') 26 | * // => false 27 | */ 28 | function isLength(value) { 29 | return typeof value == 'number' && 30 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER 31 | } 32 | 33 | export default isLength 34 | -------------------------------------------------------------------------------- /pull.js: -------------------------------------------------------------------------------- 1 | import pullAll from './pullAll.js' 2 | 3 | /** 4 | * Removes all given values from `array` using 5 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 6 | * for equality comparisons. 7 | * 8 | * **Note:** Unlike `without`, this method mutates `array`. Use `remove` 9 | * to remove elements from an array by predicate. 10 | * 11 | * @since 2.0.0 12 | * @category Array 13 | * @param {Array} array The array to modify. 14 | * @param {...*} [values] The values to remove. 15 | * @returns {Array} Returns `array`. 16 | * @see pullAll, pullAllBy, pullAllWith, pullAt, remove, reject 17 | * @example 18 | * 19 | * const array = ['a', 'b', 'c', 'a', 'b', 'c'] 20 | * 21 | * pull(array, 'a', 'c') 22 | * console.log(array) 23 | * // => ['b', 'b'] 24 | */ 25 | function pull(array, ...values) { 26 | return pullAll(array, values) 27 | } 28 | 29 | export default pull 30 | -------------------------------------------------------------------------------- /some.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `predicate` returns truthy for **any** element of `array`. 3 | * Iteration is stopped once `predicate` returns truthy. The predicate is 4 | * invoked with three arguments: (value, index, array). 5 | * 6 | * @since 5.0.0 7 | * @category Array 8 | * @param {Array} array The array to iterate over. 9 | * @param {Function} predicate The function invoked per iteration. 10 | * @returns {boolean} Returns `true` if any element passes the predicate check, 11 | * else `false`. 12 | * @example 13 | * 14 | * some([null, 0, 'yes', false], Boolean) 15 | * // => true 16 | */ 17 | function some(array, predicate) { 18 | let index = -1 19 | const length = array == null ? 0 : array.length 20 | 21 | while (++index < length) { 22 | if (predicate(array[index], index, array)) { 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | 29 | export default some 30 | -------------------------------------------------------------------------------- /startCase.js: -------------------------------------------------------------------------------- 1 | import upperFirst from './upperFirst.js' 2 | import words from './words.js' 3 | 4 | /** 5 | * Converts `string` to 6 | * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). 7 | * 8 | * @since 3.1.0 9 | * @category String 10 | * @param {string} [string=''] The string to convert. 11 | * @returns {string} Returns the start cased string. 12 | * @see camelCase, lowerCase, kebabCase, snakeCase, upperCase, upperFirst 13 | * @example 14 | * 15 | * startCase('--foo-bar--') 16 | * // => 'Foo Bar' 17 | * 18 | * startCase('fooBar') 19 | * // => 'Foo Bar' 20 | * 21 | * startCase('__FOO_BAR__') 22 | * // => 'FOO BAR' 23 | */ 24 | const startCase = (string) => ( 25 | words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( 26 | result + (index ? ' ' : '') + upperFirst(word) 27 | ), '') 28 | ) 29 | 30 | export default startCase 31 | -------------------------------------------------------------------------------- /.internal/baseEach.js: -------------------------------------------------------------------------------- 1 | import baseForOwn from './baseForOwn.js' 2 | import isArrayLike from '../isArrayLike.js' 3 | 4 | /** 5 | * The base implementation of `forEach`. 6 | * 7 | * @private 8 | * @param {Array|Object} collection The collection to iterate over. 9 | * @param {Function} iteratee The function invoked per iteration. 10 | * @returns {Array|Object} Returns `collection`. 11 | */ 12 | function baseEach(collection, iteratee) { 13 | if (collection == null) { 14 | return collection 15 | } 16 | if (!isArrayLike(collection)) { 17 | return baseForOwn(collection, iteratee) 18 | } 19 | const length = collection.length 20 | const iterable = Object(collection) 21 | let index = -1 22 | 23 | while (++index < length) { 24 | if (iteratee(iterable[index], index, iterable) === false) { 25 | break 26 | } 27 | } 28 | return collection 29 | } 30 | 31 | export default baseEach 32 | -------------------------------------------------------------------------------- /mapObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an array of values by running each property of `object` thru 3 | * `iteratee`. The iteratee is invoked with three arguments: (value, key, object). 4 | * 5 | * @since 5.0.0 6 | * @category Object 7 | * @param {Object} object The object to iterate over. 8 | * @param {Function} iteratee The function invoked per iteration. 9 | * @returns {Array} Returns the new mapped array. 10 | * @example 11 | * 12 | * function square(n) { 13 | * return n * n 14 | * } 15 | * 16 | * map({ 'a': 4, 'b': 8 }, square) 17 | * // => [16, 64] (iteration order is not guaranteed) 18 | */ 19 | function mapObject(object, iteratee) { 20 | const props = Object.keys(object) 21 | const result = new Array(props.length) 22 | 23 | props.forEach((key, index) => { 24 | result[index] = iteratee(object[key], key, object) 25 | }) 26 | return result 27 | } 28 | 29 | export default mapObject 30 | -------------------------------------------------------------------------------- /.internal/baseEachRight.js: -------------------------------------------------------------------------------- 1 | import baseForOwnRight from './baseForOwnRight.js' 2 | import isArrayLike from '../isArrayLike.js' 3 | 4 | /** 5 | * The base implementation of `forEachRight`. 6 | * 7 | * @private 8 | * @param {Array|Object} collection The collection to iterate over. 9 | * @param {Function} iteratee The function invoked per iteration. 10 | * @returns {Array|Object} Returns `collection`. 11 | */ 12 | function baseEachRight(collection, iteratee) { 13 | if (collection == null) { 14 | return collection 15 | } 16 | if (!isArrayLike(collection)) { 17 | return baseForOwnRight(collection, iteratee) 18 | } 19 | const iterable = Object(collection) 20 | let length = collection.length 21 | 22 | while (length--) { 23 | if (iteratee(iterable[length], length, iterable) === false) { 24 | break 25 | } 26 | } 27 | return collection 28 | } 29 | 30 | export default baseEachRight 31 | -------------------------------------------------------------------------------- /attempt.js: -------------------------------------------------------------------------------- 1 | import isError from './isError.js' 2 | 3 | /** 4 | * Attempts to invoke `func`, returning either the result or the caught error 5 | * object. Any additional arguments are provided to `func` when it's invoked. 6 | * 7 | * @since 3.0.0 8 | * @category Util 9 | * @param {Function} func The function to attempt. 10 | * @param {...*} [args] The arguments to invoke `func` with. 11 | * @returns {*} Returns the `func` result or error object. 12 | * @example 13 | * 14 | * // Avoid throwing errors for invalid selectors. 15 | * const elements = attempt(selector => 16 | * document.querySelectorAll(selector), '>_>') 17 | * 18 | * if (isError(elements)) { 19 | * elements = [] 20 | * } 21 | */ 22 | function attempt(func, ...args) { 23 | try { 24 | return func.apply(undefined, args) 25 | } catch (e) { 26 | return isError(e) ? e : new Error(e) 27 | } 28 | } 29 | 30 | export default attempt 31 | -------------------------------------------------------------------------------- /property.js: -------------------------------------------------------------------------------- 1 | import baseProperty from './.internal/baseProperty.js' 2 | import basePropertyDeep from './.internal/basePropertyDeep.js' 3 | import isKey from './.internal/isKey.js' 4 | import toKey from './.internal/toKey.js' 5 | 6 | /** 7 | * Creates a function that returns the value at `path` of a given object. 8 | * 9 | * @since 2.4.0 10 | * @category Util 11 | * @param {Array|string} path The path of the property to get. 12 | * @returns {Function} Returns the new accessor function. 13 | * @example 14 | * 15 | * const objects = [ 16 | * { 'a': { 'b': 2 } }, 17 | * { 'a': { 'b': 1 } } 18 | * ] 19 | * 20 | * map(objects, property('a.b')) 21 | * // => [2, 1] 22 | * 23 | * map(sortBy(objects, property(['a', 'b'])), 'a.b') 24 | * // => [1, 2] 25 | */ 26 | function property(path) { 27 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path) 28 | } 29 | 30 | export default property 31 | -------------------------------------------------------------------------------- /toInteger.js: -------------------------------------------------------------------------------- 1 | import toFinite from './toFinite.js' 2 | 3 | /** 4 | * Converts `value` to an integer. 5 | * 6 | * **Note:** This method is loosely based on 7 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). 8 | * 9 | * @since 4.0.0 10 | * @category Lang 11 | * @param {*} value The value to convert. 12 | * @returns {number} Returns the converted integer. 13 | * @see isInteger, isNumber, toNumber 14 | * @example 15 | * 16 | * toInteger(3.2) 17 | * // => 3 18 | * 19 | * toInteger(Number.MIN_VALUE) 20 | * // => 0 21 | * 22 | * toInteger(Infinity) 23 | * // => 1.7976931348623157e+308 24 | * 25 | * toInteger('3.2') 26 | * // => 3 27 | */ 28 | function toInteger(value) { 29 | const result = toFinite(value) 30 | const remainder = result % 1 31 | 32 | return result === result ? (remainder ? result - remainder : result) : 0 33 | } 34 | 35 | export default toInteger 36 | -------------------------------------------------------------------------------- /invert.js: -------------------------------------------------------------------------------- 1 | const toString = Object.prototype.toString 2 | 3 | /** 4 | * Creates an object composed of the inverted keys and values of `object`. 5 | * If `object` contains duplicate values, subsequent values overwrite 6 | * property assignments of previous values. 7 | * 8 | * @since 0.7.0 9 | * @category Object 10 | * @param {Object} object The object to invert. 11 | * @returns {Object} Returns the new inverted object. 12 | * @example 13 | * 14 | * const object = { 'a': 1, 'b': 2, 'c': 1 } 15 | * 16 | * invert(object) 17 | * // => { '1': 'c', '2': 'b' } 18 | */ 19 | function invert(object) { 20 | const result = {} 21 | Object.keys(object).forEach((key) => { 22 | let value = object[key] 23 | if (value != null && typeof value.toString != 'function') { 24 | value = toString.call(value) 25 | } 26 | result[value] = key 27 | }) 28 | return result 29 | } 30 | 31 | export default invert 32 | -------------------------------------------------------------------------------- /without.js: -------------------------------------------------------------------------------- 1 | import baseDifference from './.internal/baseDifference.js' 2 | import isArrayLikeObject from './isArrayLikeObject.js' 3 | 4 | /** 5 | * Creates an array excluding all given values using 6 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 7 | * for equality comparisons. 8 | * 9 | * **Note:** Unlike `pull`, this method returns a new array. 10 | * 11 | * @since 0.1.0 12 | * @category Array 13 | * @param {Array} array The array to inspect. 14 | * @param {...*} [values] The values to exclude. 15 | * @returns {Array} Returns the new array of filtered values. 16 | * @see difference, union, unionBy, unionWith, xor, xorBy, xorWith 17 | * @example 18 | * 19 | * without([2, 1, 2, 3], 1, 2) 20 | * // => [3] 21 | */ 22 | function without(array, ...values) { 23 | return isArrayLikeObject(array) ? baseDifference(array, values) : [] 24 | } 25 | 26 | export default without 27 | -------------------------------------------------------------------------------- /uniqBy.js: -------------------------------------------------------------------------------- 1 | import baseUniq from './.internal/baseUniq.js' 2 | 3 | /** 4 | * This method is like `uniq` except that it accepts `iteratee` which is 5 | * invoked for each element in `array` to generate the criterion by which 6 | * uniqueness is computed. The order of result values is determined by the 7 | * order they occur in the array. The iteratee is invoked with one argument: 8 | * (value). 9 | * 10 | * @since 4.0.0 11 | * @category Array 12 | * @param {Array} array The array to inspect. 13 | * @param {Function} iteratee The iteratee invoked per element. 14 | * @returns {Array} Returns the new duplicate free array. 15 | * @see uniq, uniqWith 16 | * @example 17 | * 18 | * uniqBy([2.1, 1.2, 2.3], Math.floor) 19 | * // => [2.1, 1.2] 20 | */ 21 | function uniqBy(array, iteratee) { 22 | return (array != null && array.length) 23 | ? baseUniq(array, iteratee) 24 | : [] 25 | } 26 | 27 | export default uniqBy 28 | -------------------------------------------------------------------------------- /forEachRight.js: -------------------------------------------------------------------------------- 1 | import arrayEachRight from './.internal/arrayEachRight.js' 2 | import baseEachRight from './.internal/baseEachRight.js' 3 | 4 | /** 5 | * This method is like `forEach` except that it iterates over elements of 6 | * `collection` from right to left. 7 | * 8 | * @since 2.0.0 9 | * @alias eachRight 10 | * @category Collection 11 | * @param {Array|Object} collection The collection to iterate over. 12 | * @param {Function} iteratee The function invoked per iteration. 13 | * @returns {Array|Object} Returns `collection`. 14 | * @see forEach, forIn, forInRight, forOwn, forOwnRight 15 | * @example 16 | * 17 | * forEachRight([1, 2], value => console.log(value)) 18 | * // => Logs `2` then `1`. 19 | */ 20 | function forEachRight(collection, iteratee) { 21 | const func = Array.isArray(collection) ? arrayEachRight : baseEachRight 22 | return func(collection, iteratee) 23 | } 24 | 25 | export default forEachRight 26 | -------------------------------------------------------------------------------- /escapeRegExp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Used to match `RegExp` 3 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). 4 | */ 5 | const reRegExpChar = /[\\^$.*+?()[\]{}|]/g 6 | const reHasRegExpChar = RegExp(reRegExpChar.source) 7 | 8 | /** 9 | * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", 10 | * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. 11 | * 12 | * @since 3.0.0 13 | * @category String 14 | * @param {string} [string=''] The string to escape. 15 | * @returns {string} Returns the escaped string. 16 | * @see escape, escapeRegExp, unescape 17 | * @example 18 | * 19 | * escapeRegExp('[lodash](https://lodash.com/)') 20 | * // => '\[lodash\]\(https://lodash\.com/\)' 21 | */ 22 | function escapeRegExp(string) { 23 | return (string && reHasRegExpChar.test(string)) 24 | ? string.replace(reRegExpChar, '\\$&') 25 | : string 26 | } 27 | 28 | export default escapeRegExp 29 | -------------------------------------------------------------------------------- /someValue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `predicate` returns truthy for **any** element of `object`. 3 | * Iteration is stopped once `predicate` returns truthy. The predicate is 4 | * invoked with three arguments: (value, key, object). 5 | * 6 | * @since 5.0.0 7 | * @category Object 8 | * @param {Object} object The object to iterate over. 9 | * @param {Function} predicate The function invoked per iteration. 10 | * @returns {boolean} Returns `true` if any element passes the predicate check, 11 | * else `false`. 12 | * @example 13 | * 14 | * someValues({ 'a': 0, 'b': 'yes', 'c': false }, Boolean) 15 | * // => true 16 | */ 17 | function someValues(object, predicate) { 18 | object = Object(object) 19 | const props = Object.keys(object) 20 | 21 | for (const key of props) { 22 | if (predicate(object[key], key, object)) { 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | 29 | export default someValues 30 | -------------------------------------------------------------------------------- /.internal/assignValue.js: -------------------------------------------------------------------------------- 1 | import baseAssignValue from './baseAssignValue.js' 2 | import eq from '../eq.js' 3 | 4 | /** Used to check objects for own properties. */ 5 | const hasOwnProperty = Object.prototype.hasOwnProperty 6 | 7 | /** 8 | * Assigns `value` to `key` of `object` if the existing value is not equivalent 9 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 10 | * for equality comparisons. 11 | * 12 | * @private 13 | * @param {Object} object The object to modify. 14 | * @param {string} key The key of the property to assign. 15 | * @param {*} value The value to assign. 16 | */ 17 | function assignValue(object, key, value) { 18 | const objValue = object[key] 19 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || 20 | (value === undefined && !(key in object))) { 21 | baseAssignValue(object, key, value) 22 | } 23 | } 24 | 25 | export default assignValue 26 | -------------------------------------------------------------------------------- /.internal/basePullAt.js: -------------------------------------------------------------------------------- 1 | import baseUnset from './baseUnset.js' 2 | import isIndex from './isIndex.js' 3 | 4 | /** 5 | * The base implementation of `pullAt` without support for individual 6 | * indexes or capturing the removed elements. 7 | * 8 | * @private 9 | * @param {Array} array The array to modify. 10 | * @param {number[]} indexes The indexes of elements to remove. 11 | * @returns {Array} Returns `array`. 12 | */ 13 | function basePullAt(array, indexes) { 14 | let length = array ? indexes.length : 0 15 | const lastIndex = length - 1 16 | 17 | while (length--) { 18 | let previous 19 | const index = indexes[length] 20 | if (length == lastIndex || index !== previous) { 21 | previous = index 22 | if (isIndex(index)) { 23 | array.splice(index, 1) 24 | } else { 25 | baseUnset(array, index) 26 | } 27 | } 28 | } 29 | return array 30 | } 31 | 32 | export default basePullAt 33 | -------------------------------------------------------------------------------- /unset.js: -------------------------------------------------------------------------------- 1 | import baseUnset from './.internal/baseUnset.js' 2 | 3 | /** 4 | * Removes the property at `path` of `object`. 5 | * 6 | * **Note:** This method mutates `object`. 7 | * 8 | * @since 4.0.0 9 | * @category Object 10 | * @param {Object} object The object to modify. 11 | * @param {Array|string} path The path of the property to unset. 12 | * @returns {boolean} Returns `true` if the property is deleted, else `false`. 13 | * @see get, has, set 14 | * @example 15 | * 16 | * const object = { 'a': [{ 'b': { 'c': 7 } }] } 17 | * unset(object, 'a[0].b.c') 18 | * // => true 19 | * 20 | * console.log(object) 21 | * // => { 'a': [{ 'b': {} }] } 22 | * 23 | * unset(object, ['a', '0', 'b', 'c']) 24 | * // => true 25 | * 26 | * console.log(object) 27 | * // => { 'a': [{ 'b': {} }] } 28 | */ 29 | function unset(object, path) { 30 | return object == null ? true : baseUnset(object, path) 31 | } 32 | 33 | export default unset 34 | -------------------------------------------------------------------------------- /.internal/baseFor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `baseForOwn` which iterates over `object` 3 | * properties returned by `keysFunc` and invokes `iteratee` for each property. 4 | * Iteratee functions may exit iteration early by explicitly returning `false`. 5 | * 6 | * @private 7 | * @param {Object} object The object to iterate over. 8 | * @param {Function} iteratee The function invoked per iteration. 9 | * @param {Function} keysFunc The function to get the keys of `object`. 10 | * @returns {Object} Returns `object`. 11 | */ 12 | function baseFor(object, iteratee, keysFunc) { 13 | const iterable = Object(object) 14 | const props = keysFunc(object) 15 | let { length } = props 16 | let index = -1 17 | 18 | while (length--) { 19 | const key = props[++index] 20 | if (iteratee(iterable[key], key, iterable) === false) { 21 | break 22 | } 23 | } 24 | return object 25 | } 26 | 27 | export default baseFor 28 | -------------------------------------------------------------------------------- /.internal/isKey.js: -------------------------------------------------------------------------------- 1 | import isSymbol from '../isSymbol.js' 2 | 3 | /** Used to match property names within property paths. */ 4 | const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/ 5 | const reIsPlainProp = /^\w*$/ 6 | 7 | /** 8 | * Checks if `value` is a property name and not a property path. 9 | * 10 | * @private 11 | * @param {*} value The value to check. 12 | * @param {Object} [object] The object to query keys on. 13 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`. 14 | */ 15 | function isKey(value, object) { 16 | if (Array.isArray(value)) { 17 | return false 18 | } 19 | const type = typeof value 20 | if (type == 'number' || type == 'boolean' || value == null || isSymbol(value)) { 21 | return true 22 | } 23 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || 24 | (object != null && value in Object(object)) 25 | } 26 | 27 | export default isKey 28 | -------------------------------------------------------------------------------- /meanBy.js: -------------------------------------------------------------------------------- 1 | import baseSum from './.internal/baseSum.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const NAN = 0 / 0 5 | 6 | /** 7 | * This method is like `mean` except that it accepts `iteratee` which is 8 | * invoked for each element in `array` to generate the value to be averaged. 9 | * The iteratee is invoked with one argument: (value). 10 | * 11 | * @since 4.7.0 12 | * @category Math 13 | * @param {Array} array The array to iterate over. 14 | * @param {Function} iteratee The iteratee invoked per element. 15 | * @returns {number} Returns the mean. 16 | * @example 17 | * 18 | * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }] 19 | * 20 | * meanBy(objects, ({ n }) => n) 21 | * // => 5 22 | */ 23 | function meanBy(array, iteratee) { 24 | const length = array == null ? 0 : array.length 25 | return length ? (baseSum(array, iteratee) / length) : NAN 26 | } 27 | 28 | export default meanBy 29 | -------------------------------------------------------------------------------- /sortedIndexBy.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndexBy from './.internal/baseSortedIndexBy.js' 2 | 3 | /** 4 | * This method is like `sortedIndex` except that it accepts `iteratee` 5 | * which is invoked for `value` and each element of `array` to compute their 6 | * sort ranking. The iteratee is invoked with one argument: (value). 7 | * 8 | * @since 4.0.0 9 | * @category Array 10 | * @param {Array} array The sorted array to inspect. 11 | * @param {*} value The value to evaluate. 12 | * @param {Function} iteratee The iteratee invoked per element. 13 | * @returns {number} Returns the index at which `value` should be inserted 14 | * into `array`. 15 | * @example 16 | * 17 | * const objects = [{ 'n': 4 }, { 'n': 5 }] 18 | * 19 | * sortedIndexBy(objects, { 'n': 4 }, ({ n }) => n) 20 | * // => 0 21 | */ 22 | function sortedIndexBy(array, value, iteratee) { 23 | return baseSortedIndexBy(array, value, iteratee) 24 | } 25 | 26 | export default sortedIndexBy 27 | -------------------------------------------------------------------------------- /.internal/baseReduce.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The base implementation of `reduce` and `reduceRight` which iterates 3 | * over `collection` using `eachFunc`. 4 | * 5 | * @private 6 | * @param {Array|Object} collection The collection to iterate over. 7 | * @param {Function} iteratee The function invoked per iteration. 8 | * @param {*} accumulator The initial value. 9 | * @param {boolean} initAccum Specify using the first or last element of 10 | * `collection` as the initial value. 11 | * @param {Function} eachFunc The function to iterate over `collection`. 12 | * @returns {*} Returns the accumulated value. 13 | */ 14 | function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { 15 | eachFunc(collection, (value, index, collection) => { 16 | accumulator = initAccum 17 | ? (initAccum = false, value) 18 | : iteratee(accumulator, value, index, collection) 19 | }) 20 | return accumulator 21 | } 22 | 23 | export default baseReduce 24 | -------------------------------------------------------------------------------- /isFunction.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObject from './isObject.js' 3 | 4 | /** 5 | * Checks if `value` is classified as a `Function` object. 6 | * 7 | * @since 0.1.0 8 | * @category Lang 9 | * @param {*} value The value to check. 10 | * @returns {boolean} Returns `true` if `value` is a function, else `false`. 11 | * @example 12 | * 13 | * isFunction(_) 14 | * // => true 15 | * 16 | * isFunction(/abc/) 17 | * // => false 18 | */ 19 | function isFunction(value) { 20 | if (!isObject(value)) { 21 | return false 22 | } 23 | // The use of `Object#toString` avoids issues with the `typeof` operator 24 | // in Safari 9 which returns 'object' for typed arrays and other constructors. 25 | const tag = baseGetTag(value) 26 | return tag == '[object Function]' || tag == '[object AsyncFunction]' || 27 | tag == '[object GeneratorFunction]' || tag == '[object Proxy]' 28 | } 29 | 30 | export default isFunction 31 | -------------------------------------------------------------------------------- /isError.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | import isPlainObject from './isPlainObject.js' 4 | 5 | /** 6 | * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, 7 | * `SyntaxError`, `TypeError`, or `URIError` object. 8 | * 9 | * @since 3.0.0 10 | * @category Lang 11 | * @param {*} value The value to check. 12 | * @returns {boolean} Returns `true` if `value` is an error object, else `false`. 13 | * @example 14 | * 15 | * isError(new Error) 16 | * // => true 17 | * 18 | * isError(Error) 19 | * // => false 20 | */ 21 | function isError(value) { 22 | if (!isObjectLike(value)) { 23 | return false 24 | } 25 | const tag = baseGetTag(value) 26 | return tag == '[object Error]' || tag == '[object DOMException]' || 27 | (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)) 28 | } 29 | 30 | export default isError 31 | -------------------------------------------------------------------------------- /after.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The opposite of `before`his method creates a function that invokes 3 | * `func` once it's called `n` or more times. 4 | * 5 | * @since 0.1.0 6 | * @category Function 7 | * @param {number} n The number of calls before `func` is invoked. 8 | * @param {Function} func The function to restrict. 9 | * @returns {Function} Returns the new restricted function. 10 | * @example 11 | * 12 | * const saves = ['profile', 'settings'] 13 | * const done = after(saves.length, () => console.log('done saving!')) 14 | * 15 | * forEach(saves, type => asyncSave({ 'type': type, 'complete': done })) 16 | * // => Logs 'done saving!' after the two async saves have completed. 17 | */ 18 | function after(n, func) { 19 | if (typeof func != 'function') { 20 | throw new TypeError('Expected a function') 21 | } 22 | return function(...args) { 23 | if (--n < 1) { 24 | return func.apply(this, args) 25 | } 26 | } 27 | } 28 | 29 | export default after 30 | -------------------------------------------------------------------------------- /isNumber.js: -------------------------------------------------------------------------------- 1 | import baseGetTag from './.internal/baseGetTag.js' 2 | import isObjectLike from './isObjectLike.js' 3 | 4 | /** 5 | * Checks if `value` is classified as a `Number` primitive or object. 6 | * 7 | * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are 8 | * classified as numbers, use the `Number.isFinite` method. 9 | * 10 | * @since 0.1.0 11 | * @category Lang 12 | * @param {*} value The value to check. 13 | * @returns {boolean} Returns `true` if `value` is a number, else `false`. 14 | * @see isInteger, toInteger, toNumber 15 | * @example 16 | * 17 | * isNumber(3) 18 | * // => true 19 | * 20 | * isNumber(Number.MIN_VALUE) 21 | * // => true 22 | * 23 | * isNumber(Infinity) 24 | * // => true 25 | * 26 | * isNumber('3') 27 | * // => false 28 | */ 29 | function isNumber(value) { 30 | return typeof value == 'number' || 31 | (isObjectLike(value) && baseGetTag(value) == '[object Number]') 32 | } 33 | 34 | export default isNumber 35 | -------------------------------------------------------------------------------- /pickBy.js: -------------------------------------------------------------------------------- 1 | import map from './map.js' 2 | import basePickBy from './.internal/basePickBy.js' 3 | import getAllKeysIn from './.internal/getAllKeysIn.js' 4 | 5 | /** 6 | * Creates an object composed of the `object` properties `predicate` returns 7 | * truthy for. The predicate is invoked with two arguments: (value, key). 8 | * 9 | * @since 4.0.0 10 | * @category Object 11 | * @param {Object} object The source object. 12 | * @param {Function} predicate The function invoked per property. 13 | * @returns {Object} Returns the new object. 14 | * @example 15 | * 16 | * const object = { 'a': 1, 'b': '2', 'c': 3 } 17 | * 18 | * pickBy(object, isNumber) 19 | * // => { 'a': 1, 'c': 3 } 20 | */ 21 | function pickBy(object, predicate) { 22 | if (object == null) { 23 | return {} 24 | } 25 | const props = map(getAllKeysIn(object), (prop) => [prop]) 26 | return basePickBy(object, props, (value, path) => predicate(value, path[0])) 27 | } 28 | 29 | export default pickBy 30 | -------------------------------------------------------------------------------- /.internal/baseWhile.js: -------------------------------------------------------------------------------- 1 | import slice from '../slice.js' 2 | 3 | /** 4 | * The base implementation of methods like `dropWhile` and `takeWhile`. 5 | * 6 | * @private 7 | * @param {Array} array The array to query. 8 | * @param {Function} predicate The function invoked per iteration. 9 | * @param {boolean} [isDrop] Specify dropping elements instead of taking them. 10 | * @param {boolean} [fromRight] Specify iterating from right to left. 11 | * @returns {Array} Returns the slice of `array`. 12 | */ 13 | function baseWhile(array, predicate, isDrop, fromRight) { 14 | const { length } = array 15 | let index = fromRight ? length : -1 16 | 17 | while ((fromRight ? index-- : ++index < length) && 18 | predicate(array[index], index, array)) {} 19 | 20 | return isDrop 21 | ? slice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) 22 | : slice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)) 23 | } 24 | 25 | export default baseWhile 26 | -------------------------------------------------------------------------------- /flatMapDeep.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | import map from './map.js' 3 | 4 | /** Used as references for various `Number` constants. */ 5 | const INFINITY = 1 / 0 6 | 7 | /** 8 | * This method is like `flatMap` except that it recursively flattens the 9 | * mapped results. 10 | * 11 | * @since 4.7.0 12 | * @category Collection 13 | * @param {Array|Object} collection The collection to iterate over. 14 | * @param {Function} iteratee The function invoked per iteration. 15 | * @returns {Array} Returns the new flattened array. 16 | * @see flatMap, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues 17 | * @example 18 | * 19 | * function duplicate(n) { 20 | * return [[[n, n]]] 21 | * } 22 | * 23 | * flatMapDeep([1, 2], duplicate) 24 | * // => [1, 1, 2, 2] 25 | */ 26 | function flatMapDeep(collection, iteratee) { 27 | return baseFlatten(map(collection, iteratee), INFINITY) 28 | } 29 | 30 | export default flatMapDeep 31 | -------------------------------------------------------------------------------- /isTypedArray.js: -------------------------------------------------------------------------------- 1 | import getTag from './.internal/getTag.js' 2 | import nodeUtil from './.internal/nodeUtil.js' 3 | 4 | /** Used to match `toStringTag` values of typed arrays. */ 5 | const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)\]$/ 6 | 7 | /* Node.js helper references. */ 8 | const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray 9 | 10 | /** 11 | * Checks if `value` is classified as a typed array. 12 | * 13 | * @since 3.0.0 14 | * @category Lang 15 | * @param {*} value The value to check. 16 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. 17 | * @example 18 | * 19 | * isTypedArray(new Uint8Array) 20 | * // => true 21 | * 22 | * isTypedArray([]) 23 | * // => false 24 | */ 25 | const isTypedArray = nodeIsTypedArray 26 | ? (value) => nodeIsTypedArray(value) 27 | : (value) => typeof value == 'object' && value !== null && reTypedTag.test(getTag(value)) 28 | 29 | export default isTypedArray 30 | -------------------------------------------------------------------------------- /sortedLastIndexBy.js: -------------------------------------------------------------------------------- 1 | import baseSortedIndexBy from './.internal/baseSortedIndexBy.js' 2 | 3 | /** 4 | * This method is like `sortedLastIndex` except that it accepts `iteratee` 5 | * which is invoked for `value` and each element of `array` to compute their 6 | * sort ranking. The iteratee is invoked with one argument: (value). 7 | * 8 | * @since 4.0.0 9 | * @category Array 10 | * @param {Array} array The sorted array to inspect. 11 | * @param {*} value The value to evaluate. 12 | * @param {Function} iteratee The iteratee invoked per element. 13 | * @returns {number} Returns the index at which `value` should be inserted 14 | * into `array`. 15 | * @example 16 | * 17 | * const objects = [{ 'n': 4 }, { 'n': 5 }] 18 | * 19 | * sortedLastIndexBy(objects, { 'n': 4 }, ({ n }) => n) 20 | * // => 1 21 | */ 22 | function sortedLastIndexBy(array, value, iteratee) { 23 | return baseSortedIndexBy(array, value, iteratee, true) 24 | } 25 | 26 | export default sortedLastIndexBy 27 | -------------------------------------------------------------------------------- /flatMap.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | import map from './map.js' 3 | 4 | /** 5 | * Creates a flattened array of values by running each element in `collection` 6 | * thru `iteratee` and flattening the mapped results. The iteratee is invoked 7 | * with three arguments: (value, index|key, collection). 8 | * 9 | * @since 4.0.0 10 | * @category Collection 11 | * @param {Array|Object} collection The collection to iterate over. 12 | * @param {Function} iteratee The function invoked per iteration. 13 | * @returns {Array} Returns the new flattened array. 14 | * @see flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues 15 | * @example 16 | * 17 | * function duplicate(n) { 18 | * return [n, n] 19 | * } 20 | * 21 | * flatMap([1, 2], duplicate) 22 | * // => [1, 1, 2, 2] 23 | */ 24 | function flatMap(collection, iteratee) { 25 | return baseFlatten(map(collection, iteratee), 1) 26 | } 27 | 28 | export default flatMap 29 | -------------------------------------------------------------------------------- /intersection.js: -------------------------------------------------------------------------------- 1 | import map from './map.js' 2 | import baseIntersection from './.internal/baseIntersection.js' 3 | import castArrayLikeObject from './.internal/castArrayLikeObject.js' 4 | 5 | /** 6 | * Creates an array of unique values that are included in all given arrays 7 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) 8 | * for equality comparisons. The order and references of result values are 9 | * determined by the first array. 10 | * 11 | * @since 0.1.0 12 | * @category Array 13 | * @param {...Array} [arrays] The arrays to inspect. 14 | * @returns {Array} Returns the new array of intersecting values. 15 | * @example 16 | * 17 | * intersection([2, 1], [2, 3]) 18 | * // => [2] 19 | */ 20 | function intersection(...arrays) { 21 | const mapped = map(arrays, castArrayLikeObject) 22 | return (mapped.length && mapped[0] === arrays[0]) 23 | ? baseIntersection(mapped) 24 | : [] 25 | } 26 | 27 | export default intersection 28 | -------------------------------------------------------------------------------- /padEnd.js: -------------------------------------------------------------------------------- 1 | import createPadding from './.internal/createPadding.js' 2 | import stringSize from './.internal/stringSize.js' 3 | 4 | /** 5 | * Pads `string` on the right side if it's shorter than `length`. Padding 6 | * characters are truncated if they exceed `length`. 7 | * 8 | * @since 4.0.0 9 | * @category String 10 | * @param {string} [string=''] The string to pad. 11 | * @param {number} [length=0] The padding length. 12 | * @param {string} [chars=' '] The string used as padding. 13 | * @returns {string} Returns the padded string. 14 | * @example 15 | * 16 | * padEnd('abc', 6) 17 | * // => 'abc ' 18 | * 19 | * padEnd('abc', 6, '_-') 20 | * // => 'abc_-_' 21 | * 22 | * padEnd('abc', 2) 23 | * // => 'abc' 24 | */ 25 | function padEnd(string, length, chars) { 26 | const strLength = length ? stringSize(string) : 0 27 | return (length && strLength < length) 28 | ? (string + createPadding(length - strLength, chars)) 29 | : string 30 | } 31 | 32 | export default padEnd 33 | -------------------------------------------------------------------------------- /rangeRight.js: -------------------------------------------------------------------------------- 1 | import createRange from './.internal/createRange.js' 2 | 3 | /** 4 | * This method is like `range` except that it populates values in 5 | * descending order. 6 | * 7 | * @since 4.0.0 8 | * @category Util 9 | * @param {number} [start=0] The start of the range. 10 | * @param {number} end The end of the range. 11 | * @param {number} [step=1] The value to increment or decrement by. 12 | * @returns {Array} Returns the range of numbers. 13 | * @see inRange, range 14 | * @example 15 | * 16 | * rangeRight(4) 17 | * // => [3, 2, 1, 0] 18 | * 19 | * rangeRight(-4) 20 | * // => [-3, -2, -1, 0] 21 | * 22 | * rangeRight(1, 5) 23 | * // => [4, 3, 2, 1] 24 | * 25 | * rangeRight(0, 20, 5) 26 | * // => [15, 10, 5, 0] 27 | * 28 | * rangeRight(0, -4, -1) 29 | * // => [-3, -2, -1, 0] 30 | * 31 | * rangeRight(1, 4, 0) 32 | * // => [1, 1, 1] 33 | * 34 | * rangeRight(0) 35 | * // => [] 36 | */ 37 | const rangeRight = createRange(true) 38 | 39 | export default rangeRight 40 | -------------------------------------------------------------------------------- /takeWhile.js: -------------------------------------------------------------------------------- 1 | import baseWhile from './.internal/baseWhile.js' 2 | 3 | /** 4 | * Creates a slice of `array` with elements taken from the beginning. Elements 5 | * are taken until `predicate` returns falsey. The predicate is invoked with 6 | * three arguments: (value, index, array). 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The array to query. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @returns {Array} Returns the slice of `array`. 13 | * @example 14 | * 15 | * const users = [ 16 | * { 'user': 'barney', 'active': true }, 17 | * { 'user': 'fred', 'active': true }, 18 | * { 'user': 'pebbles', 'active': false } 19 | * ] 20 | * 21 | * takeWhile(users, ({ active }) => active) 22 | * // => objects for ['barney', 'fred'] 23 | */ 24 | function takeWhile(array, predicate) { 25 | return (array != null && array.length) 26 | ? baseWhile(array, predicate) 27 | : [] 28 | } 29 | 30 | export default takeWhile 31 | -------------------------------------------------------------------------------- /dropWhile.js: -------------------------------------------------------------------------------- 1 | import baseWhile from './.internal/baseWhile.js' 2 | 3 | /** 4 | * Creates a slice of `array` excluding elements dropped from the beginning. 5 | * Elements are dropped until `predicate` returns falsey. The predicate is 6 | * invoked with three arguments: (value, index, array). 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The array to query. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @returns {Array} Returns the slice of `array`. 13 | * @example 14 | * 15 | * const users = [ 16 | * { 'user': 'barney', 'active': true }, 17 | * { 'user': 'fred', 'active': true }, 18 | * { 'user': 'pebbles', 'active': false } 19 | * ] 20 | * 21 | * dropWhile(users, ({ active }) => active) 22 | * // => objects for ['pebbles'] 23 | */ 24 | function dropWhile(array, predicate) { 25 | return (array != null && array.length) 26 | ? baseWhile(array, predicate, true) 27 | : [] 28 | } 29 | 30 | export default dropWhile 31 | -------------------------------------------------------------------------------- /invoke.js: -------------------------------------------------------------------------------- 1 | import castPath from './.internal/castPath.js' 2 | import last from './last.js' 3 | import parent from './.internal/parent.js' 4 | import toKey from './.internal/toKey.js' 5 | 6 | /** 7 | * Invokes the method at `path` of `object`. 8 | * 9 | * @since 4.0.0 10 | * @category Object 11 | * @param {Object} object The object to query. 12 | * @param {Array|string} path The path of the method to invoke. 13 | * @param {Array} [args] The arguments to invoke the method with. 14 | * @returns {*} Returns the result of the invoked method. 15 | * @example 16 | * 17 | * const object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] } 18 | * 19 | * invoke(object, 'a[0].b.c.slice', [1, 3]) 20 | * // => [2, 3] 21 | */ 22 | function invoke(object, path, args) { 23 | path = castPath(path, object) 24 | object = parent(object, path) 25 | const func = object == null ? object : object[toKey(last(path))] 26 | return func == null ? undefined : func.apply(object, args) 27 | } 28 | 29 | export default invoke 30 | -------------------------------------------------------------------------------- /padStart.js: -------------------------------------------------------------------------------- 1 | import createPadding from './.internal/createPadding.js' 2 | import stringSize from './.internal/stringSize.js' 3 | 4 | /** 5 | * Pads `string` on the left side if it's shorter than `length`. Padding 6 | * characters are truncated if they exceed `length`. 7 | * 8 | * @since 4.0.0 9 | * @category String 10 | * @param {string} [string=''] The string to pad. 11 | * @param {number} [length=0] The padding length. 12 | * @param {string} [chars=' '] The string used as padding. 13 | * @returns {string} Returns the padded string. 14 | * @example 15 | * 16 | * padStart('abc', 6) 17 | * // => ' abc' 18 | * 19 | * padStart('abc', 6, '_-') 20 | * // => '_-_abc' 21 | * 22 | * padStart('abc', 2) 23 | * // => 'abc' 24 | */ 25 | function padStart(string, length, chars) { 26 | const strLength = length ? stringSize(string) : 0 27 | return (length && strLength < length) 28 | ? (createPadding(length - strLength, chars) + string) 29 | : string 30 | } 31 | 32 | export default padStart 33 | -------------------------------------------------------------------------------- /toFinite.js: -------------------------------------------------------------------------------- 1 | import toNumber from './toNumber.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const INFINITY = 1 / 0 5 | const MAX_INTEGER = 1.7976931348623157e+308 6 | 7 | /** 8 | * Converts `value` to a finite number. 9 | * 10 | * @since 4.12.0 11 | * @category Lang 12 | * @param {*} value The value to convert. 13 | * @returns {number} Returns the converted number. 14 | * @example 15 | * 16 | * toFinite(3.2) 17 | * // => 3.2 18 | * 19 | * toFinite(Number.MIN_VALUE) 20 | * // => 5e-324 21 | * 22 | * toFinite(Infinity) 23 | * // => 1.7976931348623157e+308 24 | * 25 | * toFinite('3.2') 26 | * // => 3.2 27 | */ 28 | function toFinite(value) { 29 | if (!value) { 30 | return value === 0 ? value : 0 31 | } 32 | value = toNumber(value) 33 | if (value === INFINITY || value === -INFINITY) { 34 | const sign = (value < 0 ? -1 : 1) 35 | return sign * MAX_INTEGER 36 | } 37 | return value === value ? value : 0 38 | } 39 | 40 | export default toFinite 41 | -------------------------------------------------------------------------------- /zipWith.js: -------------------------------------------------------------------------------- 1 | import unzipWith from './unzipWith.js' 2 | 3 | /** 4 | * This method is like `zip` except that it accepts `iteratee` to specify 5 | * how grouped values should be combined. The iteratee is invoked with the 6 | * elements of each group: (...group). 7 | * 8 | * @since 3.8.0 9 | * @category Array 10 | * @param {...Array} [arrays] The arrays to process. 11 | * @param {Function} iteratee The function to combine 12 | * grouped values. 13 | * @returns {Array} Returns the new array of grouped elements. 14 | * @see unzip, unzipWith, zip, zipObject, zipObjectDeep, zipWith 15 | * @example 16 | * 17 | * zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c) 18 | * // => [111, 222] 19 | */ 20 | function zipWith(...arrays) { 21 | const length = arrays.length 22 | let iteratee = length > 1 ? arrays[length - 1] : undefined 23 | iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined 24 | return unzipWith(arrays, iteratee) 25 | } 26 | 27 | export default zipWith 28 | -------------------------------------------------------------------------------- /get.js: -------------------------------------------------------------------------------- 1 | import baseGet from './.internal/baseGet.js' 2 | 3 | /** 4 | * Gets the value at `path` of `object`. If the resolved value is 5 | * `undefined`, the `defaultValue` is returned in its place. 6 | * 7 | * @since 3.7.0 8 | * @category Object 9 | * @param {Object} object The object to query. 10 | * @param {Array|string} path The path of the property to get. 11 | * @param {*} [defaultValue] The value returned for `undefined` resolved values. 12 | * @returns {*} Returns the resolved value. 13 | * @see has, hasIn, set, unset 14 | * @example 15 | * 16 | * const object = { 'a': [{ 'b': { 'c': 3 } }] } 17 | * 18 | * get(object, 'a[0].b.c') 19 | * // => 3 20 | * 21 | * get(object, ['a', '0', 'b', 'c']) 22 | * // => 3 23 | * 24 | * get(object, 'a.b.c', 'default') 25 | * // => 'default' 26 | */ 27 | function get(object, path, defaultValue) { 28 | const result = object == null ? undefined : baseGet(object, path) 29 | return result === undefined ? defaultValue : result 30 | } 31 | 32 | export default get 33 | -------------------------------------------------------------------------------- /keys.js: -------------------------------------------------------------------------------- 1 | import arrayLikeKeys from './.internal/arrayLikeKeys.js' 2 | import isArrayLike from './isArrayLike.js' 3 | 4 | /** 5 | * Creates an array of the own enumerable property names of `object`. 6 | * 7 | * **Note:** Non-object values are coerced to objects. See the 8 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) 9 | * for more details. 10 | * 11 | * @since 0.1.0 12 | * @category Object 13 | * @param {Object} object The object to query. 14 | * @returns {Array} Returns the array of property names. 15 | * @see values, valuesIn 16 | * @example 17 | * 18 | * function Foo() { 19 | * this.a = 1 20 | * this.b = 2 21 | * } 22 | * 23 | * Foo.prototype.c = 3 24 | * 25 | * keys(new Foo) 26 | * // => ['a', 'b'] (iteration order is not guaranteed) 27 | * 28 | * keys('hi') 29 | * // => ['0', '1'] 30 | */ 31 | function keys(object) { 32 | return isArrayLike(object) 33 | ? arrayLikeKeys(object) 34 | : Object.keys(Object(object)) 35 | } 36 | 37 | export default keys 38 | -------------------------------------------------------------------------------- /mapKey.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The opposite of `mapValue` this method creates an object with the 3 | * same values as `object` and keys generated by running each own enumerable 4 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked 5 | * with three arguments: (value, key, object). 6 | * 7 | * @since 3.8.0 8 | * @category Object 9 | * @param {Object} object The object to iterate over. 10 | * @param {Function} iteratee The function invoked per iteration. 11 | * @returns {Object} Returns the new mapped object. 12 | * @see mapValue 13 | * @example 14 | * 15 | * mapKey({ 'a': 1, 'b': 2 }, function(value, key) { 16 | * return key + value 17 | * }) 18 | * // => { 'a1': 1, 'b2': 2 } 19 | */ 20 | function mapKey(object, iteratee) { 21 | object = Object(object) 22 | const result = {} 23 | 24 | Object.keys(object).forEach((key) => { 25 | const value = object[key] 26 | result[iteratee(value, key, object)] = value 27 | }) 28 | return result 29 | } 30 | 31 | export default mapKey 32 | -------------------------------------------------------------------------------- /repeat.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Repeats the given string `n` times. 3 | * 4 | * @since 3.0.0 5 | * @category String 6 | * @param {string} [string=''] The string to repeat. 7 | * @param {number} [n=1] The number of times to repeat the string. 8 | * @returns {string} Returns the repeated string. 9 | * @example 10 | * 11 | * repeat('*', 3) 12 | * // => '***' 13 | * 14 | * repeat('abc', 2) 15 | * // => 'abcabc' 16 | * 17 | * repeat('abc', 0) 18 | * // => '' 19 | */ 20 | function repeat(string, n) { 21 | let result = '' 22 | if (!string || n < 1 || n > Number.MAX_SAFE_INTEGER) { 23 | return result 24 | } 25 | // Leverage the exponentiation by squaring algorithm for a faster repeat. 26 | // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. 27 | do { 28 | if (n % 2) { 29 | result += string 30 | } 31 | n = Math.floor(n / 2) 32 | if (n) { 33 | string += string 34 | } 35 | } while (n) 36 | 37 | return result 38 | } 39 | 40 | export default repeat 41 | -------------------------------------------------------------------------------- /unzipWith.js: -------------------------------------------------------------------------------- 1 | import map from './map.js' 2 | import unzip from './unzip.js' 3 | 4 | /** 5 | * This method is like `unzip` except that it accepts `iteratee` to specify 6 | * how regrouped values should be combined. The iteratee is invoked with the 7 | * elements of each group: (...group). 8 | * 9 | * @since 3.8.0 10 | * @category Array 11 | * @param {Array} array The array of grouped elements to process. 12 | * @param {Function} iteratee The function to combine 13 | * regrouped values. 14 | * @returns {Array} Returns the new array of regrouped elements. 15 | * @example 16 | * 17 | * const zipped = zip([1, 2], [10, 20], [100, 200]) 18 | * // => [[1, 10, 100], [2, 20, 200]] 19 | * 20 | * unzipWith(zipped, add) 21 | * // => [3, 30, 300] 22 | */ 23 | function unzipWith(array, iteratee) { 24 | if (!(array != null && array.length)) { 25 | return [] 26 | } 27 | const result = unzip(array) 28 | return map(result, (group) => iteratee.apply(undefined, group)) 29 | } 30 | 31 | export default unzipWith 32 | -------------------------------------------------------------------------------- /dropRightWhile.js: -------------------------------------------------------------------------------- 1 | import baseWhile from './.internal/baseWhile.js' 2 | 3 | /** 4 | * Creates a slice of `array` excluding elements dropped from the end. 5 | * Elements are dropped until `predicate` returns falsey. The predicate is 6 | * invoked with three arguments: (value, index, array). 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The array to query. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @returns {Array} Returns the slice of `array`. 13 | * @example 14 | * 15 | * const users = [ 16 | * { 'user': 'barney', 'active': false }, 17 | * { 'user': 'fred', 'active': true }, 18 | * { 'user': 'pebbles', 'active': true } 19 | * ] 20 | * 21 | * dropRightWhile(users, ({ active }) => active) 22 | * // => objects for ['barney'] 23 | */ 24 | function dropRightWhile(array, predicate) { 25 | return (array != null && array.length) 26 | ? baseWhile(array, predicate, true, true) 27 | : [] 28 | } 29 | 30 | export default dropRightWhile 31 | -------------------------------------------------------------------------------- /filterObject.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Iterates over properties of `object`, returning an array of all elements 3 | * `predicate` returns truthy for. The predicate is invoked with three 4 | * arguments: (value, key, object). 5 | * 6 | * @since 5.0.0 7 | * @category Object 8 | * @param {Object} object The object to iterate over. 9 | * @param {Function} predicate The function invoked per iteration. 10 | * @returns {Array} Returns the new filtered array. 11 | * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject 12 | * @example 13 | * 14 | * const object = { 'a': 5, 'b': 8, 'c': 10 } 15 | * 16 | * filterObject(object, (n) => !(n % 5)) 17 | * // => [5, 10] 18 | */ 19 | function filterObject(object, predicate) { 20 | object = Object(object) 21 | const result = [] 22 | 23 | Object.keys(object).forEach((key) => { 24 | const value = object[key] 25 | if (predicate(value, key, object)) { 26 | result.push(value) 27 | } 28 | }) 29 | return result 30 | } 31 | 32 | export default filterObject 33 | -------------------------------------------------------------------------------- /forOwn.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Iterates over own enumerable string keyed properties of an object and 3 | * invokes `iteratee` for each property. The iteratee is invoked with three 4 | * arguments: (value, key, object). Iteratee functions may exit iteration 5 | * early by explicitly returning `false`. 6 | * 7 | * @since 0.3.0 8 | * @category Object 9 | * @param {Object} object The object to iterate over. 10 | * @param {Function} iteratee The function invoked per iteration. 11 | * @see forEach, forEachRight, forIn, forInRight, forOwnRight 12 | * @example 13 | * 14 | * function Foo() { 15 | * this.a = 1 16 | * this.b = 2 17 | * } 18 | * 19 | * Foo.prototype.c = 3 20 | * 21 | * forOwn(new Foo, function(value, key) { 22 | * console.log(key) 23 | * }) 24 | * // => Logs 'a' then 'b' (iteration order is not guaranteed). 25 | */ 26 | function forOwn(object, iteratee) { 27 | object = Object(object) 28 | Object.keys(object).forEach((key) => iteratee(object[key], key, object)) 29 | } 30 | 31 | export default forOwn 32 | -------------------------------------------------------------------------------- /takeRightWhile.js: -------------------------------------------------------------------------------- 1 | import baseWhile from './.internal/baseWhile.js' 2 | 3 | /** 4 | * Creates a slice of `array` with elements taken from the end. Elements are 5 | * taken until `predicate` returns falsey. The predicate is invoked with 6 | * three arguments: (value, index, array). 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The array to query. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @returns {Array} Returns the slice of `array`. 13 | * @example 14 | * 15 | * const users = [ 16 | * { 'user': 'barney', 'active': false }, 17 | * { 'user': 'fred', 'active': true }, 18 | * { 'user': 'pebbles', 'active': true } 19 | * ] 20 | * 21 | * takeRightWhile(users, ({ active }) => active) 22 | * // => objects for ['fred', 'pebbles'] 23 | */ 24 | function takeRightWhile(array, predicate) { 25 | return (array != null && array.length) 26 | ? baseWhile(array, predicate, false, true) 27 | : [] 28 | } 29 | 30 | export default takeRightWhile 31 | -------------------------------------------------------------------------------- /flatMapDepth.js: -------------------------------------------------------------------------------- 1 | import baseFlatten from './.internal/baseFlatten.js' 2 | import map from './map.js' 3 | 4 | /** 5 | * This method is like `flatMap` except that it recursively flattens the 6 | * mapped results up to `depth` times. 7 | * 8 | * @since 4.7.0 9 | * @category Collection 10 | * @param {Array|Object} collection The collection to iterate over. 11 | * @param {Function} iteratee The function invoked per iteration. 12 | * @param {number} [depth=1] The maximum recursion depth. 13 | * @returns {Array} Returns the new flattened array. 14 | * @see flatMap, flatMapDeep, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues 15 | * @example 16 | * 17 | * function duplicate(n) { 18 | * return [[[n, n]]] 19 | * } 20 | * 21 | * flatMapDepth([1, 2], duplicate, 2) 22 | * // => [[1, 1], [2, 2]] 23 | */ 24 | function flatMapDepth(collection, iteratee, depth) { 25 | depth = depth === undefined ? 1 : +depth 26 | return baseFlatten(map(collection, iteratee), depth) 27 | } 28 | 29 | export default flatMapDepth 30 | -------------------------------------------------------------------------------- /forOwnRight.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This method is like `forOwn` except that it iterates over properties of 3 | * `object` in the opposite order. 4 | * 5 | * @since 2.0.0 6 | * @category Object 7 | * @param {Object} object The object to iterate over. 8 | * @param {Function} iteratee The function invoked per iteration. 9 | * @returns {Object} Returns `object`. 10 | * @see forEach, forEachRight, forIn, forInRight, forOwn 11 | * @example 12 | * 13 | * function Foo() { 14 | * this.a = 1 15 | * this.b = 2 16 | * } 17 | * 18 | * Foo.prototype.c = 3 19 | * 20 | * forOwnRight(new Foo, function(value, key) { 21 | * console.log(key) 22 | * }) 23 | * // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'. 24 | */ 25 | function forOwnRight(object, iteratee) { 26 | if (object == null) { 27 | return 28 | } 29 | const props = Object.keys(object) 30 | let length = props.length 31 | while (length--) { 32 | iteratee(object[props[length]], iteratee, object) 33 | } 34 | } 35 | 36 | export default forOwnRight 37 | -------------------------------------------------------------------------------- /startsWith.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if `string` starts with the given target string. 3 | * 4 | * @since 3.0.0 5 | * @category String 6 | * @param {string} [string=''] The string to inspect. 7 | * @param {string} [target] The string to search for. 8 | * @param {number} [position=0] The position to search from. 9 | * @returns {boolean} Returns `true` if `string` starts with `target`, 10 | * else `false`. 11 | * @see endsWith, includes 12 | * @example 13 | * 14 | * startsWith('abc', 'a') 15 | * // => true 16 | * 17 | * startsWith('abc', 'b') 18 | * // => false 19 | * 20 | * startsWith('abc', 'b', 1) 21 | * // => true 22 | */ 23 | function startsWith(string, target, position) { 24 | const { length } = string 25 | position = position == null ? 0 : position 26 | if (position < 0) { 27 | position = 0 28 | } 29 | else if (position > length) { 30 | position = length 31 | } 32 | target = `${target}` 33 | return string.slice(position, position + target.length) == target 34 | } 35 | 36 | export default startsWith 37 | -------------------------------------------------------------------------------- /.internal/baseOrderBy.js: -------------------------------------------------------------------------------- 1 | import baseMap from './baseMap.js' 2 | import baseSortBy from './baseSortBy.js' 3 | import compareMultiple from './compareMultiple.js' 4 | 5 | /** 6 | * The base implementation of `orderBy` without param guards. 7 | * 8 | * @private 9 | * @param {Array|Object} collection The collection to iterate over. 10 | * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. 11 | * @param {string[]} orders The sort orders of `iteratees`. 12 | * @returns {Array} Returns the new sorted array. 13 | */ 14 | function baseOrderBy(collection, iteratees, orders) { 15 | let index = -1 16 | iteratees = iteratees.length ? iteratees : [(value) => value] 17 | 18 | const result = baseMap(collection, (value, key, collection) => { 19 | const criteria = iteratees.map((iteratee) => iteratee(value)) 20 | return { 'criteria': criteria, 'index': ++index, 'value': value } 21 | }) 22 | 23 | return baseSortBy(result, (object, other) => compareMultiple(object, other, orders)) 24 | } 25 | 26 | export default baseOrderBy 27 | -------------------------------------------------------------------------------- /conformsTo.js: -------------------------------------------------------------------------------- 1 | import baseConformsTo from './.internal/baseConformsTo.js' 2 | import keys from './keys.js' 3 | 4 | /** 5 | * Checks if `object` conforms to `source` by invoking the predicate 6 | * properties of `source` with the corresponding property values of `object`. 7 | * 8 | * **Note:** This method is equivalent to `conforms` when `source` is 9 | * partially applied. 10 | * 11 | * @since 4.14.0 12 | * @category Lang 13 | * @param {Object} object The object to inspect. 14 | * @param {Object} source The object of property predicates to conform to. 15 | * @returns {boolean} Returns `true` if `object` conforms, else `false`. 16 | * @example 17 | * 18 | * const object = { 'a': 1, 'b': 2 } 19 | * 20 | * conformsTo(object, { 'b': function(n) { return n > 1 } }) 21 | * // => true 22 | * 23 | * conformsTo(object, { 'b': function(n) { return n > 2 } }) 24 | * // => false 25 | */ 26 | function conformsTo(object, source) { 27 | return source == null || baseConformsTo(object, source, keys(source)) 28 | } 29 | 30 | export default conformsTo 31 | -------------------------------------------------------------------------------- /isNative.js: -------------------------------------------------------------------------------- 1 | import isObject from './isObject.js' 2 | 3 | /** 4 | * Used to match `RegExp` 5 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). 6 | */ 7 | const reRegExpChar = /[\\^$.*+?()[\]{}|]/g 8 | 9 | /** Used to detect if a method is native. */ 10 | const reIsNative = RegExp(`^${ 11 | Function.prototype.toString.call(Object.prototype.hasOwnProperty) 12 | .replace(reRegExpChar, '\\$&') 13 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') 14 | }$`) 15 | 16 | /** 17 | * Checks if `value` is a pristine native function. 18 | * 19 | * @since 3.0.0 20 | * @category Lang 21 | * @param {*} value The value to check. 22 | * @returns {boolean} Returns `true` if `value` is a native function, 23 | * else `false`. 24 | * @example 25 | * 26 | * isNative(Array.prototype.push) 27 | * // => true 28 | * 29 | * isNative(isDate) 30 | * // => false 31 | */ 32 | function isNative(value) { 33 | return isObject(value) && reIsNative.test(value) 34 | } 35 | 36 | export default isNative 37 | -------------------------------------------------------------------------------- /reject.js: -------------------------------------------------------------------------------- 1 | import filter from './filter.js' 2 | import filterObject from './filterObject.js' 3 | import negate from './negate.js' 4 | 5 | /** 6 | * The opposite of `filter` this method returns the elements of `collection` 7 | * that `predicate` does **not** return truthy for. 8 | * 9 | * @since 0.1.0 10 | * @category Collection 11 | * @param {Array|Object} collection The collection to iterate over. 12 | * @param {Function} predicate The function invoked per iteration. 13 | * @returns {Array} Returns the new filtered array. 14 | * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, filter 15 | * @example 16 | * 17 | * const users = [ 18 | * { 'user': 'barney', 'active': true }, 19 | * { 'user': 'fred', 'active': false } 20 | * ] 21 | * 22 | * reject(users, ({ active }) => active) 23 | * // => objects for ['fred'] 24 | */ 25 | function reject(collection, predicate) { 26 | const func = Array.isArray(collection) ? filter : filterObject 27 | return func(collection, negate(predicate)) 28 | } 29 | 30 | export default reject 31 | -------------------------------------------------------------------------------- /before.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function that invokes `func`, with the `this` binding and arguments 3 | * of the created function, while it's called less than `n` times. Subsequent 4 | * calls to the created function return the result of the last `func` invocation. 5 | * 6 | * @since 3.0.0 7 | * @category Function 8 | * @param {number} n The number of calls at which `func` is no longer invoked. 9 | * @param {Function} func The function to restrict. 10 | * @returns {Function} Returns the new restricted function. 11 | * @example 12 | * 13 | * jQuery(element).on('click', before(5, addContactToList)) 14 | * // => Allows adding up to 4 contacts to the list. 15 | */ 16 | function before(n, func) { 17 | let result 18 | if (typeof func != 'function') { 19 | throw new TypeError('Expected a function') 20 | } 21 | return function(...args) { 22 | if (--n > 0) { 23 | result = func.apply(this, args) 24 | } 25 | if (n <= 1) { 26 | func = undefined 27 | } 28 | return result 29 | } 30 | } 31 | 32 | export default before 33 | -------------------------------------------------------------------------------- /toSafeInteger.js: -------------------------------------------------------------------------------- 1 | import toInteger from './toInteger.js' 2 | 3 | /** Used as references for various `Number` constants. */ 4 | const MAX_SAFE_INTEGER = 9007199254740991 5 | 6 | /** 7 | * Converts `value` to a safe integer. A safe integer can be compared and 8 | * represented correctly. 9 | * 10 | * @since 4.0.0 11 | * @category Lang 12 | * @param {*} value The value to convert. 13 | * @returns {number} Returns the converted integer. 14 | * @example 15 | * 16 | * toSafeInteger(3.2) 17 | * // => 3 18 | * 19 | * toSafeInteger(Number.MIN_VALUE) 20 | * // => 0 21 | * 22 | * toSafeInteger(Infinity) 23 | * // => 9007199254740991 24 | * 25 | * toSafeInteger('3.2') 26 | * // => 3 27 | */ 28 | function toSafeInteger(value) { 29 | if (!value) { 30 | return value === 0 ? value : 0 31 | } 32 | value = toInteger(value) 33 | if (value < -MAX_SAFE_INTEGER) { 34 | return -MAX_SAFE_INTEGER 35 | } 36 | if (value > MAX_SAFE_INTEGER) { 37 | return MAX_SAFE_INTEGER 38 | } 39 | return value 40 | } 41 | 42 | export default toSafeInteger 43 | -------------------------------------------------------------------------------- /.internal/hasUnicode.js: -------------------------------------------------------------------------------- 1 | /** Used to compose unicode character classes. */ 2 | const rsAstralRange = '\\ud800-\\udfff' 3 | const rsComboMarksRange = '\\u0300-\\u036f' 4 | const reComboHalfMarksRange = '\\ufe20-\\ufe2f' 5 | const rsComboSymbolsRange = '\\u20d0-\\u20ff' 6 | const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange 7 | const rsVarRange = '\\ufe0e\\ufe0f' 8 | 9 | /** Used to compose unicode capture groups. */ 10 | const rsZWJ = '\\u200d' 11 | 12 | /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ 13 | const reHasUnicode = RegExp(`[${rsZWJ + rsAstralRange + rsComboRange + rsVarRange}]`) 14 | 15 | /** 16 | * Checks if `string` contains Unicode symbols. 17 | * 18 | * @private 19 | * @param {string} string The string to inspect. 20 | * @returns {boolean} Returns `true` if a symbol is found, else `false`. 21 | */ 22 | function hasUnicode(string) { 23 | return reHasUnicode.test(string) 24 | } 25 | 26 | export default hasUnicode 27 | -------------------------------------------------------------------------------- /overArgs.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Creates a function that invokes `func` with its arguments transformed. 4 | * 5 | * @since 4.0.0 6 | * @category Function 7 | * @param {Function} func The function to wrap. 8 | * @param {Function[]} [transforms=[identity]] 9 | * The argument transforms. 10 | * @returns {Function} Returns the new function. 11 | * @example 12 | * 13 | * function doubled(n) { 14 | * return n * 2 15 | * } 16 | * 17 | * function square(n) { 18 | * return n * n 19 | * } 20 | * 21 | * const func = overArgs((x, y) => [x, y], [square, doubled]) 22 | * 23 | * func(9, 3) 24 | * // => [81, 6] 25 | * 26 | * func(10, 5) 27 | * // => [100, 10] 28 | */ 29 | function overArgs(func, transforms) { 30 | const funcsLength = transforms.length 31 | return function(...args) { 32 | let index = -1 33 | const length = Math.min(args.length, funcsLength) 34 | while (++index < length) { 35 | args[index] = transforms[index].call(this, args[index]) 36 | } 37 | return func.apply(this, args) 38 | } 39 | } 40 | 41 | export default overArgs 42 | -------------------------------------------------------------------------------- /chunk.js: -------------------------------------------------------------------------------- 1 | import slice from './slice.js' 2 | 3 | /** 4 | * Creates an array of elements split into groups the length of `size`. 5 | * If `array` can't be split evenly, the final chunk will be the remaining 6 | * elements. 7 | * 8 | * @since 3.0.0 9 | * @category Array 10 | * @param {Array} array The array to process. 11 | * @param {number} [size=1] The length of each chunk 12 | * @returns {Array} Returns the new array of chunks. 13 | * @example 14 | * 15 | * chunk(['a', 'b', 'c', 'd'], 2) 16 | * // => [['a', 'b'], ['c', 'd']] 17 | * 18 | * chunk(['a', 'b', 'c', 'd'], 3) 19 | * // => [['a', 'b', 'c'], ['d']] 20 | */ 21 | function chunk(array, size) { 22 | size = Math.max(size, 0) 23 | const length = array == null ? 0 : array.length 24 | if (!length || size < 1) { 25 | return [] 26 | } 27 | let index = 0 28 | let resIndex = 0 29 | const result = new Array(Math.ceil(length / size)) 30 | 31 | while (index < length) { 32 | result[resIndex++] = slice(array, index, (index += size)) 33 | } 34 | return result 35 | } 36 | 37 | export default chunk 38 | -------------------------------------------------------------------------------- /update.js: -------------------------------------------------------------------------------- 1 | import baseUpdate from './.internal/baseUpdate.js' 2 | 3 | /** 4 | * This method is like `set` except that it accepts `updater` to produce the 5 | * value to set. Use `updateWith` to customize `path` creation. The `updater` 6 | * is invoked with one argument: (value). 7 | * 8 | * **Note:** This method mutates `object`. 9 | * 10 | * @since 4.6.0 11 | * @category Object 12 | * @param {Object} object The object to modify. 13 | * @param {Array|string} path The path of the property to set. 14 | * @param {Function} updater The function to produce the updated value. 15 | * @returns {Object} Returns `object`. 16 | * @example 17 | * 18 | * const object = { 'a': [{ 'b': { 'c': 3 } }] } 19 | * 20 | * update(object, 'a[0].b.c', n => n * n) 21 | * console.log(object.a[0].b.c) 22 | * // => 9 23 | * 24 | * update(object, 'x[0].y.z', n => n ? n + 1 : 0) 25 | * console.log(object.x[0].y.z) 26 | * // => 0 27 | */ 28 | function update(object, path, updater) { 29 | return object == null ? object : baseUpdate(object, path, updater) 30 | } 31 | 32 | export default update 33 | -------------------------------------------------------------------------------- /mapValue.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates an object with the same keys as `object` and values generated 3 | * by running each own enumerable string keyed property of `object` thru 4 | * `iteratee`. The iteratee is invoked with three arguments: 5 | * (value, key, object). 6 | * 7 | * @since 2.4.0 8 | * @category Object 9 | * @param {Object} object The object to iterate over. 10 | * @param {Function} iteratee The function invoked per iteration. 11 | * @returns {Object} Returns the new mapped object. 12 | * @see mapKeys 13 | * @example 14 | * 15 | * const users = { 16 | * 'fred': { 'user': 'fred', 'age': 40 }, 17 | * 'pebbles': { 'user': 'pebbles', 'age': 1 } 18 | * } 19 | * 20 | * mapValue(users, ({ age }) => age) 21 | * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) 22 | */ 23 | function mapValue(object, iteratee) { 24 | object = Object(object) 25 | const result = {} 26 | 27 | Object.keys(object).forEach((key) => { 28 | result[key] = iteratee(object[key], key, object) 29 | }) 30 | return result 31 | } 32 | 33 | export default mapValue 34 | -------------------------------------------------------------------------------- /sampleSize.js: -------------------------------------------------------------------------------- 1 | import copyArray from './.internal/copyArray.js' 2 | 3 | /** 4 | * Gets `n` random elements at unique keys from `array` up to the 5 | * size of `array`. 6 | * 7 | * @since 4.0.0 8 | * @category Array 9 | * @param {Array} array The array to sample. 10 | * @param {number} [n=1] The number of elements to sample. 11 | * @returns {Array} Returns the random elements. 12 | * @example 13 | * 14 | * sampleSize([1, 2, 3], 2) 15 | * // => [3, 1] 16 | * 17 | * sampleSize([1, 2, 3], 4) 18 | * // => [2, 3, 1] 19 | */ 20 | function sampleSize(array, n) { 21 | const length = array == null ? 0 : array.length 22 | if (!length || n < 1) { 23 | return [] 24 | } 25 | n = n > length ? length : n 26 | let index = -1 27 | const lastIndex = n - 1 28 | const result = copyArray(array) 29 | while (++index < n) { 30 | const rand = index + Math.floor(Math.random() * (lastIndex - index + 1)) 31 | const value = result[rand] 32 | result[rand] = result[index] 33 | result[index] = value 34 | } 35 | return result 36 | } 37 | 38 | export default sampleSize 39 | -------------------------------------------------------------------------------- /uniqWith.js: -------------------------------------------------------------------------------- 1 | import baseUniq from './.internal/baseUniq.js' 2 | 3 | /** 4 | * This method is like `uniq` except that it accepts `comparator` which 5 | * is invoked to compare elements of `array`. The order of result values is 6 | * determined by the order they occur in the array.The comparator is invoked 7 | * with two arguments: (arrVal, othVal). 8 | * 9 | * @since 4.0.0 10 | * @category Array 11 | * @param {Array} array The array to inspect. 12 | * @param {Function} [comparator] The comparator invoked per element. 13 | * @returns {Array} Returns the new duplicate free array. 14 | * @see uniq, uniqBy 15 | * @example 16 | * 17 | * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }] 18 | * 19 | * uniqWith(objects, isEqual) 20 | * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] 21 | */ 22 | function uniqWith(array, comparator) { 23 | comparator = typeof comparator == 'function' ? comparator : undefined 24 | return (array != null && array.length) 25 | ? baseUniq(array, undefined, comparator) 26 | : [] 27 | } 28 | 29 | export default uniqWith 30 | -------------------------------------------------------------------------------- /findLastKey.js: -------------------------------------------------------------------------------- 1 | import baseFindKey from './.internal/baseFindKey.js' 2 | import baseForOwnRight from './.internal/baseForOwnRight.js' 3 | 4 | /** 5 | * This method is like `findKey` except that it iterates over elements of 6 | * a collection in the opposite order. 7 | * 8 | * @since 2.0.0 9 | * @category Object 10 | * @param {Object} object The object to inspect. 11 | * @param {Function} predicate The function invoked per iteration. 12 | * @returns {string|undefined} Returns the key of the matched element, 13 | * else `undefined`. 14 | * @see find, findIndex, findKey, findLast, findLastIndex 15 | * @example 16 | * 17 | * const users = { 18 | * 'barney': { 'age': 36, 'active': true }, 19 | * 'fred': { 'age': 40, 'active': false }, 20 | * 'pebbles': { 'age': 1, 'active': true } 21 | * } 22 | * 23 | * findLastKey(users, ({ age }) => age < 40) 24 | * // => returns 'pebbles' assuming `findKey` returns 'barney' 25 | */ 26 | function findLastKey(object, predicate) { 27 | return baseFindKey(object, predicate, baseForOwnRight) 28 | } 29 | 30 | export default findLastKey 31 | -------------------------------------------------------------------------------- /toLength.js: -------------------------------------------------------------------------------- 1 | import toInteger from './toInteger.js' 2 | 3 | /** Used as references for the maximum length and index of an array. */ 4 | const MAX_ARRAY_LENGTH = 4294967295 5 | 6 | /** 7 | * Converts `value` to an integer suitable for use as the length of an 8 | * array-like object. 9 | * 10 | * **Note:** This method is based on 11 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). 12 | * 13 | * @since 4.0.0 14 | * @category Lang 15 | * @param {*} value The value to convert. 16 | * @returns {number} Returns the converted integer. 17 | * @example 18 | * 19 | * toLength(3.2) 20 | * // => 3 21 | * 22 | * toLength(Number.MIN_VALUE) 23 | * // => 0 24 | * 25 | * toLength(Infinity) 26 | * // => 4294967295 27 | * 28 | * toLength('3.2') 29 | * // => 3 30 | */ 31 | function toLength(value) { 32 | if (!value) { 33 | return 0 34 | } 35 | value = toInteger(value) 36 | if (value < 0) { 37 | return 0 38 | } 39 | if (value > MAX_ARRAY_LENGTH) { 40 | return MAX_ARRAY_LENGTH 41 | } 42 | return value 43 | } 44 | 45 | export default toLength 46 | --------------------------------------------------------------------------------