Remove isIterateeCall.

This commit is contained in:
John-David Dalton
2017-03-03 23:32:24 -08:00
parent ba52c744ae
commit 17f7069d07
11 changed files with 11 additions and 93 deletions

View File

@@ -1,5 +1,4 @@
import baseRange from './baseRange.js'
import isIterateeCall from './isIterateeCall.js'
import toFinite from '../toFinite.js'
/**
@@ -11,9 +10,6 @@ import toFinite from '../toFinite.js'
*/
function createRange(fromRight) {
return (start, end, step) => {
if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
end = step = undefined
}
// Ensure the sign of `-0` is preserved.
start = toFinite(start)
if (end === undefined) {

View File

@@ -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

View File

@@ -1,5 +1,4 @@
import baseSlice from './.internal/baseSlice.js'
import isIterateeCall from './.internal/isIterateeCall.js'
import toInteger from './toInteger.js'
/* Built-in method references for those with the same name as other `lodash` methods. */
@@ -15,7 +14,6 @@ const nativeMax = Math.max
* @category Array
* @param {Array} array The array to process.
* @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.
* @example
*
@@ -25,12 +23,8 @@ const nativeMax = Math.max
* chunk(['a', 'b', 'c', 'd'], 3)
* // => [['a', 'b', 'c'], ['d']]
*/
function chunk(array, size, guard) {
if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
size = 1
} else {
size = nativeMax(toInteger(size), 0)
}
function chunk(array, size) {
size = nativeMax(toInteger(size), 0)
const length = array == null ? 0 : array.length
if (!length || size < 1) {
return []

View File

@@ -1,6 +1,5 @@
import arrayEvery from './.internal/arrayEvery.js'
import baseEvery from './.internal/baseEvery.js'
import isIterateeCall from './.internal/isIterateeCall.js'
/**
* Checks if `predicate` returns truthy for **all** elements of `collection`.
@@ -16,7 +15,6 @@ import isIterateeCall from './.internal/isIterateeCall.js'
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @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,
* else `false`.
* @example
@@ -24,11 +22,8 @@ import isIterateeCall from './.internal/isIterateeCall.js'
* every([true, 1, null, 'yes'], Boolean)
* // => false
*/
function every(collection, predicate, guard) {
function every(collection, predicate) {
const func = Array.isArray(collection) ? arrayEvery : baseEvery
if (guard && isIterateeCall(collection, predicate, guard)) {
predicate = undefined
}
return func(collection, predicate)
}

View File

@@ -1,4 +1,3 @@
import isIterateeCall from './.internal/isIterateeCall.js'
import toFinite from './toFinite.js'
/** 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
*/
function random(lower, upper, floating) {
if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
upper = floating = undefined
}
if (floating === undefined) {
if (typeof upper == 'boolean') {
floating = upper

View File

@@ -1,5 +1,4 @@
import baseRepeat from './.internal/baseRepeat.js'
import isIterateeCall from './.internal/isIterateeCall.js'
import toInteger from './toInteger.js'
import toString from './toString.js'
@@ -10,7 +9,6 @@ import toString from './toString.js'
* @category String
* @param {string} [string=''] The string to repeat.
* @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.
* @example
*
@@ -23,12 +21,8 @@ import toString from './toString.js'
* repeat('abc', 0)
* // => ''
*/
function repeat(string, n, guard) {
if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
n = 1
} else {
n = toInteger(n)
}
function repeat(string, n) {
n = toInteger(n)
return baseRepeat(toString(string), n)
}

View File

@@ -1,4 +1,3 @@
import isIterateeCall from './.internal/isIterateeCall.js'
import copyArray from './.internal/copyArray.js'
import toInteger from './toInteger.js'
@@ -10,7 +9,6 @@ import toInteger from './toInteger.js'
* @category Array
* @param {Array} array The array 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.
* @example
*
@@ -20,12 +18,8 @@ import toInteger from './toInteger.js'
* sampleSize([1, 2, 3], 4)
* // => [2, 3, 1]
*/
function sampleSize(array, n, guard) {
if ((guard ? isIterateeCall(array, n, guard) : n === undefined)) {
n = 1
} else {
n = toInteger(n)
}
function sampleSize(array, n) {
n = toInteger(n)
const length = array == null ? 0 : array.length
if (!length || n < 1) {
return []

View File

@@ -1,5 +1,4 @@
import baseSlice from './.internal/baseSlice.js'
import isIterateeCall from './.internal/isIterateeCall.js'
import toInteger from './toInteger.js'
/**
@@ -21,14 +20,8 @@ function slice(array, start, end) {
if (!length) {
return []
}
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
start = 0
end = length
}
else {
start = start == null ? 0 : toInteger(start)
end = end === undefined ? length : toInteger(end)
}
start = start == null ? 0 : toInteger(start)
end = end === undefined ? length : toInteger(end)
return baseSlice(array, start, end)
}

View File

@@ -1,6 +1,5 @@
import arraySome from './.internal/arraySome.js'
import baseSome from './.internal/baseSome.js'
import isIterateeCall from './.internal/isIterateeCall.js'
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
@@ -11,7 +10,6 @@ import isIterateeCall from './.internal/isIterateeCall.js'
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @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,
* else `false`.
* @example
@@ -19,11 +17,8 @@ import isIterateeCall from './.internal/isIterateeCall.js'
* some([null, 0, 'yes', false], Boolean)
* // => true
*/
function some(collection, predicate, guard) {
function some(collection, predicate) {
const func = Array.isArray(collection) ? arraySome : baseSome
if (guard && isIterateeCall(collection, predicate, guard)) {
predicate = undefined
}
return func(collection, predicate)
}

View File

@@ -1,7 +1,6 @@
import baseToString from './.internal/baseToString.js'
import castSlice from './.internal/castSlice.js'
import hasUnicode from './.internal/hasUnicode.js'
import isIterateeCall from './.internal/isIterateeCall.js'
import isRegExp from './isRegExp.js'
import stringToArray from './.internal/stringToArray.js'
import toString from './toString.js'
@@ -27,9 +26,6 @@ const MAX_ARRAY_LENGTH = 4294967295
* // => ['a', 'b']
*/
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
if (!limit) {
return []

View File

@@ -3,7 +3,6 @@ import attempt from './attempt.js'
import baseValues from './.internal/baseValues.js'
import customDefaultsAssignIn from './.internal/customDefaultsAssignIn.js'
import isError from './isError.js'
import isIterateeCall from './.internal/isIterateeCall.js'
import keys from './keys.js'
import reInterpolate from './.internal/reInterpolate.js'
import templateSettings from './templateSettings.js'
@@ -69,7 +68,6 @@ const stringEscapes = {
* The sourceURL of the compiled template.
* @param {string} [options.variable='obj']
* The data object variable name.
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
* @returns {Function} Returns the compiled template function.
* @example
*
@@ -138,15 +136,12 @@ const stringEscapes = {
* };\
* ')
*/
function template(string, options, guard) {
function template(string, options) {
// Based on John Resig's `tmpl` implementation
// (http://ejohn.org/blog/javascript-micro-templating/)
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
const settings = templateSettings.imports.templateSettings || templateSettings
if (guard && isIterateeCall(string, options, guard)) {
options = undefined
}
string = toString(string)
options = assignInWith({}, options, settings, customDefaultsAssignIn)