mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Remove remaining rest helper use.
This commit is contained in:
14
_castRest.js
14
_castRest.js
@@ -1,14 +0,0 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
|
||||
/**
|
||||
* A `baseRest` alias which can be replaced with `identity` by module
|
||||
* replacement plugins.
|
||||
*
|
||||
* @private
|
||||
* @type {Function}
|
||||
* @param {Function} func The function to apply a rest parameter to.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
const castRest = baseRest;
|
||||
|
||||
export default castRest;
|
||||
@@ -1,4 +1,3 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import isIterateeCall from './_isIterateeCall.js';
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import isIterateeCall from './_isIterateeCall.js';
|
||||
* @returns {Function} Returns the new assigner function.
|
||||
*/
|
||||
function createAssigner(assigner) {
|
||||
return baseRest((object, sources) => {
|
||||
return (object, ...sources) => {
|
||||
let index = -1;
|
||||
let length = sources.length;
|
||||
let customizer = length > 1 ? sources[length - 1] : undefined;
|
||||
@@ -31,7 +30,7 @@ function createAssigner(assigner) {
|
||||
}
|
||||
}
|
||||
return object;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default createAssigner;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import LodashWrapper from './_LodashWrapper.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
import getData from './_getData.js';
|
||||
import getFuncName from './_getFuncName.js';
|
||||
import isArray from './isArray.js';
|
||||
@@ -22,7 +21,7 @@ const WRAP_REARG_FLAG = 256;
|
||||
* @returns {Function} Returns the new flow function.
|
||||
*/
|
||||
function createFlow(fromRight) {
|
||||
return flatRest(funcs => {
|
||||
return (...funcs) => {
|
||||
const length = funcs.length;
|
||||
const prereq = LodashWrapper.prototype.thru;
|
||||
|
||||
@@ -74,7 +73,7 @@ function createFlow(fromRight) {
|
||||
}
|
||||
return result;
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default createFlow;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import apply from './_apply.js';
|
||||
import arrayMap from './_arrayMap.js';
|
||||
import baseIteratee from './_baseIteratee.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import baseUnary from './_baseUnary.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
|
||||
/**
|
||||
* Creates a function like `_.over`.
|
||||
@@ -13,13 +11,13 @@ import flatRest from './_flatRest.js';
|
||||
* @returns {Function} Returns the new over function.
|
||||
*/
|
||||
function createOver(arrayFunc) {
|
||||
return flatRest(iteratees => {
|
||||
return (...iteratees) => {
|
||||
iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
|
||||
return baseRest(function(args) {
|
||||
return (...args) => {
|
||||
const thisArg = this;
|
||||
return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args));
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default createOver;
|
||||
|
||||
16
_flatRest.js
16
_flatRest.js
@@ -1,16 +0,0 @@
|
||||
import flatten from './flatten.js';
|
||||
import overRest from './_overRest.js';
|
||||
import setToString from './_setToString.js';
|
||||
|
||||
/**
|
||||
* A specialized version of `baseRest` which flattens the rest array.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to apply a rest parameter to.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function flatRest(func) {
|
||||
return setToString(overRest(func, undefined, flatten), `${ func }`);
|
||||
}
|
||||
|
||||
export default flatRest;
|
||||
36
_overRest.js
36
_overRest.js
@@ -1,36 +0,0 @@
|
||||
import apply from './_apply.js';
|
||||
|
||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||
const nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* A specialized version of `baseRest` which transforms the rest array.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} func The function to apply a rest parameter to.
|
||||
* @param {number} [start=func.length-1] The start position of the rest parameter.
|
||||
* @param {Function} transform The rest array transform.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function overRest(func, start, transform) {
|
||||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
||||
return function() {
|
||||
const args = arguments;
|
||||
let index = -1;
|
||||
const length = nativeMax(args.length - start, 0);
|
||||
const array = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
array[index] = args[start + index];
|
||||
}
|
||||
index = -1;
|
||||
const otherArgs = Array(start + 1);
|
||||
while (++index < start) {
|
||||
otherArgs[index] = args[index];
|
||||
}
|
||||
otherArgs[start] = transform(array);
|
||||
return apply(func, this, otherArgs);
|
||||
};
|
||||
}
|
||||
|
||||
export default overRest;
|
||||
5
at.js
5
at.js
@@ -1,5 +1,4 @@
|
||||
import baseAt from './_baseAt.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
|
||||
/**
|
||||
* Creates an array of values corresponding to `paths` of `object`.
|
||||
@@ -18,6 +17,8 @@ import flatRest from './_flatRest.js';
|
||||
* _.at(object, ['a[0].b.c', 'a[1]']);
|
||||
* // => [3, 4]
|
||||
*/
|
||||
const at = flatRest(baseAt);
|
||||
function at(...paths) {
|
||||
return baseAt(paths);
|
||||
}
|
||||
|
||||
export default at;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import apply from './_apply.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import isError from './isError.js';
|
||||
|
||||
/**
|
||||
@@ -24,12 +23,12 @@ import isError from './isError.js';
|
||||
* elements = [];
|
||||
* }
|
||||
*/
|
||||
const attempt = baseRest((func, args) => {
|
||||
function attempt(func, ...args) {
|
||||
try {
|
||||
return apply(func, undefined, args);
|
||||
} catch (e) {
|
||||
return isError(e) ? e : new Error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default attempt;
|
||||
|
||||
5
bind.js
5
bind.js
@@ -1,4 +1,3 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import createWrap from './_createWrap.js';
|
||||
import getHolder from './_getHolder.js';
|
||||
import replaceHolders from './_replaceHolders.js';
|
||||
@@ -42,7 +41,7 @@ const WRAP_PARTIAL_FLAG = 32;
|
||||
* bound('hi');
|
||||
* // => 'hi fred!'
|
||||
*/
|
||||
const bind = baseRest((func, thisArg, partials) => {
|
||||
function bind(func, thisArg, ...partials) {
|
||||
let holders;
|
||||
let bitmask = WRAP_BIND_FLAG;
|
||||
if (partials.length) {
|
||||
@@ -50,7 +49,7 @@ const bind = baseRest((func, thisArg, partials) => {
|
||||
bitmask |= WRAP_PARTIAL_FLAG;
|
||||
}
|
||||
return createWrap(func, bitmask, thisArg, partials, holders);
|
||||
});
|
||||
}
|
||||
|
||||
// Assign default placeholders.
|
||||
bind.placeholder = {};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import arrayEach from './_arrayEach.js';
|
||||
import baseAssignValue from './_baseAssignValue.js';
|
||||
import bind from './bind.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
import toKey from './_toKey.js';
|
||||
|
||||
/**
|
||||
@@ -30,12 +29,12 @@ import toKey from './_toKey.js';
|
||||
* jQuery(element).on('click', view.click);
|
||||
* // => Logs 'clicked docs' when clicked.
|
||||
*/
|
||||
const bindAll = flatRest((object, methodNames) => {
|
||||
function bindAll(object, ...methodNames) {
|
||||
arrayEach(methodNames, key => {
|
||||
key = toKey(key);
|
||||
baseAssignValue(object, key, bind(object[key], object));
|
||||
});
|
||||
return object;
|
||||
});
|
||||
}
|
||||
|
||||
export default bindAll;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import createWrap from './_createWrap.js';
|
||||
import getHolder from './_getHolder.js';
|
||||
import replaceHolders from './_replaceHolders.js';
|
||||
@@ -53,7 +52,7 @@ const WRAP_PARTIAL_FLAG = 32;
|
||||
* bound('hi');
|
||||
* // => 'hiya fred!'
|
||||
*/
|
||||
const bindKey = baseRest((object, key, partials) => {
|
||||
function bindKey(object, key, ...partials) {
|
||||
let holders;
|
||||
let bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
|
||||
if (partials.length) {
|
||||
@@ -61,7 +60,7 @@ const bindKey = baseRest((object, key, partials) => {
|
||||
bitmask |= WRAP_PARTIAL_FLAG;
|
||||
}
|
||||
return createWrap(key, bitmask, object, partials, holders);
|
||||
});
|
||||
}
|
||||
|
||||
// Assign default placeholders.
|
||||
bindKey.placeholder = {};
|
||||
|
||||
5
cond.js
5
cond.js
@@ -1,7 +1,6 @@
|
||||
import apply from './_apply.js';
|
||||
import arrayMap from './_arrayMap.js';
|
||||
import baseIteratee from './_baseIteratee.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
|
||||
/** Error message constants. */
|
||||
const FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -46,7 +45,7 @@ function cond(pairs) {
|
||||
return [toIteratee(pair[0]), pair[1]];
|
||||
});
|
||||
|
||||
return baseRest(function(args) {
|
||||
return (...args) => {
|
||||
let index = -1;
|
||||
while (++index < length) {
|
||||
const pair = pairs[index];
|
||||
@@ -54,7 +53,7 @@ function cond(pairs) {
|
||||
return apply(pair[1], this, args);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default cond;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import apply from './_apply.js';
|
||||
import assignInWith from './assignInWith.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import customDefaultsAssignIn from './_customDefaultsAssignIn.js';
|
||||
|
||||
/**
|
||||
@@ -24,9 +23,9 @@ import customDefaultsAssignIn from './_customDefaultsAssignIn.js';
|
||||
* _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
|
||||
* // => { 'a': 1, 'b': 2 }
|
||||
*/
|
||||
const defaults = baseRest(args => {
|
||||
function defaults(...args) {
|
||||
args.push(undefined, customDefaultsAssignIn);
|
||||
return apply(assignInWith, undefined, args);
|
||||
});
|
||||
}
|
||||
|
||||
export default defaults;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import apply from './_apply.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import customDefaultsMerge from './_customDefaultsMerge.js';
|
||||
import mergeWith from './mergeWith.js';
|
||||
|
||||
@@ -22,9 +21,9 @@ import mergeWith from './mergeWith.js';
|
||||
* _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
|
||||
* // => { 'a': { 'b': 2, 'c': 3 } }
|
||||
*/
|
||||
const defaultsDeep = baseRest(args => {
|
||||
function defaultsDeep(...args) {
|
||||
args.push(undefined, customDefaultsMerge);
|
||||
return apply(mergeWith, undefined, args);
|
||||
});
|
||||
}
|
||||
|
||||
export default defaultsDeep;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import baseInvoke from './_baseInvoke.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
|
||||
/**
|
||||
* Invokes the method at `path` of `object`.
|
||||
@@ -19,6 +18,8 @@ import baseRest from './_baseRest.js';
|
||||
* _.invoke(object, 'a[0].b.c.slice', 1, 3);
|
||||
* // => [2, 3]
|
||||
*/
|
||||
const invoke = baseRest(baseInvoke);
|
||||
function invoke(object, path, ...args) {
|
||||
return baseInvoke(object, path, args);
|
||||
}
|
||||
|
||||
export default invoke;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import baseInvoke from './_baseInvoke.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes the method at `path` of a given object.
|
||||
@@ -25,6 +24,8 @@ import baseRest from './_baseRest.js';
|
||||
* _.map(objects, _.method(['a', 'b']));
|
||||
* // => [2, 1]
|
||||
*/
|
||||
const method = baseRest((path, args) => object => baseInvoke(object, path, args));
|
||||
function method(path, ...args) {
|
||||
return object => baseInvoke(object, path, args);
|
||||
}
|
||||
|
||||
export default method;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import baseInvoke from './_baseInvoke.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
|
||||
/**
|
||||
* The opposite of `_.method`; this method creates a function that invokes
|
||||
@@ -24,6 +23,8 @@ import baseRest from './_baseRest.js';
|
||||
* _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
||||
* // => [2, 0]
|
||||
*/
|
||||
const methodOf = baseRest((object, args) => path => baseInvoke(object, path, args));
|
||||
function methodOf(object, ...args) {
|
||||
return path => baseInvoke(object, path, args);
|
||||
}
|
||||
|
||||
export default methodOf;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import baseNth from './_baseNth.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import toInteger from './toInteger.js';
|
||||
|
||||
/**
|
||||
@@ -24,7 +23,7 @@ import toInteger from './toInteger.js';
|
||||
*/
|
||||
function nthArg(n) {
|
||||
n = toInteger(n);
|
||||
return baseRest(args => baseNth(args, n));
|
||||
return (...args) => baseNth(args, n);
|
||||
}
|
||||
|
||||
export default nthArg;
|
||||
|
||||
5
pick.js
5
pick.js
@@ -1,5 +1,4 @@
|
||||
import basePick from './_basePick.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
|
||||
/**
|
||||
* Creates an object composed of the picked `object` properties.
|
||||
@@ -18,6 +17,8 @@ import flatRest from './_flatRest.js';
|
||||
* _.pick(object, ['a', 'c']);
|
||||
* // => { 'a': 1, 'c': 3 }
|
||||
*/
|
||||
const pick = flatRest((object, paths) => object == null ? {} : basePick(object, paths));
|
||||
function pick(object, ...paths) {
|
||||
return object == null ? {} : basePick(object, paths);
|
||||
}
|
||||
|
||||
export default pick;
|
||||
|
||||
5
pull.js
5
pull.js
@@ -1,4 +1,3 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import pullAll from './pullAll.js';
|
||||
|
||||
/**
|
||||
@@ -24,6 +23,8 @@ import pullAll from './pullAll.js';
|
||||
* console.log(array);
|
||||
* // => ['b', 'b']
|
||||
*/
|
||||
const pull = baseRest(pullAll);
|
||||
function pull(array, ...values) {
|
||||
return pullAll(array, values);
|
||||
}
|
||||
|
||||
export default pull;
|
||||
|
||||
@@ -2,7 +2,6 @@ import arrayMap from './_arrayMap.js';
|
||||
import baseAt from './_baseAt.js';
|
||||
import basePullAt from './_basePullAt.js';
|
||||
import compareAscending from './_compareAscending.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
import isIndex from './_isIndex.js';
|
||||
|
||||
/**
|
||||
@@ -29,12 +28,12 @@ import isIndex from './_isIndex.js';
|
||||
* console.log(pulled);
|
||||
* // => ['b', 'd']
|
||||
*/
|
||||
const pullAt = flatRest((array, indexes) => {
|
||||
const length = array == null ? 0 : array.length, result = baseAt(array, indexes);
|
||||
function pullAt(array, ...indexes) {
|
||||
const length = array == null ? 0 : array.length;
|
||||
const result = baseAt(array, indexes);
|
||||
|
||||
basePullAt(array, arrayMap(indexes, index => isIndex(index, length) ? +index : index).sort(compareAscending));
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
export default pullAt;
|
||||
|
||||
5
rearg.js
5
rearg.js
@@ -1,5 +1,4 @@
|
||||
import createWrap from './_createWrap.js';
|
||||
import flatRest from './_flatRest.js';
|
||||
|
||||
/** Used to compose bitmasks for function metadata. */
|
||||
const WRAP_REARG_FLAG = 256;
|
||||
@@ -26,6 +25,8 @@ const WRAP_REARG_FLAG = 256;
|
||||
* rearged('b', 'c', 'a')
|
||||
* // => ['a', 'b', 'c']
|
||||
*/
|
||||
const rearg = flatRest((func, indexes) => createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes));
|
||||
function rearg(func, ...indexes) {
|
||||
return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
|
||||
}
|
||||
|
||||
export default rearg;
|
||||
|
||||
40
rest.js
40
rest.js
@@ -1,40 +0,0 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import toInteger from './toInteger.js';
|
||||
|
||||
/** Error message constants. */
|
||||
const FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of the
|
||||
* created function and arguments from `start` and beyond provided as
|
||||
* an array.
|
||||
*
|
||||
* **Note:** This method is based on the
|
||||
* [rest parameter](https://mdn.io/rest_parameters).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Function
|
||||
* @param {Function} func The function to apply a rest parameter to.
|
||||
* @param {number} [start=func.length-1] The start position of the rest parameter.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var say = _.rest(function(what, names) {
|
||||
* return what + ' ' + _.initial(names).join(', ') +
|
||||
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
||||
* });
|
||||
*
|
||||
* say('hello', 'fred', 'barney', 'pebbles');
|
||||
* // => 'hello fred, barney, & pebbles'
|
||||
*/
|
||||
function rest(func, start) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
start = start === undefined ? start : toInteger(start);
|
||||
return baseRest(func, start);
|
||||
}
|
||||
|
||||
export default rest;
|
||||
@@ -1,6 +1,5 @@
|
||||
import apply from './_apply.js';
|
||||
import arrayPush from './_arrayPush.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import castSlice from './_castSlice.js';
|
||||
import toInteger from './toInteger.js';
|
||||
|
||||
@@ -49,7 +48,7 @@ function spread(func, start) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
start = start == null ? 0 : nativeMax(toInteger(start), 0);
|
||||
return baseRest(function(args) {
|
||||
return (...args) => {
|
||||
const array = args[start];
|
||||
const otherArgs = castSlice(args, 0, start);
|
||||
|
||||
@@ -57,7 +56,7 @@ function spread(func, start) {
|
||||
arrayPush(otherArgs, array);
|
||||
}
|
||||
return apply(func, this, otherArgs);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default spread;
|
||||
|
||||
5
zip.js
5
zip.js
@@ -1,4 +1,3 @@
|
||||
import baseRest from './_baseRest.js';
|
||||
import unzip from './unzip.js';
|
||||
|
||||
/**
|
||||
@@ -17,6 +16,8 @@ import unzip from './unzip.js';
|
||||
* _.zip(['a', 'b'], [1, 2], [true, false]);
|
||||
* // => [['a', 1, true], ['b', 2, false]]
|
||||
*/
|
||||
const zip = baseRest(unzip);
|
||||
function zip(...arays) {
|
||||
return unzip(arrays);
|
||||
}
|
||||
|
||||
export default zip;
|
||||
|
||||
Reference in New Issue
Block a user