mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 21:27:50 +00:00
Remove isIterateeCall.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import baseRange from './baseRange.js'
|
import baseRange from './baseRange.js'
|
||||||
import isIterateeCall from './isIterateeCall.js'
|
|
||||||
import toFinite from '../toFinite.js'
|
import toFinite from '../toFinite.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,9 +10,6 @@ import toFinite from '../toFinite.js'
|
|||||||
*/
|
*/
|
||||||
function createRange(fromRight) {
|
function createRange(fromRight) {
|
||||||
return (start, end, step) => {
|
return (start, end, step) => {
|
||||||
if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
|
||||||
end = step = undefined
|
|
||||||
}
|
|
||||||
// Ensure the sign of `-0` is preserved.
|
// Ensure the sign of `-0` is preserved.
|
||||||
start = toFinite(start)
|
start = toFinite(start)
|
||||||
if (end === undefined) {
|
if (end === undefined) {
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import eq from '../eq.js'
|
|
||||||
import isArrayLike from '../isArrayLike.js'
|
|
||||||
import isIndex from './isIndex.js'
|
|
||||||
import isObject from '../isObject.js'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given arguments are from an iteratee call.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The potential iteratee value argument.
|
|
||||||
* @param {*} index The potential iteratee index or key argument.
|
|
||||||
* @param {*} object The potential iteratee object argument.
|
|
||||||
* @returns {boolean} Returns `true` if the arguments are from an iteratee call,
|
|
||||||
* else `false`.
|
|
||||||
*/
|
|
||||||
function isIterateeCall(value, index, object) {
|
|
||||||
if (!isObject(object)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const type = typeof index
|
|
||||||
if (type == 'number'
|
|
||||||
? (isArrayLike(object) && isIndex(index, object.length))
|
|
||||||
: (type == 'string' && index in object)
|
|
||||||
) {
|
|
||||||
return eq(object[index], value)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
export default isIterateeCall
|
|
||||||
8
chunk.js
8
chunk.js
@@ -1,5 +1,4 @@
|
|||||||
import baseSlice from './.internal/baseSlice.js'
|
import baseSlice from './.internal/baseSlice.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
|
|
||||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||||
@@ -15,7 +14,6 @@ const nativeMax = Math.max
|
|||||||
* @category Array
|
* @category Array
|
||||||
* @param {Array} array The array to process.
|
* @param {Array} array The array to process.
|
||||||
* @param {number} [size=1] The length of each chunk
|
* @param {number} [size=1] The length of each chunk
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {Array} Returns the new array of chunks.
|
* @returns {Array} Returns the new array of chunks.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -25,12 +23,8 @@ const nativeMax = Math.max
|
|||||||
* chunk(['a', 'b', 'c', 'd'], 3)
|
* chunk(['a', 'b', 'c', 'd'], 3)
|
||||||
* // => [['a', 'b', 'c'], ['d']]
|
* // => [['a', 'b', 'c'], ['d']]
|
||||||
*/
|
*/
|
||||||
function chunk(array, size, guard) {
|
function chunk(array, size) {
|
||||||
if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
|
|
||||||
size = 1
|
|
||||||
} else {
|
|
||||||
size = nativeMax(toInteger(size), 0)
|
size = nativeMax(toInteger(size), 0)
|
||||||
}
|
|
||||||
const length = array == null ? 0 : array.length
|
const length = array == null ? 0 : array.length
|
||||||
if (!length || size < 1) {
|
if (!length || size < 1) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
7
every.js
7
every.js
@@ -1,6 +1,5 @@
|
|||||||
import arrayEvery from './.internal/arrayEvery.js'
|
import arrayEvery from './.internal/arrayEvery.js'
|
||||||
import baseEvery from './.internal/baseEvery.js'
|
import baseEvery from './.internal/baseEvery.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
||||||
@@ -16,7 +15,6 @@ import isIterateeCall from './.internal/isIterateeCall.js'
|
|||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} predicate The function invoked per iteration.
|
* @param {Function} predicate The function invoked per iteration.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||||||
* else `false`.
|
* else `false`.
|
||||||
* @example
|
* @example
|
||||||
@@ -24,11 +22,8 @@ import isIterateeCall from './.internal/isIterateeCall.js'
|
|||||||
* every([true, 1, null, 'yes'], Boolean)
|
* every([true, 1, null, 'yes'], Boolean)
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function every(collection, predicate, guard) {
|
function every(collection, predicate) {
|
||||||
const func = Array.isArray(collection) ? arrayEvery : baseEvery
|
const func = Array.isArray(collection) ? arrayEvery : baseEvery
|
||||||
if (guard && isIterateeCall(collection, predicate, guard)) {
|
|
||||||
predicate = undefined
|
|
||||||
}
|
|
||||||
return func(collection, predicate)
|
return func(collection, predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import toFinite from './toFinite.js'
|
import toFinite from './toFinite.js'
|
||||||
|
|
||||||
/** Built-in method references without a dependency on `root`. */
|
/** Built-in method references without a dependency on `root`. */
|
||||||
@@ -38,9 +37,6 @@ const nativeRandom = Math.random
|
|||||||
* // => a floating-point number between 1.2 and 5.2
|
* // => a floating-point number between 1.2 and 5.2
|
||||||
*/
|
*/
|
||||||
function random(lower, upper, floating) {
|
function random(lower, upper, floating) {
|
||||||
if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
|
|
||||||
upper = floating = undefined
|
|
||||||
}
|
|
||||||
if (floating === undefined) {
|
if (floating === undefined) {
|
||||||
if (typeof upper == 'boolean') {
|
if (typeof upper == 'boolean') {
|
||||||
floating = upper
|
floating = upper
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseRepeat from './.internal/baseRepeat.js'
|
import baseRepeat from './.internal/baseRepeat.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
import toString from './toString.js'
|
import toString from './toString.js'
|
||||||
|
|
||||||
@@ -10,7 +9,6 @@ import toString from './toString.js'
|
|||||||
* @category String
|
* @category String
|
||||||
* @param {string} [string=''] The string to repeat.
|
* @param {string} [string=''] The string to repeat.
|
||||||
* @param {number} [n=1] The number of times to repeat the string.
|
* @param {number} [n=1] The number of times to repeat the string.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {string} Returns the repeated string.
|
* @returns {string} Returns the repeated string.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -23,12 +21,8 @@ import toString from './toString.js'
|
|||||||
* repeat('abc', 0)
|
* repeat('abc', 0)
|
||||||
* // => ''
|
* // => ''
|
||||||
*/
|
*/
|
||||||
function repeat(string, n, guard) {
|
function repeat(string, n) {
|
||||||
if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
|
|
||||||
n = 1
|
|
||||||
} else {
|
|
||||||
n = toInteger(n)
|
n = toInteger(n)
|
||||||
}
|
|
||||||
return baseRepeat(toString(string), n)
|
return baseRepeat(toString(string), n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import copyArray from './.internal/copyArray.js'
|
import copyArray from './.internal/copyArray.js'
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
|
|
||||||
@@ -10,7 +9,6 @@ import toInteger from './toInteger.js'
|
|||||||
* @category Array
|
* @category Array
|
||||||
* @param {Array} array The array to sample.
|
* @param {Array} array The array to sample.
|
||||||
* @param {number} [n=1] The number of elements to sample.
|
* @param {number} [n=1] The number of elements to sample.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {Array} Returns the random elements.
|
* @returns {Array} Returns the random elements.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -20,12 +18,8 @@ import toInteger from './toInteger.js'
|
|||||||
* sampleSize([1, 2, 3], 4)
|
* sampleSize([1, 2, 3], 4)
|
||||||
* // => [2, 3, 1]
|
* // => [2, 3, 1]
|
||||||
*/
|
*/
|
||||||
function sampleSize(array, n, guard) {
|
function sampleSize(array, n) {
|
||||||
if ((guard ? isIterateeCall(array, n, guard) : n === undefined)) {
|
|
||||||
n = 1
|
|
||||||
} else {
|
|
||||||
n = toInteger(n)
|
n = toInteger(n)
|
||||||
}
|
|
||||||
const length = array == null ? 0 : array.length
|
const length = array == null ? 0 : array.length
|
||||||
if (!length || n < 1) {
|
if (!length || n < 1) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
7
slice.js
7
slice.js
@@ -1,5 +1,4 @@
|
|||||||
import baseSlice from './.internal/baseSlice.js'
|
import baseSlice from './.internal/baseSlice.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,14 +20,8 @@ function slice(array, start, end) {
|
|||||||
if (!length) {
|
if (!length) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
|
|
||||||
start = 0
|
|
||||||
end = length
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
start = start == null ? 0 : toInteger(start)
|
start = start == null ? 0 : toInteger(start)
|
||||||
end = end === undefined ? length : toInteger(end)
|
end = end === undefined ? length : toInteger(end)
|
||||||
}
|
|
||||||
return baseSlice(array, start, end)
|
return baseSlice(array, start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
some.js
7
some.js
@@ -1,6 +1,5 @@
|
|||||||
import arraySome from './.internal/arraySome.js'
|
import arraySome from './.internal/arraySome.js'
|
||||||
import baseSome from './.internal/baseSome.js'
|
import baseSome from './.internal/baseSome.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `predicate` returns truthy for **any** element of `collection`.
|
* Checks if `predicate` returns truthy for **any** element of `collection`.
|
||||||
@@ -11,7 +10,6 @@ import isIterateeCall from './.internal/isIterateeCall.js'
|
|||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} predicate The function invoked per iteration.
|
* @param {Function} predicate The function invoked per iteration.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
||||||
* else `false`.
|
* else `false`.
|
||||||
* @example
|
* @example
|
||||||
@@ -19,11 +17,8 @@ import isIterateeCall from './.internal/isIterateeCall.js'
|
|||||||
* some([null, 0, 'yes', false], Boolean)
|
* some([null, 0, 'yes', false], Boolean)
|
||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function some(collection, predicate, guard) {
|
function some(collection, predicate) {
|
||||||
const func = Array.isArray(collection) ? arraySome : baseSome
|
const func = Array.isArray(collection) ? arraySome : baseSome
|
||||||
if (guard && isIterateeCall(collection, predicate, guard)) {
|
|
||||||
predicate = undefined
|
|
||||||
}
|
|
||||||
return func(collection, predicate)
|
return func(collection, predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
split.js
4
split.js
@@ -1,7 +1,6 @@
|
|||||||
import baseToString from './.internal/baseToString.js'
|
import baseToString from './.internal/baseToString.js'
|
||||||
import castSlice from './.internal/castSlice.js'
|
import castSlice from './.internal/castSlice.js'
|
||||||
import hasUnicode from './.internal/hasUnicode.js'
|
import hasUnicode from './.internal/hasUnicode.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import isRegExp from './isRegExp.js'
|
import isRegExp from './isRegExp.js'
|
||||||
import stringToArray from './.internal/stringToArray.js'
|
import stringToArray from './.internal/stringToArray.js'
|
||||||
import toString from './toString.js'
|
import toString from './toString.js'
|
||||||
@@ -27,9 +26,6 @@ const MAX_ARRAY_LENGTH = 4294967295
|
|||||||
* // => ['a', 'b']
|
* // => ['a', 'b']
|
||||||
*/
|
*/
|
||||||
function split(string, separator, limit) {
|
function split(string, separator, limit) {
|
||||||
if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
|
|
||||||
separator = limit = undefined
|
|
||||||
}
|
|
||||||
limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0
|
limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0
|
||||||
if (!limit) {
|
if (!limit) {
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import attempt from './attempt.js'
|
|||||||
import baseValues from './.internal/baseValues.js'
|
import baseValues from './.internal/baseValues.js'
|
||||||
import customDefaultsAssignIn from './.internal/customDefaultsAssignIn.js'
|
import customDefaultsAssignIn from './.internal/customDefaultsAssignIn.js'
|
||||||
import isError from './isError.js'
|
import isError from './isError.js'
|
||||||
import isIterateeCall from './.internal/isIterateeCall.js'
|
|
||||||
import keys from './keys.js'
|
import keys from './keys.js'
|
||||||
import reInterpolate from './.internal/reInterpolate.js'
|
import reInterpolate from './.internal/reInterpolate.js'
|
||||||
import templateSettings from './templateSettings.js'
|
import templateSettings from './templateSettings.js'
|
||||||
@@ -69,7 +68,6 @@ const stringEscapes = {
|
|||||||
* The sourceURL of the compiled template.
|
* The sourceURL of the compiled template.
|
||||||
* @param {string} [options.variable='obj']
|
* @param {string} [options.variable='obj']
|
||||||
* The data object variable name.
|
* The data object variable name.
|
||||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
|
||||||
* @returns {Function} Returns the compiled template function.
|
* @returns {Function} Returns the compiled template function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -138,15 +136,12 @@ const stringEscapes = {
|
|||||||
* };\
|
* };\
|
||||||
* ')
|
* ')
|
||||||
*/
|
*/
|
||||||
function template(string, options, guard) {
|
function template(string, options) {
|
||||||
// Based on John Resig's `tmpl` implementation
|
// Based on John Resig's `tmpl` implementation
|
||||||
// (http://ejohn.org/blog/javascript-micro-templating/)
|
// (http://ejohn.org/blog/javascript-micro-templating/)
|
||||||
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
||||||
const settings = templateSettings.imports.templateSettings || templateSettings
|
const settings = templateSettings.imports.templateSettings || templateSettings
|
||||||
|
|
||||||
if (guard && isIterateeCall(string, options, guard)) {
|
|
||||||
options = undefined
|
|
||||||
}
|
|
||||||
string = toString(string)
|
string = toString(string)
|
||||||
options = assignInWith({}, options, settings, customDefaultsAssignIn)
|
options = assignInWith({}, options, settings, customDefaultsAssignIn)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user