mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Use more ES2015.
This commit is contained in:
@@ -12,7 +12,7 @@ import baseEach from './_baseEach.js';
|
|||||||
* @returns {Function} Returns `accumulator`.
|
* @returns {Function} Returns `accumulator`.
|
||||||
*/
|
*/
|
||||||
function baseAggregator(collection, setter, iteratee, accumulator) {
|
function baseAggregator(collection, setter, iteratee, accumulator) {
|
||||||
baseEach(collection, function(value, key, collection) {
|
baseEach(collection, (value, key, collection) => {
|
||||||
setter(accumulator, value, iteratee(value), collection);
|
setter(accumulator, value, iteratee(value), collection);
|
||||||
});
|
});
|
||||||
return accumulator;
|
return accumulator;
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ import isObject from './isObject.js';
|
|||||||
import keys from './keys.js';
|
import keys from './keys.js';
|
||||||
|
|
||||||
/** Used to compose bitmasks for cloning. */
|
/** Used to compose bitmasks for cloning. */
|
||||||
var CLONE_DEEP_FLAG = 1,
|
const CLONE_DEEP_FLAG = 1;
|
||||||
CLONE_FLAT_FLAG = 2,
|
const CLONE_FLAT_FLAG = 2;
|
||||||
CLONE_SYMBOLS_FLAG = 4;
|
const CLONE_SYMBOLS_FLAG = 4;
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var argsTag = '[object Arguments]',
|
const argsTag = '[object Arguments]',
|
||||||
arrayTag = '[object Array]',
|
arrayTag = '[object Array]',
|
||||||
boolTag = '[object Boolean]',
|
boolTag = '[object Boolean]',
|
||||||
dateTag = '[object Date]',
|
dateTag = '[object Date]',
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ import keys from './keys.js';
|
|||||||
* @returns {Function} Returns the new spec function.
|
* @returns {Function} Returns the new spec function.
|
||||||
*/
|
*/
|
||||||
function baseConforms(source) {
|
function baseConforms(source) {
|
||||||
var props = keys(source);
|
const props = keys(source);
|
||||||
return function(object) {
|
return object => baseConformsTo(object, source, props);
|
||||||
return baseConformsTo(object, source, props);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseConforms;
|
export default baseConforms;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import isObject from './isObject.js';
|
import isObject from './isObject.js';
|
||||||
|
|
||||||
/** Built-in value references. */
|
/** Built-in value references. */
|
||||||
var objectCreate = Object.create;
|
const objectCreate = Object.create;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.create` without support for assigning
|
* The base implementation of `_.create` without support for assigning
|
||||||
@@ -11,9 +11,9 @@ var objectCreate = Object.create;
|
|||||||
* @param {Object} proto The object to inherit from.
|
* @param {Object} proto The object to inherit from.
|
||||||
* @returns {Object} Returns the new object.
|
* @returns {Object} Returns the new object.
|
||||||
*/
|
*/
|
||||||
var baseCreate = (function() {
|
const baseCreate = (() => {
|
||||||
function object() {}
|
function object() {}
|
||||||
return function(proto) {
|
return proto => {
|
||||||
if (!isObject(proto)) {
|
if (!isObject(proto)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,6 @@ var baseCreate = (function() {
|
|||||||
object.prototype = undefined;
|
object.prototype = undefined;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}());
|
})();
|
||||||
|
|
||||||
export default baseCreate;
|
export default baseCreate;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/** Error message constants. */
|
/** Error message constants. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
const FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.delay` and `_.defer` which accepts `args`
|
* The base implementation of `_.delay` and `_.defer` which accepts `args`
|
||||||
@@ -15,7 +15,7 @@ function baseDelay(func, wait, args) {
|
|||||||
if (typeof func != 'function') {
|
if (typeof func != 'function') {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
return setTimeout(function() { func.apply(undefined, args); }, wait);
|
return setTimeout(() => func.apply(undefined, args), wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseDelay;
|
export default baseDelay;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import baseEach from './_baseEach.js';
|
|||||||
* else `false`
|
* else `false`
|
||||||
*/
|
*/
|
||||||
function baseEvery(collection, predicate) {
|
function baseEvery(collection, predicate) {
|
||||||
var result = true;
|
let result = true;
|
||||||
baseEach(collection, function(value, index, collection) {
|
baseEach(collection, (value, index, collection) => {
|
||||||
result = !!predicate(value, index, collection);
|
result = !!predicate(value, index, collection);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import baseEach from './_baseEach.js';
|
|||||||
* @returns {Array} Returns the new filtered array.
|
* @returns {Array} Returns the new filtered array.
|
||||||
*/
|
*/
|
||||||
function baseFilter(collection, predicate) {
|
function baseFilter(collection, predicate) {
|
||||||
var result = [];
|
const result = [];
|
||||||
baseEach(collection, function(value, index, collection) {
|
baseEach(collection, (value, index, collection) => {
|
||||||
if (predicate(value, index, collection)) {
|
if (predicate(value, index, collection)) {
|
||||||
result.push(value);
|
result.push(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
* @returns {*} Returns the found element or its key, else `undefined`.
|
* @returns {*} Returns the found element or its key, else `undefined`.
|
||||||
*/
|
*/
|
||||||
function baseFindKey(collection, predicate, eachFunc) {
|
function baseFindKey(collection, predicate, eachFunc) {
|
||||||
var result;
|
let result;
|
||||||
eachFunc(collection, function(value, key, collection) {
|
eachFunc(collection, (value, key, collection) => {
|
||||||
if (predicate(value, key, collection)) {
|
if (predicate(value, key, collection)) {
|
||||||
result = key;
|
result = key;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import isFunction from './isFunction.js';
|
|||||||
* @returns {Array} Returns the function names.
|
* @returns {Array} Returns the function names.
|
||||||
*/
|
*/
|
||||||
function baseFunctions(object, props) {
|
function baseFunctions(object, props) {
|
||||||
return arrayFilter(props, function(key) {
|
return arrayFilter(props, key => isFunction(object[key]));
|
||||||
return isFunction(object[key]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseFunctions;
|
export default baseFunctions;
|
||||||
|
|||||||
@@ -7,23 +7,23 @@ import toSource from './_toSource.js';
|
|||||||
* Used to match `RegExp`
|
* Used to match `RegExp`
|
||||||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
||||||
*/
|
*/
|
||||||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
||||||
|
|
||||||
/** Used to detect host constructors (Safari). */
|
/** Used to detect host constructors (Safari). */
|
||||||
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
const reIsHostCtor = /^\[object .+?Constructor\]$/;
|
||||||
|
|
||||||
/** Used for built-in method references. */
|
/** Used for built-in method references. */
|
||||||
var funcProto = Function.prototype,
|
const funcProto = Function.prototype;
|
||||||
objectProto = Object.prototype;
|
const objectProto = Object.prototype;
|
||||||
|
|
||||||
/** Used to resolve the decompiled source of functions. */
|
/** Used to resolve the decompiled source of functions. */
|
||||||
var funcToString = funcProto.toString;
|
const funcToString = funcProto.toString;
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
/** Used to check objects for own properties. */
|
||||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
const hasOwnProperty = objectProto.hasOwnProperty;
|
||||||
|
|
||||||
/** Used to detect if a method is native. */
|
/** Used to detect if a method is native. */
|
||||||
var reIsNative = RegExp('^' +
|
const reIsNative = RegExp('^' +
|
||||||
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
||||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||||
);
|
);
|
||||||
@@ -40,7 +40,7 @@ function baseIsNative(value) {
|
|||||||
if (!isObject(value) || isMasked(value)) {
|
if (!isObject(value) || isMasked(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
const pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
||||||
return pattern.test(toSource(value));
|
return pattern.test(toSource(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import isArrayLike from './isArrayLike.js';
|
|||||||
* @returns {Array} Returns the new mapped array.
|
* @returns {Array} Returns the new mapped array.
|
||||||
*/
|
*/
|
||||||
function baseMap(collection, iteratee) {
|
function baseMap(collection, iteratee) {
|
||||||
var index = -1,
|
let index = -1;
|
||||||
result = isArrayLike(collection) ? Array(collection.length) : [];
|
const result = isArrayLike(collection) ? Array(collection.length) : [];
|
||||||
|
|
||||||
baseEach(collection, function(value, key, collection) {
|
baseEach(collection, (value, key, collection) => {
|
||||||
result[++index] = iteratee(value, key, collection);
|
result[++index] = iteratee(value, key, collection);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
|
|||||||
if (object === source) {
|
if (object === source) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
baseFor(source, function(srcValue, key) {
|
baseFor(source, (srcValue, key) => {
|
||||||
if (isObject(srcValue)) {
|
if (isObject(srcValue)) {
|
||||||
stack || (stack = new Stack);
|
stack || (stack = new Stack);
|
||||||
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var newValue = customizer
|
const newValue = customizer
|
||||||
? customizer(object[key], srcValue, (key + ''), object, source, stack)
|
? customizer(object[key], srcValue, (key + ''), object, source, stack)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|||||||
6
union.js
6
union.js
@@ -1,5 +1,4 @@
|
|||||||
import baseFlatten from './_baseFlatten.js';
|
import baseFlatten from './_baseFlatten.js';
|
||||||
import baseRest from './_baseRest.js';
|
|
||||||
import baseUniq from './_baseUniq.js';
|
import baseUniq from './_baseUniq.js';
|
||||||
import isArrayLikeObject from './isArrayLikeObject.js';
|
import isArrayLikeObject from './isArrayLikeObject.js';
|
||||||
|
|
||||||
@@ -19,8 +18,7 @@ import isArrayLikeObject from './isArrayLikeObject.js';
|
|||||||
* _.union([2], [1, 2]);
|
* _.union([2], [1, 2]);
|
||||||
* // => [2, 1]
|
* // => [2, 1]
|
||||||
*/
|
*/
|
||||||
var union = baseRest(function(arrays) {
|
const union = (...arrays) =>
|
||||||
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
||||||
});
|
|
||||||
|
|
||||||
export default union;
|
export default union;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import baseFlatten from './_baseFlatten.js';
|
import baseFlatten from './_baseFlatten.js';
|
||||||
import baseIteratee from './_baseIteratee.js';
|
import baseIteratee from './_baseIteratee.js';
|
||||||
import baseRest from './_baseRest.js';
|
|
||||||
import baseUniq from './_baseUniq.js';
|
import baseUniq from './_baseUniq.js';
|
||||||
import isArrayLikeObject from './isArrayLikeObject.js';
|
import isArrayLikeObject from './isArrayLikeObject.js';
|
||||||
import last from './last.js';
|
import last from './last.js';
|
||||||
@@ -28,12 +27,12 @@ import last from './last.js';
|
|||||||
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||||
*/
|
*/
|
||||||
var unionBy = baseRest(function(arrays) {
|
const unionBy = (...arrays) => {
|
||||||
var iteratee = last(arrays);
|
let iteratee = last(arrays);
|
||||||
if (isArrayLikeObject(iteratee)) {
|
if (isArrayLikeObject(iteratee)) {
|
||||||
iteratee = undefined;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2));
|
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2));
|
||||||
});
|
};
|
||||||
|
|
||||||
export default unionBy;
|
export default unionBy;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseDifference from './_baseDifference.js';
|
import baseDifference from './_baseDifference.js';
|
||||||
import baseRest from './_baseRest.js';
|
|
||||||
import isArrayLikeObject from './isArrayLikeObject.js';
|
import isArrayLikeObject from './isArrayLikeObject.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,10 +21,7 @@ import isArrayLikeObject from './isArrayLikeObject.js';
|
|||||||
* _.without([2, 1, 2, 3], 1, 2);
|
* _.without([2, 1, 2, 3], 1, 2);
|
||||||
* // => [3]
|
* // => [3]
|
||||||
*/
|
*/
|
||||||
var without = baseRest(function(array, values) {
|
const without = (array, ...values) =>
|
||||||
return isArrayLikeObject(array)
|
isArrayLikeObject(array) ? baseDifference(array, values) : [];
|
||||||
? baseDifference(array, values)
|
|
||||||
: [];
|
|
||||||
});
|
|
||||||
|
|
||||||
export default without;
|
export default without;
|
||||||
|
|||||||
6
xor.js
6
xor.js
@@ -1,5 +1,4 @@
|
|||||||
import arrayFilter from './_arrayFilter.js';
|
import arrayFilter from './_arrayFilter.js';
|
||||||
import baseRest from './_baseRest.js';
|
|
||||||
import baseXor from './_baseXor.js';
|
import baseXor from './_baseXor.js';
|
||||||
import isArrayLikeObject from './isArrayLikeObject.js';
|
import isArrayLikeObject from './isArrayLikeObject.js';
|
||||||
|
|
||||||
@@ -21,8 +20,7 @@ import isArrayLikeObject from './isArrayLikeObject.js';
|
|||||||
* _.xor([2, 1], [2, 3]);
|
* _.xor([2, 1], [2, 3]);
|
||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*/
|
*/
|
||||||
var xor = baseRest(function(arrays) {
|
const xor = (...arrays) =>
|
||||||
return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
baseXor(arrayFilter(arrays, isArrayLikeObject));
|
||||||
});
|
|
||||||
|
|
||||||
export default xor;
|
export default xor;
|
||||||
|
|||||||
7
xorBy.js
7
xorBy.js
@@ -1,6 +1,5 @@
|
|||||||
import arrayFilter from './_arrayFilter.js';
|
import arrayFilter from './_arrayFilter.js';
|
||||||
import baseIteratee from './_baseIteratee.js';
|
import baseIteratee from './_baseIteratee.js';
|
||||||
import baseRest from './_baseRest.js';
|
|
||||||
import baseXor from './_baseXor.js';
|
import baseXor from './_baseXor.js';
|
||||||
import isArrayLikeObject from './isArrayLikeObject.js';
|
import isArrayLikeObject from './isArrayLikeObject.js';
|
||||||
import last from './last.js';
|
import last from './last.js';
|
||||||
@@ -28,12 +27,12 @@ import last from './last.js';
|
|||||||
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||||
* // => [{ 'x': 2 }]
|
* // => [{ 'x': 2 }]
|
||||||
*/
|
*/
|
||||||
var xorBy = baseRest(function(arrays) {
|
const xorBy = (...arrays) => {
|
||||||
var iteratee = last(arrays);
|
let iteratee = last(arrays);
|
||||||
if (isArrayLikeObject(iteratee)) {
|
if (isArrayLikeObject(iteratee)) {
|
||||||
iteratee = undefined;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2));
|
return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2));
|
||||||
});
|
};
|
||||||
|
|
||||||
export default xorBy;
|
export default xorBy;
|
||||||
|
|||||||
Reference in New Issue
Block a user