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