From 63d9a3fc42f12853de2c83497e5c68541dc61a4a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 12 Apr 2016 22:18:39 -0700 Subject: [PATCH] Bump to v4.11.0. --- README.md | 4 +- _baseNth.js | 24 +++++++ _baseOrderBy.js | 4 +- _copyObject.js | 21 +++++- _copyObjectWith.js | 33 --------- _createCompounder.js | 8 ++- _createOver.js | 7 +- _createRecurryWrapper.js | 5 +- _mergeData.js | 12 ++-- array.js | 3 +- assignInWith.js | 4 +- assignWith.js | 4 +- head.js | 2 +- main.js | 147 ++++++++++++++++++++++++++------------- nth.js | 32 +++++++++ nthArg.js | 18 +++-- overArgs.js | 7 +- package.json | 2 +- replace.js | 8 ++- sortBy.js | 8 ++- split.js | 8 ++- words.js | 13 ++-- wrapperLodash.js | 2 +- 23 files changed, 250 insertions(+), 126 deletions(-) create mode 100644 _baseNth.js delete mode 100644 _copyObjectWith.js create mode 100644 nth.js diff --git a/README.md b/README.md index fc373770c..2e518b463 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.10.0 +# lodash-amd v4.11.0 The [Lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. @@ -27,4 +27,4 @@ require({ }); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.10.0-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.11.0-amd) for more details. diff --git a/_baseNth.js b/_baseNth.js new file mode 100644 index 000000000..d3a1ecfea --- /dev/null +++ b/_baseNth.js @@ -0,0 +1,24 @@ +define(['./_isIndex'], function(isIndex) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * The base implementation of `_.nth` which doesn't coerce `n` to an integer. + * + * @private + * @param {Array} array The array to query. + * @param {number} n The index of the element to return. + * @returns {*} Returns the nth element of `array`. + */ + function baseNth(array, n) { + var length = array.length; + if (!length) { + return; + } + n += n < 0 ? length : 0; + return isIndex(n, length) ? array[n] : undefined; + } + + return baseNth; +}); diff --git a/_baseOrderBy.js b/_baseOrderBy.js index 3d555b236..06fec4c6b 100644 --- a/_baseOrderBy.js +++ b/_baseOrderBy.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_compareMultiple', './identity'], function(arrayMap, baseIteratee, baseMap, baseSortBy, compareMultiple, identity) { +define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_baseUnary', './_compareMultiple', './identity'], function(arrayMap, baseIteratee, baseMap, baseSortBy, baseUnary, compareMultiple, identity) { /** * The base implementation of `_.orderBy` without param guards. @@ -11,7 +11,7 @@ define(['./_arrayMap', './_baseIteratee', './_baseMap', './_baseSortBy', './_com */ function baseOrderBy(collection, iteratees, orders) { var index = -1; - iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseIteratee); + iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(baseIteratee)); var result = baseMap(collection, function(value, key, collection) { var criteria = arrayMap(iteratees, function(iteratee) { diff --git a/_copyObject.js b/_copyObject.js index c1bd3dd68..236f7f36b 100644 --- a/_copyObject.js +++ b/_copyObject.js @@ -1,4 +1,4 @@ -define(['./_copyObjectWith'], function(copyObjectWith) { +define(['./_assignValue'], function(assignValue) { /** * Copies properties of `source` to `object`. @@ -7,10 +7,25 @@ define(['./_copyObjectWith'], function(copyObjectWith) { * @param {Object} source The object to copy properties from. * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. + * @param {Function} [customizer] The function to customize copied values. * @returns {Object} Returns `object`. */ - function copyObject(source, props, object) { - return copyObjectWith(source, props, object); + function copyObject(source, props, object, customizer) { + object || (object = {}); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : source[key]; + + assignValue(object, key, newValue); + } + return object; } return copyObject; diff --git a/_copyObjectWith.js b/_copyObjectWith.js deleted file mode 100644 index 4cc5123fd..000000000 --- a/_copyObjectWith.js +++ /dev/null @@ -1,33 +0,0 @@ -define(['./_assignValue'], function(assignValue) { - - /** - * This function is like `copyObject` except that it accepts a function to - * customize copied values. - * - * @private - * @param {Object} source The object to copy properties from. - * @param {Array} props The property identifiers to copy. - * @param {Object} [object={}] The object to copy properties to. - * @param {Function} [customizer] The function to customize copied values. - * @returns {Object} Returns `object`. - */ - function copyObjectWith(source, props, object, customizer) { - object || (object = {}); - - var index = -1, - length = props.length; - - while (++index < length) { - var key = props[index]; - - var newValue = customizer - ? customizer(object[key], source[key], key, object, source) - : source[key]; - - assignValue(object, key, newValue); - } - return object; - } - - return copyObjectWith; -}); diff --git a/_createCompounder.js b/_createCompounder.js index 6a136194a..ec5f7b551 100644 --- a/_createCompounder.js +++ b/_createCompounder.js @@ -1,5 +1,11 @@ define(['./_arrayReduce', './deburr', './words'], function(arrayReduce, deburr, words) { + /** Used to compose unicode capture groups. */ + var rsApos = "['\u2019]"; + + /** Used to match apostrophes. */ + var reApos = RegExp(rsApos, 'g'); + /** * Creates a function like `_.camelCase`. * @@ -9,7 +15,7 @@ define(['./_arrayReduce', './deburr', './words'], function(arrayReduce, deburr, */ function createCompounder(callback) { return function(string) { - return arrayReduce(words(deburr(string)), callback, ''); + return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); }; } diff --git a/_createOver.js b/_createOver.js index 1b817838d..25c4a1890 100644 --- a/_createOver.js +++ b/_createOver.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, isFlattenableIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseUnary', './isArray', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, baseUnary, isArray, isFlattenableIteratee, rest) { /** * Creates a function like `_.over`. @@ -9,7 +9,10 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_isFl */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseIteratee); + iteratees = (iteratees.length == 1 && isArray(iteratees[0])) + ? arrayMap(iteratees[0], baseUnary(baseIteratee)) + : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(baseIteratee)); + return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { diff --git a/_createRecurryWrapper.js b/_createRecurryWrapper.js index 1d8ab99cb..4213ef033 100644 --- a/_createRecurryWrapper.js +++ b/_createRecurryWrapper.js @@ -1,4 +1,4 @@ -define(['./_copyArray', './_isLaziable', './_setData'], function(copyArray, isLaziable, setData) { +define(['./_isLaziable', './_setData'], function(isLaziable, setData) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -31,7 +31,6 @@ define(['./_copyArray', './_isLaziable', './_setData'], function(copyArray, isLa */ function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { var isCurry = bitmask & CURRY_FLAG, - newArgPos = argPos ? copyArray(argPos) : undefined, newHolders = isCurry ? holders : undefined, newHoldersRight = isCurry ? undefined : holders, newPartials = isCurry ? partials : undefined, @@ -45,7 +44,7 @@ define(['./_copyArray', './_isLaziable', './_setData'], function(copyArray, isLa } var newData = [ func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, - newHoldersRight, newArgPos, ary, arity + newHoldersRight, argPos, ary, arity ]; var result = wrapFunc.apply(undefined, newData); diff --git a/_mergeData.js b/_mergeData.js index 68c98d9c0..fb03a3898 100644 --- a/_mergeData.js +++ b/_mergeData.js @@ -1,4 +1,4 @@ -define(['./_composeArgs', './_composeArgsRight', './_copyArray', './_replaceHolders'], function(composeArgs, composeArgsRight, copyArray, replaceHolders) { +define(['./_composeArgs', './_composeArgsRight', './_replaceHolders'], function(composeArgs, composeArgsRight, replaceHolders) { /** Used as the internal argument placeholder. */ var PLACEHOLDER = '__lodash_placeholder__'; @@ -55,20 +55,20 @@ define(['./_composeArgs', './_composeArgsRight', './_copyArray', './_replaceHold var value = source[3]; if (value) { var partials = data[3]; - data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value); - data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]); + data[3] = partials ? composeArgs(partials, value, source[4]) : value; + data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; } // Compose partial right arguments. value = source[5]; if (value) { partials = data[5]; - data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value); - data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]); + data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; + data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; } // Use source `argPos` if available. value = source[7]; if (value) { - data[7] = copyArray(value); + data[7] = value; } // Use source `ary` if it's smaller. if (srcBitmask & ARY_FLAG) { diff --git a/array.js b/array.js index bc2531857..acef09b01 100644 --- a/array.js +++ b/array.js @@ -1,4 +1,4 @@ -define(['./chunk', './compact', './concat', './difference', './differenceBy', './differenceWith', './drop', './dropRight', './dropRightWhile', './dropWhile', './fill', './findIndex', './findLastIndex', './flatten', './flattenDeep', './flattenDepth', './fromPairs', './head', './indexOf', './initial', './intersection', './intersectionBy', './intersectionWith', './join', './last', './lastIndexOf', './pull', './pullAll', './pullAllBy', './pullAllWith', './pullAt', './remove', './reverse', './slice', './sortedIndex', './sortedIndexBy', './sortedIndexOf', './sortedLastIndex', './sortedLastIndexBy', './sortedLastIndexOf', './sortedUniq', './sortedUniqBy', './tail', './take', './takeRight', './takeRightWhile', './takeWhile', './union', './unionBy', './unionWith', './uniq', './uniqBy', './uniqWith', './unzip', './unzipWith', './without', './xor', './xorBy', './xorWith', './zip', './zipObject', './zipObjectDeep', './zipWith'], function(chunk, compact, concat, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, flatten, flattenDeep, flattenDepth, fromPairs, head, indexOf, initial, intersection, intersectionBy, intersectionWith, join, last, lastIndexOf, pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reverse, slice, sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy, tail, take, takeRight, takeRightWhile, takeWhile, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, without, xor, xorBy, xorWith, zip, zipObject, zipObjectDeep, zipWith) { +define(['./chunk', './compact', './concat', './difference', './differenceBy', './differenceWith', './drop', './dropRight', './dropRightWhile', './dropWhile', './fill', './findIndex', './findLastIndex', './flatten', './flattenDeep', './flattenDepth', './fromPairs', './head', './indexOf', './initial', './intersection', './intersectionBy', './intersectionWith', './join', './last', './lastIndexOf', './nth', './pull', './pullAll', './pullAllBy', './pullAllWith', './pullAt', './remove', './reverse', './slice', './sortedIndex', './sortedIndexBy', './sortedIndexOf', './sortedLastIndex', './sortedLastIndexBy', './sortedLastIndexOf', './sortedUniq', './sortedUniqBy', './tail', './take', './takeRight', './takeRightWhile', './takeWhile', './union', './unionBy', './unionWith', './uniq', './uniqBy', './uniqWith', './unzip', './unzipWith', './without', './xor', './xorBy', './xorWith', './zip', './zipObject', './zipObjectDeep', './zipWith'], function(chunk, compact, concat, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, flatten, flattenDeep, flattenDepth, fromPairs, head, indexOf, initial, intersection, intersectionBy, intersectionWith, join, last, lastIndexOf, nth, pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reverse, slice, sortedIndex, sortedIndexBy, sortedIndexOf, sortedLastIndex, sortedLastIndexBy, sortedLastIndexOf, sortedUniq, sortedUniqBy, tail, take, takeRight, takeRightWhile, takeWhile, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, without, xor, xorBy, xorWith, zip, zipObject, zipObjectDeep, zipWith) { return { 'chunk': chunk, 'compact': compact, @@ -26,6 +26,7 @@ define(['./chunk', './compact', './concat', './difference', './differenceBy', '. 'join': join, 'last': last, 'lastIndexOf': lastIndexOf, + 'nth': nth, 'pull': pull, 'pullAll': pullAll, 'pullAllBy': pullAllBy, diff --git a/assignInWith.js b/assignInWith.js index 0ff470621..228249f6e 100644 --- a/assignInWith.js +++ b/assignInWith.js @@ -1,4 +1,4 @@ -define(['./_copyObjectWith', './_createAssigner', './keysIn'], function(copyObjectWith, createAssigner, keysIn) { +define(['./_copyObject', './_createAssigner', './keysIn'], function(copyObject, createAssigner, keysIn) { /** * This method is like `_.assignIn` except that it accepts `customizer` @@ -29,7 +29,7 @@ define(['./_copyObjectWith', './_createAssigner', './keysIn'], function(copyObje * // => { 'a': 1, 'b': 2 } */ var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObjectWith(source, keysIn(source), object, customizer); + copyObject(source, keysIn(source), object, customizer); }); return assignInWith; diff --git a/assignWith.js b/assignWith.js index 5cb9fa092..5e0fe3212 100644 --- a/assignWith.js +++ b/assignWith.js @@ -1,4 +1,4 @@ -define(['./_copyObjectWith', './_createAssigner', './keys'], function(copyObjectWith, createAssigner, keys) { +define(['./_copyObject', './_createAssigner', './keys'], function(copyObject, createAssigner, keys) { /** * This method is like `_.assign` except that it accepts `customizer` @@ -28,7 +28,7 @@ define(['./_copyObjectWith', './_createAssigner', './keys'], function(copyObject * // => { 'a': 1, 'b': 2 } */ var assignWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObjectWith(source, keys(source), object, customizer); + copyObject(source, keys(source), object, customizer); }); return assignWith; diff --git a/head.js b/head.js index 9ebdc8daf..0213aabb8 100644 --- a/head.js +++ b/head.js @@ -22,7 +22,7 @@ define([], function() { * // => undefined */ function head(array) { - return array ? array[0] : undefined; + return (array && array.length) ? array[0] : undefined; } return head; diff --git a/main.js b/main.js index 2ef4dd477..859189a26 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.10.0 (Custom Build) + * lodash 4.11.0 (Custom Build) * Build: `lodash exports="amd" -d -o ./main.js` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.10.0'; + var VERSION = '4.11.0'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -188,7 +188,8 @@ rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange; /** Used to compose unicode capture groups. */ - var rsAstral = '[' + rsAstralRange + ']', + var rsApos = "['\u2019]", + rsAstral = '[' + rsAstralRange + ']', rsBreak = '[' + rsBreakRange + ']', rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', rsDigits = '\\d+', @@ -206,6 +207,8 @@ /** Used to compose unicode regexes. */ var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')', rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', @@ -213,6 +216,9 @@ rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + /** Used to match apostrophes. */ + var reApos = RegExp(rsApos, 'g'); + /** * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). @@ -224,10 +230,10 @@ /** Used to match complex or compound words. */ var reComplexWord = RegExp([ - rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', - rsUpper + '?' + rsLowerMisc + '+', - rsUpper + '+', + rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', + rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, + rsUpper + '+' + rsOptUpperContr, rsDigits, rsEmoji ].join('|'), 'g'); @@ -1382,7 +1388,8 @@ /** Used for built-in method references. */ var arrayProto = context.Array.prototype, - objectProto = context.Object.prototype; + objectProto = context.Object.prototype, + stringProto = context.String.prototype; /** Used to resolve the decompiled source of functions. */ var funcToString = context.Function.prototype.toString; @@ -1437,7 +1444,9 @@ nativeMin = Math.min, nativeParseInt = context.parseInt, nativeRandom = Math.random, - nativeReverse = arrayProto.reverse; + nativeReplace = stringProto.replace, + nativeReverse = arrayProto.reverse, + nativeSplit = stringProto.split; /* Built-in method references that are verified to be native. */ var DataView = getNative(context, 'DataView'), @@ -1550,7 +1559,7 @@ * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`, - * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`, + * `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`, `padStart`, `parseInt`, * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, @@ -3291,6 +3300,23 @@ assignMergeValue(object, key, newValue); } + /** + * The base implementation of `_.nth` which doesn't coerce `n` to an integer. + * + * @private + * @param {Array} array The array to query. + * @param {number} n The index of the element to return. + * @returns {*} Returns the nth element of `array`. + */ + function baseNth(array, n) { + var length = array.length; + if (!length) { + return; + } + n += n < 0 ? length : 0; + return isIndex(n, length) ? array[n] : undefined; + } + /** * The base implementation of `_.orderBy` without param guards. * @@ -3302,7 +3328,7 @@ */ function baseOrderBy(collection, iteratees, orders) { var index = -1; - iteratees = arrayMap(iteratees.length ? iteratees : [identity], getIteratee()); + iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee())); var result = baseMap(collection, function(value, key, collection) { var criteria = arrayMap(iteratees, function(iteratee) { @@ -4175,24 +4201,10 @@ * @param {Object} source The object to copy properties from. * @param {Array} props The property identifiers to copy. * @param {Object} [object={}] The object to copy properties to. - * @returns {Object} Returns `object`. - */ - function copyObject(source, props, object) { - return copyObjectWith(source, props, object); - } - - /** - * This function is like `copyObject` except that it accepts a function to - * customize copied values. - * - * @private - * @param {Object} source The object to copy properties from. - * @param {Array} props The property identifiers to copy. - * @param {Object} [object={}] The object to copy properties to. * @param {Function} [customizer] The function to customize copied values. * @returns {Object} Returns `object`. */ - function copyObjectWith(source, props, object, customizer) { + function copyObject(source, props, object, customizer) { object || (object = {}); var index = -1, @@ -4383,7 +4395,7 @@ */ function createCompounder(callback) { return function(string) { - return arrayReduce(words(deburr(string)), callback, ''); + return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); }; } @@ -4619,7 +4631,10 @@ */ function createOver(arrayFunc) { return rest(function(iteratees) { - iteratees = arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), getIteratee()); + iteratees = (iteratees.length == 1 && isArray(iteratees[0])) + ? arrayMap(iteratees[0], baseUnary(getIteratee())) + : arrayMap(baseFlatten(iteratees, 1, isFlattenableIteratee), baseUnary(getIteratee())); + return rest(function(args) { var thisArg = this; return arrayFunc(iteratees, function(iteratee) { @@ -4733,7 +4748,6 @@ */ function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { var isCurry = bitmask & CURRY_FLAG, - newArgPos = argPos ? copyArray(argPos) : undefined, newHolders = isCurry ? holders : undefined, newHoldersRight = isCurry ? undefined : holders, newPartials = isCurry ? partials : undefined, @@ -4747,7 +4761,7 @@ } var newData = [ func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, - newHoldersRight, newArgPos, ary, arity + newHoldersRight, argPos, ary, arity ]; var result = wrapFunc.apply(undefined, newData); @@ -5660,20 +5674,20 @@ var value = source[3]; if (value) { var partials = data[3]; - data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray(value); - data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(source[4]); + data[3] = partials ? composeArgs(partials, value, source[4]) : value; + data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; } // Compose partial right arguments. value = source[5]; if (value) { partials = data[5]; - data[5] = partials ? composeArgsRight(partials, value, source[6]) : copyArray(value); - data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(source[6]); + data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; + data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; } // Use source `argPos` if available. value = source[7]; if (value) { - data[7] = copyArray(value); + data[7] = value; } // Use source `ary` if it's smaller. if (srcBitmask & ARY_FLAG) { @@ -6428,7 +6442,7 @@ * // => undefined */ function head(array) { - return array ? array[0] : undefined; + return (array && array.length) ? array[0] : undefined; } /** @@ -6664,6 +6678,31 @@ return -1; } + /** + * Gets the nth element of `array`. If `n` is negative, the nth element + * from the end is returned. + * + * @static + * @memberOf _ + * @since 4.11.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=0] The index of the element to return. + * @returns {*} Returns the nth element of `array`. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * + * _.nth(array, 1); + * // => 'b' + * + * _.nth(array, -2); + * // => 'c'; + */ + function nth(array, n) { + return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; + } + /** * Removes all given values from `array` using * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) @@ -8967,7 +9006,11 @@ } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees = [iteratees[0]]; } - return baseOrderBy(collection, baseFlatten(iteratees, 1), []); + iteratees = (iteratees.length == 1 && isArray(iteratees[0])) + ? iteratees[0] + : baseFlatten(iteratees, 1, isFlattenableIteratee); + + return baseOrderBy(collection, iteratees, []); }); /*------------------------------------------------------------------------*/ @@ -9665,7 +9708,10 @@ * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), getIteratee()); + transforms = (transforms.length == 1 && isArray(transforms[0])) + ? arrayMap(transforms[0], baseUnary(getIteratee())) + : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(getIteratee())); + var funcsLength = transforms.length; return rest(function(args) { var index = -1, @@ -11671,7 +11717,7 @@ * // => { 'a': 1, 'b': 2 } */ var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObjectWith(source, keysIn(source), object, customizer); + copyObject(source, keysIn(source), object, customizer); }); /** @@ -11702,7 +11748,7 @@ * // => { 'a': 1, 'b': 2 } */ var assignWith = createAssigner(function(object, source, srcIndex, customizer) { - copyObjectWith(source, keys(source), object, customizer); + copyObject(source, keys(source), object, customizer); }); /** @@ -13529,7 +13575,7 @@ var args = arguments, string = toString(args[0]); - return args.length < 3 ? string : string.replace(args[1], args[2]); + return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]); } /** @@ -13594,7 +13640,7 @@ return castSlice(stringToArray(string), 0, limit); } } - return string.split(separator, limit); + return nativeSplit.call(string, separator, limit); } /** @@ -14718,7 +14764,8 @@ } /** - * Creates a function that returns its nth argument. + * Creates a function that returns its nth argument. If `n` is negative, + * the nth argument from the end is returned. * * @static * @memberOf _ @@ -14729,15 +14776,18 @@ * @example * * var func = _.nthArg(1); - * - * func('a', 'b', 'c'); + * func('a', 'b', 'c', 'd'); * // => 'b' + * + * var func = _.nthArg(-2); + * func('a', 'b', 'c', 'd'); + * // => 'c' */ function nthArg(n) { n = toInteger(n); - return function() { - return arguments[n]; - }; + return rest(function(args) { + return baseNth(args, n); + }); } /** @@ -15645,6 +15695,7 @@ lodash.min = min; lodash.minBy = minBy; lodash.multiply = multiply; + lodash.nth = nth; lodash.noConflict = noConflict; lodash.noop = noop; lodash.now = now; diff --git a/nth.js b/nth.js new file mode 100644 index 000000000..6cdd01011 --- /dev/null +++ b/nth.js @@ -0,0 +1,32 @@ +define(['./_baseNth', './toInteger'], function(baseNth, toInteger) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * Gets the nth element of `array`. If `n` is negative, the nth element + * from the end is returned. + * + * @static + * @memberOf _ + * @since 4.11.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=0] The index of the element to return. + * @returns {*} Returns the nth element of `array`. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * + * _.nth(array, 1); + * // => 'b' + * + * _.nth(array, -2); + * // => 'c'; + */ + function nth(array, n) { + return (array && array.length) ? baseNth(array, toInteger(n)) : undefined; + } + + return nth; +}); diff --git a/nthArg.js b/nthArg.js index b6a2022e0..1163d0abe 100644 --- a/nthArg.js +++ b/nthArg.js @@ -1,7 +1,8 @@ -define(['./toInteger'], function(toInteger) { +define(['./_baseNth', './rest', './toInteger'], function(baseNth, rest, toInteger) { /** - * Creates a function that returns its nth argument. + * Creates a function that returns its nth argument. If `n` is negative, + * the nth argument from the end is returned. * * @static * @memberOf _ @@ -12,15 +13,18 @@ define(['./toInteger'], function(toInteger) { * @example * * var func = _.nthArg(1); - * - * func('a', 'b', 'c'); + * func('a', 'b', 'c', 'd'); * // => 'b' + * + * var func = _.nthArg(-2); + * func('a', 'b', 'c', 'd'); + * // => 'c' */ function nthArg(n) { n = toInteger(n); - return function() { - return arguments[n]; - }; + return rest(function(args) { + return baseNth(args, n); + }); } return nthArg; diff --git a/overArgs.js b/overArgs.js index ed51db195..e50a64141 100644 --- a/overArgs.js +++ b/overArgs.js @@ -1,4 +1,4 @@ -define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, isFlattenableIteratee, rest) { +define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_baseUnary', './isArray', './_isFlattenableIteratee', './rest'], function(apply, arrayMap, baseFlatten, baseIteratee, baseUnary, isArray, isFlattenableIteratee, rest) { /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeMin = Math.min; @@ -36,7 +36,10 @@ define(['./_apply', './_arrayMap', './_baseFlatten', './_baseIteratee', './_isFl * // => [100, 10] */ var overArgs = rest(function(func, transforms) { - transforms = arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseIteratee); + transforms = (transforms.length == 1 && isArray(transforms[0])) + ? arrayMap(transforms[0], baseUnary(baseIteratee)) + : arrayMap(baseFlatten(transforms, 1, isFlattenableIteratee), baseUnary(baseIteratee)); + var funcsLength = transforms.length; return rest(function(args) { var index = -1, diff --git a/package.json b/package.json index 5c08c381c..81520e679 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.10.0", + "version": "4.11.0", "description": "Lodash exported as AMD modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", diff --git a/replace.js b/replace.js index 0cb10da6a..27ecae38a 100644 --- a/replace.js +++ b/replace.js @@ -1,5 +1,11 @@ define(['./toString'], function(toString) { + /** Used for built-in method references. */ + var stringProto = String.prototype; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeReplace = stringProto.replace; + /** * Replaces matches for `pattern` in `string` with `replacement`. * @@ -23,7 +29,7 @@ define(['./toString'], function(toString) { var args = arguments, string = toString(args[0]); - return args.length < 3 ? string : string.replace(args[1], args[2]); + return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]); } return replace; diff --git a/sortBy.js b/sortBy.js index 35382a22e..becc5f262 100644 --- a/sortBy.js +++ b/sortBy.js @@ -1,4 +1,4 @@ -define(['./_baseFlatten', './_baseOrderBy', './_isIterateeCall', './rest'], function(baseFlatten, baseOrderBy, isIterateeCall, rest) { +define(['./_baseFlatten', './_baseOrderBy', './isArray', './_isFlattenableIteratee', './_isIterateeCall', './rest'], function(baseFlatten, baseOrderBy, isArray, isFlattenableIteratee, isIterateeCall, rest) { /** * Creates an array of elements, sorted in ascending order by the results of @@ -44,7 +44,11 @@ define(['./_baseFlatten', './_baseOrderBy', './_isIterateeCall', './rest'], func } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { iteratees = [iteratees[0]]; } - return baseOrderBy(collection, baseFlatten(iteratees, 1), []); + iteratees = (iteratees.length == 1 && isArray(iteratees[0])) + ? iteratees[0] + : baseFlatten(iteratees, 1, isFlattenableIteratee); + + return baseOrderBy(collection, iteratees, []); }); return sortBy; diff --git a/split.js b/split.js index f43e65151..6021f7ad8 100644 --- a/split.js +++ b/split.js @@ -6,6 +6,12 @@ define(['./_castSlice', './_isIterateeCall', './isRegExp', './_reHasComplexSymbo /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = 4294967295; + /** Used for built-in method references. */ + var stringProto = String.prototype; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeSplit = stringProto.split; + /** * Splits `string` by `separator`. * @@ -43,7 +49,7 @@ define(['./_castSlice', './_isIterateeCall', './isRegExp', './_reHasComplexSymbo return castSlice(stringToArray(string), 0, limit); } } - return string.split(separator, limit); + return nativeSplit.call(string, separator, limit); } return split; diff --git a/words.js b/words.js index cfb1cecac..6f46c210a 100644 --- a/words.js +++ b/words.js @@ -21,7 +21,8 @@ define(['./toString'], function(toString) { rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange; /** Used to compose unicode capture groups. */ - var rsBreak = '[' + rsBreakRange + ']', + var rsApos = "['\u2019]", + rsBreak = '[' + rsBreakRange + ']', rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', rsDigits = '\\d+', rsDingbat = '[' + rsDingbatRange + ']', @@ -38,6 +39,8 @@ define(['./toString'], function(toString) { /** Used to compose unicode regexes. */ var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')', rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', reOptMod = rsModifier + '?', rsOptVar = '[' + rsVarRange + ']?', rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', @@ -46,10 +49,10 @@ define(['./toString'], function(toString) { /** Used to match complex or compound words. */ var reComplexWord = RegExp([ - rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', - rsUpper + '?' + rsLowerMisc + '+', - rsUpper + '+', + rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', + rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, + rsUpper + '+' + rsOptUpperContr, rsDigits, rsEmoji ].join('|'), 'g'); diff --git a/wrapperLodash.js b/wrapperLodash.js index 31b3e9585..dea646d1c 100644 --- a/wrapperLodash.js +++ b/wrapperLodash.js @@ -86,7 +86,7 @@ define(['./_LazyWrapper', './_LodashWrapper', './_baseLodash', './isArray', './i * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`, * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`, * `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`, - * `noConflict`, `noop`, `now`, `pad`, `padEnd`, `padStart`, `parseInt`, + * `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`, `padStart`, `parseInt`, * `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, * `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, * `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,