From fff78cbd5a1ed3bcb62918f16f996c40887db788 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 11 Aug 2016 23:27:31 -0700 Subject: [PATCH] Bump to v4.15.0. --- README.md | 4 +- _arrayIncludes.js | 2 +- _arrayIncludesWith.js | 2 +- _arrayLikeKeys.js | 6 +- _asciiSize.js | 13 + _asciiToArray.js | 15 ++ _asciiWords.js | 18 ++ _assocIndexOf.js | 2 +- _baseFindIndex.js | 2 +- _baseFindKey.js | 2 +- _baseIndexOf.js | 2 +- _baseIndexOfWith.js | 2 +- _baseIsNative.js | 5 +- _baseSet.js | 2 +- _baseUpdate.js | 2 +- _createCaseFirst.js | 4 +- _createPadding.js | 4 +- _deburrLetter.js | 48 +++- _getTag.js | 2 +- _hasPath.js | 4 +- _reHasComplexSymbol.js => _hasUnicode.js | 15 +- _hasUnicodeWord.js | 18 ++ _stringSize.js | 39 +-- _stringToArray.js | 32 +-- _toSource.js | 5 +- _unicodeSize.js | 45 ++++ _unicodeToArray.js | 41 +++ _unicodeWords.js | 66 +++++ deburr.js | 11 +- endsWith.js | 2 +- find.js | 2 +- findIndex.js | 2 +- findKey.js | 2 +- findLast.js | 2 +- findLastIndex.js | 2 +- findLastKey.js | 2 +- includes.js | 2 +- indexOf.js | 2 +- isArguments.js | 2 +- isEmpty.js | 23 +- isFunction.js | 3 +- isPlainObject.js | 5 +- lastIndexOf.js | 2 +- main.js | 315 ++++++++++++++++------- package.json | 2 +- replace.js | 8 +- size.js | 15 +- sortedIndexOf.js | 2 +- sortedLastIndexOf.js | 2 +- split.js | 12 +- startsWith.js | 2 +- toNumber.js | 4 +- truncate.js | 4 +- words.js | 61 +---- 54 files changed, 581 insertions(+), 312 deletions(-) create mode 100644 _asciiSize.js create mode 100644 _asciiToArray.js create mode 100644 _asciiWords.js rename _reHasComplexSymbol.js => _hasUnicode.js (53%) create mode 100644 _hasUnicodeWord.js create mode 100644 _unicodeSize.js create mode 100644 _unicodeToArray.js create mode 100644 _unicodeWords.js diff --git a/README.md b/README.md index c46df68d2..d349b8d0a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.14.2 +# lodash-amd v4.15.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.14.2-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.15.0-amd) for more details. diff --git a/_arrayIncludes.js b/_arrayIncludes.js index 5ee6baa65..be652430f 100644 --- a/_arrayIncludes.js +++ b/_arrayIncludes.js @@ -5,7 +5,7 @@ define(['./_baseIndexOf'], function(baseIndexOf) { * specifying an index to search from. * * @private - * @param {Array} [array] The array to search. + * @param {Array} [array] The array to inspect. * @param {*} target The value to search for. * @returns {boolean} Returns `true` if `target` is found, else `false`. */ diff --git a/_arrayIncludesWith.js b/_arrayIncludesWith.js index 3e1f9dc7f..13b8ea55e 100644 --- a/_arrayIncludesWith.js +++ b/_arrayIncludesWith.js @@ -4,7 +4,7 @@ define([], function() { * This function is like `arrayIncludes` except that it accepts a comparator. * * @private - * @param {Array} [array] The array to search. + * @param {Array} [array] The array to inspect. * @param {*} target The value to search for. * @param {Function} comparator The comparator invoked per element. * @returns {boolean} Returns `true` if `target` is found, else `false`. diff --git a/_arrayLikeKeys.js b/_arrayLikeKeys.js index 4f33c1cd3..27913ca2b 100644 --- a/_arrayLikeKeys.js +++ b/_arrayLikeKeys.js @@ -1,4 +1,4 @@ -define(['./_baseTimes', './isArguments', './isArray', './_isIndex', './isString'], function(baseTimes, isArguments, isArray, isIndex, isString) { +define(['./_baseTimes', './isArguments', './isArray', './_isIndex'], function(baseTimes, isArguments, isArray, isIndex) { /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -15,7 +15,9 @@ define(['./_baseTimes', './isArguments', './isArray', './_isIndex', './isString' * @returns {Array} Returns the array of property names. */ function arrayLikeKeys(value, inherited) { - var result = (isArray(value) || isString(value) || isArguments(value)) + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. + // Safari 9 makes `arguments.length` enumerable in strict mode. + var result = (isArray(value) || isArguments(value)) ? baseTimes(value.length, String) : []; diff --git a/_asciiSize.js b/_asciiSize.js new file mode 100644 index 000000000..ee7fdcd9b --- /dev/null +++ b/_asciiSize.js @@ -0,0 +1,13 @@ +define(['./_baseProperty'], function(baseProperty) { + + /** + * Gets the size of an ASCII `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + var asciiSize = baseProperty('length'); + + return asciiSize; +}); diff --git a/_asciiToArray.js b/_asciiToArray.js new file mode 100644 index 000000000..6f155edaa --- /dev/null +++ b/_asciiToArray.js @@ -0,0 +1,15 @@ +define([], function() { + + /** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function asciiToArray(string) { + return string.split(''); + } + + return asciiToArray; +}); diff --git a/_asciiWords.js b/_asciiWords.js new file mode 100644 index 000000000..20fcf2ed6 --- /dev/null +++ b/_asciiWords.js @@ -0,0 +1,18 @@ +define([], function() { + + /** Used to match words composed of alphanumeric characters. */ + var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; + + /** + * Splits an ASCII `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function asciiWords(string) { + return string.match(reAsciiWord) || []; + } + + return asciiWords; +}); diff --git a/_assocIndexOf.js b/_assocIndexOf.js index e5faa1b29..4451881fe 100644 --- a/_assocIndexOf.js +++ b/_assocIndexOf.js @@ -4,7 +4,7 @@ define(['./eq'], function(eq) { * Gets the index at which the `key` is found in `array` of key-value pairs. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} key The key to search for. * @returns {number} Returns the index of the matched value, else `-1`. */ diff --git a/_baseFindIndex.js b/_baseFindIndex.js index 4b4f0deb0..4e480bacf 100644 --- a/_baseFindIndex.js +++ b/_baseFindIndex.js @@ -5,7 +5,7 @@ define([], function() { * support for iteratee shorthands. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} predicate The function invoked per iteration. * @param {number} fromIndex The index to search from. * @param {boolean} [fromRight] Specify iterating from right to left. diff --git a/_baseFindKey.js b/_baseFindKey.js index 1d32f13c1..73e7ba3f8 100644 --- a/_baseFindKey.js +++ b/_baseFindKey.js @@ -6,7 +6,7 @@ define([], function() { * using `eachFunc`. * * @private - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} predicate The function invoked per iteration. * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the found element or its key, else `undefined`. diff --git a/_baseIndexOf.js b/_baseIndexOf.js index 3ad0c6134..05f772f5c 100644 --- a/_baseIndexOf.js +++ b/_baseIndexOf.js @@ -4,7 +4,7 @@ define(['./_baseFindIndex', './_baseIsNaN'], function(baseFindIndex, baseIsNaN) * The base implementation of `_.indexOf` without `fromIndex` bounds checks. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. diff --git a/_baseIndexOfWith.js b/_baseIndexOfWith.js index f06502fc9..6c6abda26 100644 --- a/_baseIndexOfWith.js +++ b/_baseIndexOfWith.js @@ -4,7 +4,7 @@ define([], function() { * This function is like `baseIndexOf` except that it accepts a comparator. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @param {Function} comparator The comparator invoked per element. diff --git a/_baseIsNative.js b/_baseIsNative.js index 3c1867cdd..535b9022a 100644 --- a/_baseIsNative.js +++ b/_baseIsNative.js @@ -10,10 +10,11 @@ define(['./isFunction', './_isHostObject', './_isMasked', './isObject', './_toSo var reIsHostCtor = /^\[object .+?Constructor\]$/; /** Used for built-in method references. */ - var objectProto = Object.prototype; + var funcProto = Function.prototype, + objectProto = Object.prototype; /** Used to resolve the decompiled source of functions. */ - var funcToString = Function.prototype.toString; + var funcToString = funcProto.toString; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/_baseSet.js b/_baseSet.js index b6e9554c9..8f6369326 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -7,7 +7,7 @@ define(['./_assignValue', './_castPath', './_isIndex', './_isKey', './isObject', * The base implementation of `_.set`. * * @private - * @param {Object} object The object to query. + * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. * @param {*} value The value to set. * @param {Function} [customizer] The function to customize path creation. diff --git a/_baseUpdate.js b/_baseUpdate.js index c5550d4e2..b97cbe65a 100644 --- a/_baseUpdate.js +++ b/_baseUpdate.js @@ -4,7 +4,7 @@ define(['./_baseGet', './_baseSet'], function(baseGet, baseSet) { * The base implementation of `_.update`. * * @private - * @param {Object} object The object to query. + * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to update. * @param {Function} updater The function to produce the updated value. * @param {Function} [customizer] The function to customize path creation. diff --git a/_createCaseFirst.js b/_createCaseFirst.js index 7fe0c57e2..769ee827b 100644 --- a/_createCaseFirst.js +++ b/_createCaseFirst.js @@ -1,4 +1,4 @@ -define(['./_castSlice', './_reHasComplexSymbol', './_stringToArray', './toString'], function(castSlice, reHasComplexSymbol, stringToArray, toString) { +define(['./_castSlice', './_hasUnicode', './_stringToArray', './toString'], function(castSlice, hasUnicode, stringToArray, toString) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -14,7 +14,7 @@ define(['./_castSlice', './_reHasComplexSymbol', './_stringToArray', './toString return function(string) { string = toString(string); - var strSymbols = reHasComplexSymbol.test(string) + var strSymbols = hasUnicode(string) ? stringToArray(string) : undefined; diff --git a/_createPadding.js b/_createPadding.js index 740026c84..48f751a58 100644 --- a/_createPadding.js +++ b/_createPadding.js @@ -1,4 +1,4 @@ -define(['./_baseRepeat', './_baseToString', './_castSlice', './_reHasComplexSymbol', './_stringSize', './_stringToArray'], function(baseRepeat, baseToString, castSlice, reHasComplexSymbol, stringSize, stringToArray) { +define(['./_baseRepeat', './_baseToString', './_castSlice', './_hasUnicode', './_stringSize', './_stringToArray'], function(baseRepeat, baseToString, castSlice, hasUnicode, stringSize, stringToArray) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -23,7 +23,7 @@ define(['./_baseRepeat', './_baseToString', './_castSlice', './_reHasComplexSymb return charsLength ? baseRepeat(chars, length) : chars; } var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); - return reHasComplexSymbol.test(chars) + return hasUnicode(chars) ? castSlice(stringToArray(result), 0, length).join('') : result.slice(0, length); } diff --git a/_deburrLetter.js b/_deburrLetter.js index a05732e4d..153d6736c 100644 --- a/_deburrLetter.js +++ b/_deburrLetter.js @@ -1,15 +1,16 @@ define(['./_basePropertyOf'], function(basePropertyOf) { - /** Used to map latin-1 supplementary letters to basic latin letters. */ + /** Used to map Latin Unicode letters to basic Latin letters. */ var deburredLetters = { + // Latin-1 Supplement block. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', '\xc7': 'C', '\xe7': 'c', '\xd0': 'D', '\xf0': 'd', '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', - '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', - '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', + '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', + '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', '\xd1': 'N', '\xf1': 'n', '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', @@ -18,11 +19,48 @@ define(['./_basePropertyOf'], function(basePropertyOf) { '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', '\xc6': 'Ae', '\xe6': 'ae', '\xde': 'Th', '\xfe': 'th', - '\xdf': 'ss' + '\xdf': 'ss', + // Latin Extended-A block. + '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', + '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', + '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', + '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', + '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', + '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', + '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', + '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', + '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', + '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', + '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', + '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', + '\u0134': 'J', '\u0135': 'j', + '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', + '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', + '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', + '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', + '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', + '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', + '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', + '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', + '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', + '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', + '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', + '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', + '\u0163': 't', '\u0165': 't', '\u0167': 't', + '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', + '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', + '\u0174': 'W', '\u0175': 'w', + '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', + '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', + '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', + '\u0132': 'IJ', '\u0133': 'ij', + '\u0152': 'Oe', '\u0153': 'oe', + '\u0149': "'n", '\u017f': 'ss' }; /** - * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters. + * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A + * letters to basic Latin letters. * * @private * @param {string} letter The matched letter to deburr. diff --git a/_getTag.js b/_getTag.js index 17cb0c6b4..5abc24cf7 100644 --- a/_getTag.js +++ b/_getTag.js @@ -39,7 +39,7 @@ define(['./_DataView', './_Map', './_Promise', './_Set', './_WeakMap', './_baseG var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11, - // for data views in Edge, and promises in Node.js. + // for data views in Edge < 14, and promises in Node.js. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || (Map && getTag(new Map) != mapTag) || (Promise && getTag(Promise.resolve()) != promiseTag) || diff --git a/_hasPath.js b/_hasPath.js index 6be909bfc..81556dbe1 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,4 +1,4 @@ -define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './isString', './_toKey'], function(castPath, isArguments, isArray, isIndex, isKey, isLength, isString, toKey) { +define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './_toKey'], function(castPath, isArguments, isArray, isIndex, isKey, isLength, toKey) { /** * Checks if `path` exists on `object`. @@ -28,7 +28,7 @@ define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', ' } var length = object ? object.length : 0; return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isString(object) || isArguments(object)); + (isArray(object) || isArguments(object)); } return hasPath; diff --git a/_reHasComplexSymbol.js b/_hasUnicode.js similarity index 53% rename from _reHasComplexSymbol.js rename to _hasUnicode.js index 887f25aa3..ce9d5c0e8 100644 --- a/_reHasComplexSymbol.js +++ b/_hasUnicode.js @@ -10,7 +10,18 @@ define([], function() { var rsZWJ = '\\u200d'; /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ - var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); + var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); - return reHasComplexSymbol; + /** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ + function hasUnicode(string) { + return reHasUnicode.test(string); + } + + return hasUnicode; }); diff --git a/_hasUnicodeWord.js b/_hasUnicodeWord.js new file mode 100644 index 000000000..3c1b47ec5 --- /dev/null +++ b/_hasUnicodeWord.js @@ -0,0 +1,18 @@ +define([], function() { + + /** Used to detect strings that need a more robust regexp to match words. */ + var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + + /** + * Checks if `string` contains a word composed of Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a word is found, else `false`. + */ + function hasUnicodeWord(string) { + return reHasUnicodeWord.test(string); + } + + return hasUnicodeWord; +}); diff --git a/_stringSize.js b/_stringSize.js index f080172fe..85f5af3ae 100644 --- a/_stringSize.js +++ b/_stringSize.js @@ -1,30 +1,4 @@ -define(['./_reHasComplexSymbol'], function(reHasComplexSymbol) { - - /** Used to compose unicode character classes. */ - var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - - /** Used to compose unicode capture groups. */ - var rsAstral = '[' + rsAstralRange + ']', - rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', - rsFitz = '\\ud83c[\\udffb-\\udfff]', - rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', - rsNonAstral = '[^' + rsAstralRange + ']', - rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsZWJ = '\\u200d'; - - /** Used to compose unicode regexes. */ - var reOptMod = rsModifier + '?', - rsOptVar = '[' + rsVarRange + ']?', - rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', - rsSeq = rsOptVar + reOptMod + rsOptJoin, - rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; - - /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ - var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); +define(['./_asciiSize', './_hasUnicode', './_unicodeSize'], function(asciiSize, hasUnicode, unicodeSize) { /** * Gets the number of symbols in `string`. @@ -34,14 +8,9 @@ define(['./_reHasComplexSymbol'], function(reHasComplexSymbol) { * @returns {number} Returns the string size. */ function stringSize(string) { - if (!(string && reHasComplexSymbol.test(string))) { - return string.length; - } - var result = reComplexSymbol.lastIndex = 0; - while (reComplexSymbol.test(string)) { - result++; - } - return result; + return hasUnicode(string) + ? unicodeSize(string) + : asciiSize(string); } return stringSize; diff --git a/_stringToArray.js b/_stringToArray.js index 3c26d917a..f6b7ee22a 100644 --- a/_stringToArray.js +++ b/_stringToArray.js @@ -1,30 +1,4 @@ -define([], function() { - - /** Used to compose unicode character classes. */ - var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - - /** Used to compose unicode capture groups. */ - var rsAstral = '[' + rsAstralRange + ']', - rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', - rsFitz = '\\ud83c[\\udffb-\\udfff]', - rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', - rsNonAstral = '[^' + rsAstralRange + ']', - rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsZWJ = '\\u200d'; - - /** Used to compose unicode regexes. */ - var reOptMod = rsModifier + '?', - rsOptVar = '[' + rsVarRange + ']?', - rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', - rsSeq = rsOptVar + reOptMod + rsOptJoin, - rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; - - /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ - var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); +define(['./_asciiToArray', './_hasUnicode', './_unicodeToArray'], function(asciiToArray, hasUnicode, unicodeToArray) { /** * Converts `string` to an array. @@ -34,7 +8,9 @@ define([], function() { * @returns {Array} Returns the converted array. */ function stringToArray(string) { - return string.match(reComplexSymbol); + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string); } return stringToArray; diff --git a/_toSource.js b/_toSource.js index 1560ba83d..86e1573ff 100644 --- a/_toSource.js +++ b/_toSource.js @@ -1,7 +1,10 @@ define([], function() { + /** Used for built-in method references. */ + var funcProto = Function.prototype; + /** Used to resolve the decompiled source of functions. */ - var funcToString = Function.prototype.toString; + var funcToString = funcProto.toString; /** * Converts `func` to its source code. diff --git a/_unicodeSize.js b/_unicodeSize.js new file mode 100644 index 000000000..90a590e2e --- /dev/null +++ b/_unicodeSize.js @@ -0,0 +1,45 @@ +define([], function() { + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', + rsComboSymbolsRange = '\\u20d0-\\u20f0', + rsVarRange = '\\ufe0e\\ufe0f'; + + /** Used to compose unicode capture groups. */ + var rsAstral = '[' + rsAstralRange + ']', + rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', + rsFitz = '\\ud83c[\\udffb-\\udfff]', + rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', + rsNonAstral = '[^' + rsAstralRange + ']', + rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', + rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', + rsZWJ = '\\u200d'; + + /** Used to compose unicode regexes. */ + var reOptMod = rsModifier + '?', + rsOptVar = '[' + rsVarRange + ']?', + rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsSeq = rsOptVar + reOptMod + rsOptJoin, + rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + + /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ + var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + + /** + * Gets the size of a Unicode `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + function unicodeSize(string) { + var result = reUnicode.lastIndex = 0; + while (reUnicode.test(string)) { + result++; + } + return result; + } + + return unicodeSize; +}); diff --git a/_unicodeToArray.js b/_unicodeToArray.js new file mode 100644 index 000000000..1ab668d5b --- /dev/null +++ b/_unicodeToArray.js @@ -0,0 +1,41 @@ +define([], function() { + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', + rsComboSymbolsRange = '\\u20d0-\\u20f0', + rsVarRange = '\\ufe0e\\ufe0f'; + + /** Used to compose unicode capture groups. */ + var rsAstral = '[' + rsAstralRange + ']', + rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', + rsFitz = '\\ud83c[\\udffb-\\udfff]', + rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', + rsNonAstral = '[^' + rsAstralRange + ']', + rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', + rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', + rsZWJ = '\\u200d'; + + /** Used to compose unicode regexes. */ + var reOptMod = rsModifier + '?', + rsOptVar = '[' + rsVarRange + ']?', + rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsSeq = rsOptVar + reOptMod + rsOptJoin, + rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + + /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ + var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + + /** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function unicodeToArray(string) { + return string.match(reUnicode) || []; + } + + return unicodeToArray; +}); diff --git a/_unicodeWords.js b/_unicodeWords.js new file mode 100644 index 000000000..7c0143002 --- /dev/null +++ b/_unicodeWords.js @@ -0,0 +1,66 @@ +define([], function() { + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', + rsComboSymbolsRange = '\\u20d0-\\u20f0', + rsDingbatRange = '\\u2700-\\u27bf', + rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', + rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', + rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', + rsPunctuationRange = '\\u2000-\\u206f', + rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', + rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', + rsVarRange = '\\ufe0e\\ufe0f', + rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; + + /** Used to compose unicode capture groups. */ + var rsApos = "['\u2019]", + rsBreak = '[' + rsBreakRange + ']', + rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', + rsDigits = '\\d+', + rsDingbat = '[' + rsDingbatRange + ']', + rsLower = '[' + rsLowerRange + ']', + rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', + rsFitz = '\\ud83c[\\udffb-\\udfff]', + rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', + rsNonAstral = '[^' + rsAstralRange + ']', + rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', + rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', + rsUpper = '[' + rsUpperRange + ']', + rsZWJ = '\\u200d'; + + /** 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 + ')*', + rsSeq = rsOptVar + reOptMod + rsOptJoin, + rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; + + /** Used to match complex or compound words. */ + var reUnicodeWord = RegExp([ + rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', + rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, + rsUpper + '+' + rsOptUpperContr, + rsDigits, + rsEmoji + ].join('|'), 'g'); + + /** + * Splits a Unicode `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function unicodeWords(string) { + return string.match(reUnicodeWord) || []; + } + + return unicodeWords; +}); diff --git a/deburr.js b/deburr.js index b15787667..3e23e9c0e 100644 --- a/deburr.js +++ b/deburr.js @@ -1,7 +1,7 @@ define(['./_deburrLetter', './toString'], function(deburrLetter, toString) { - /** Used to match latin-1 supplementary letters (excluding mathematical operators). */ - var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; + /** Used to match Latin Unicode letters (excluding mathematical operators). */ + var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; /** Used to compose unicode character classes. */ var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', @@ -18,8 +18,9 @@ define(['./_deburrLetter', './toString'], function(deburrLetter, toString) { /** * Deburrs `string` by converting - * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * to basic latin letters and removing + * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) + * letters to basic Latin letters and removing * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). * * @static @@ -35,7 +36,7 @@ define(['./_deburrLetter', './toString'], function(deburrLetter, toString) { */ function deburr(string) { string = toString(string); - return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, ''); + return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); } return deburr; diff --git a/endsWith.js b/endsWith.js index 306c56815..655607bac 100644 --- a/endsWith.js +++ b/endsWith.js @@ -10,7 +10,7 @@ define(['./_baseClamp', './_baseToString', './toInteger', './toString'], functio * @memberOf _ * @since 3.0.0 * @category String - * @param {string} [string=''] The string to search. + * @param {string} [string=''] The string to inspect. * @param {string} [target] The string to search for. * @param {number} [position=string.length] The position to search up to. * @returns {boolean} Returns `true` if `string` ends with `target`, diff --git a/find.js b/find.js index dcd76261b..b3cd025e2 100644 --- a/find.js +++ b/find.js @@ -9,7 +9,7 @@ define(['./_createFind', './findIndex'], function(createFind, findIndex) { * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. diff --git a/findIndex.js b/findIndex.js index 24f58958e..ab971e385 100644 --- a/findIndex.js +++ b/findIndex.js @@ -11,7 +11,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @memberOf _ * @since 1.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. diff --git a/findKey.js b/findKey.js index 711449940..f772bbb30 100644 --- a/findKey.js +++ b/findKey.js @@ -8,7 +8,7 @@ define(['./_baseFindKey', './_baseForOwn', './_baseIteratee'], function(baseFind * @memberOf _ * @since 1.1.0 * @category Object - * @param {Object} object The object to search. + * @param {Object} object The object to inspect. * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. diff --git a/findLast.js b/findLast.js index 6d8f94e9d..c9970d7a0 100644 --- a/findLast.js +++ b/findLast.js @@ -8,7 +8,7 @@ define(['./_createFind', './findLastIndex'], function(createFind, findLastIndex) * @memberOf _ * @since 2.0.0 * @category Collection - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. diff --git a/findLastIndex.js b/findLastIndex.js index d9724a37f..3cdd64573 100644 --- a/findLastIndex.js +++ b/findLastIndex.js @@ -15,7 +15,7 @@ define(['./_baseFindIndex', './_baseIteratee', './toInteger'], function(baseFind * @memberOf _ * @since 2.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. diff --git a/findLastKey.js b/findLastKey.js index 19cc53fa5..4102d8de9 100644 --- a/findLastKey.js +++ b/findLastKey.js @@ -8,7 +8,7 @@ define(['./_baseFindKey', './_baseForOwnRight', './_baseIteratee'], function(bas * @memberOf _ * @since 2.0.0 * @category Object - * @param {Object} object The object to search. + * @param {Object} object The object to inspect. * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. diff --git a/includes.js b/includes.js index 19fbc218b..9e74ab74d 100644 --- a/includes.js +++ b/includes.js @@ -14,7 +14,7 @@ define(['./_baseIndexOf', './isArrayLike', './isString', './toInteger', './value * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object|string} collection The collection to search. + * @param {Array|Object|string} collection The collection to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. diff --git a/indexOf.js b/indexOf.js index 2ec35078f..25d69cc3a 100644 --- a/indexOf.js +++ b/indexOf.js @@ -13,7 +13,7 @@ define(['./_baseIndexOf', './toInteger'], function(baseIndexOf, toInteger) { * @memberOf _ * @since 0.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. diff --git a/isArguments.js b/isArguments.js index dc2671cfd..be51856c2 100644 --- a/isArguments.js +++ b/isArguments.js @@ -38,7 +38,7 @@ define(['./isArrayLikeObject'], function(isArrayLikeObject) { * // => false */ function isArguments(value) { - // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); } diff --git a/isEmpty.js b/isEmpty.js index c83b7ee79..d534d0b94 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -1,4 +1,4 @@ -define(['./_getTag', './isArguments', './isArray', './isArrayLike', './isBuffer', './isFunction', './isObjectLike', './_isPrototype', './isString', './_nativeKeys'], function(getTag, isArguments, isArray, isArrayLike, isBuffer, isFunction, isObjectLike, isPrototype, isString, nativeKeys) { +define(['./_getTag', './isArguments', './isArray', './isArrayLike', './isBuffer', './_isPrototype', './_nativeKeys'], function(getTag, isArguments, isArray, isArrayLike, isBuffer, isPrototype, nativeKeys) { /** `Object#toString` result references. */ var mapTag = '[object Map]', @@ -51,24 +51,23 @@ define(['./_getTag', './isArguments', './isArray', './isArrayLike', './isBuffer' */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || isFunction(value.splice) || - isArguments(value) || isBuffer(value))) { + (isArray(value) || typeof value == 'string' || + typeof value.splice == 'function' || isBuffer(value) || isArguments(value))) { return !value.length; } - if (isObjectLike(value)) { - var tag = getTag(value); - if (tag == mapTag || tag == setTag) { - return !value.size; - } + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + if (nonEnumShadows || isPrototype(value)) { + return !nativeKeys(value).length; } - var isProto = isPrototype(value); for (var key in value) { - if (hasOwnProperty.call(value, key) && - !(isProto && key == 'constructor')) { + if (hasOwnProperty.call(value, key)) { return false; } } - return !(nonEnumShadows && nativeKeys(value).length); + return true; } return isEmpty; diff --git a/isFunction.js b/isFunction.js index e8044df2b..e88da4b8f 100644 --- a/isFunction.js +++ b/isFunction.js @@ -33,8 +33,7 @@ define(['./isObject'], function(isObject) { */ function isFunction(value) { // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8 which returns 'object' for typed array and weak map constructors, - // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + // in Safari 8-9 which returns 'object' for typed array and other constructors. var tag = isObject(value) ? objectToString.call(value) : ''; return tag == funcTag || tag == genTag; } diff --git a/isPlainObject.js b/isPlainObject.js index a13e826a9..24d53787a 100644 --- a/isPlainObject.js +++ b/isPlainObject.js @@ -4,10 +4,11 @@ define(['./_getPrototype', './_isHostObject', './isObjectLike'], function(getPro var objectTag = '[object Object]'; /** Used for built-in method references. */ - var objectProto = Object.prototype; + var funcProto = Function.prototype, + objectProto = Object.prototype; /** Used to resolve the decompiled source of functions. */ - var funcToString = Function.prototype.toString; + var funcToString = funcProto.toString; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; diff --git a/lastIndexOf.js b/lastIndexOf.js index 5a51faa03..7cf8f226c 100644 --- a/lastIndexOf.js +++ b/lastIndexOf.js @@ -15,7 +15,7 @@ define(['./_baseFindIndex', './_baseIsNaN', './toInteger'], function(baseFindInd * @memberOf _ * @since 0.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. diff --git a/main.js b/main.js index 021fdd391..a793fc27c 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.14.2'; + var VERSION = '4.15.0'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -150,8 +150,8 @@ reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, reSplitDetails = /,? & /; - /** Used to match non-compound words composed of alphanumeric characters. */ - var reBasicWord = /[a-zA-Z0-9]+/g; + /** Used to match words composed of alphanumeric characters. */ + var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; /** Used to match backslashes in property paths. */ var reEscapeChar = /\\(\\)?/g; @@ -183,8 +183,8 @@ /** Used to detect unsigned integer values. */ var reIsUint = /^(?:0|[1-9]\d*)$/; - /** Used to match latin-1 supplementary letters (excluding mathematical operators). */ - var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; + /** Used to match Latin Unicode letters (excluding mathematical operators). */ + var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; /** Used to ensure capturing order of template delimiters. */ var reNoMatch = /($^)/; @@ -245,10 +245,10 @@ var reComboMark = RegExp(rsCombo, 'g'); /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ - var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); /** Used to match complex or compound words. */ - var reComplexWord = RegExp([ + var reUnicodeWord = RegExp([ rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, @@ -258,18 +258,18 @@ ].join('|'), 'g'); /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ - var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); + var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); /** Used to detect strings that need a more robust regexp to match words. */ - var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** Used to assign default `context` object properties. */ var contextProps = [ 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', - 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_', 'clearTimeout', - 'isFinite', 'parseInt', 'setTimeout' + 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', + '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' ]; /** Used to make template sourceURLs easier to identify. */ @@ -307,16 +307,17 @@ cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[weakMapTag] = false; - /** Used to map latin-1 supplementary letters to basic latin letters. */ + /** Used to map Latin Unicode letters to basic Latin letters. */ var deburredLetters = { + // Latin-1 Supplement block. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', '\xc7': 'C', '\xe7': 'c', '\xd0': 'D', '\xf0': 'd', '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', - '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', - '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', + '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', + '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', '\xd1': 'N', '\xf1': 'n', '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', @@ -325,7 +326,43 @@ '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', '\xc6': 'Ae', '\xe6': 'ae', '\xde': 'Th', '\xfe': 'th', - '\xdf': 'ss' + '\xdf': 'ss', + // Latin Extended-A block. + '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', + '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', + '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', + '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', + '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', + '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', + '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', + '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', + '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', + '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', + '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', + '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', + '\u0134': 'J', '\u0135': 'j', + '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', + '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', + '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', + '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', + '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', + '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', + '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', + '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', + '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', + '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', + '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', + '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', + '\u0163': 't', '\u0165': 't', '\u0167': 't', + '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', + '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', + '\u0174': 'W', '\u0175': 'w', + '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', + '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', + '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', + '\u0132': 'IJ', '\u0133': 'ij', + '\u0152': 'Oe', '\u0153': 'oe', + '\u0149': "'n", '\u017f': 'ss' }; /** Used to map characters to HTML entities. */ @@ -561,7 +598,7 @@ * specifying an index to search from. * * @private - * @param {Array} [array] The array to search. + * @param {Array} [array] The array to inspect. * @param {*} target The value to search for. * @returns {boolean} Returns `true` if `target` is found, else `false`. */ @@ -574,7 +611,7 @@ * This function is like `arrayIncludes` except that it accepts a comparator. * * @private - * @param {Array} [array] The array to search. + * @param {Array} [array] The array to inspect. * @param {*} target The value to search for. * @param {Function} comparator The comparator invoked per element. * @returns {boolean} Returns `true` if `target` is found, else `false`. @@ -700,13 +737,44 @@ return false; } + /** + * Gets the size of an ASCII `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + var asciiSize = baseProperty('length'); + + /** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function asciiToArray(string) { + return string.split(''); + } + + /** + * Splits an ASCII `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function asciiWords(string) { + return string.match(reAsciiWord) || []; + } + /** * The base implementation of methods like `_.findKey` and `_.findLastKey`, * without support for iteratee shorthands, which iterates over `collection` * using `eachFunc`. * * @private - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} predicate The function invoked per iteration. * @param {Function} eachFunc The function to iterate over `collection`. * @returns {*} Returns the found element or its key, else `undefined`. @@ -727,7 +795,7 @@ * support for iteratee shorthands. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} predicate The function invoked per iteration. * @param {number} fromIndex The index to search from. * @param {boolean} [fromRight] Specify iterating from right to left. @@ -749,7 +817,7 @@ * The base implementation of `_.indexOf` without `fromIndex` bounds checks. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. @@ -773,7 +841,7 @@ * This function is like `baseIndexOf` except that it accepts a comparator. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @param {Function} comparator The comparator invoked per element. @@ -1036,7 +1104,8 @@ } /** - * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters. + * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A + * letters to basic Latin letters. * * @private * @param {string} letter The matched letter to deburr. @@ -1076,6 +1145,28 @@ return object == null ? undefined : object[key]; } + /** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ + function hasUnicode(string) { + return reHasUnicode.test(string); + } + + /** + * Checks if `string` contains a word composed of Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a word is found, else `false`. + */ + function hasUnicodeWord(string) { + return reHasUnicodeWord.test(string); + } + /** * Checks if `value` is a host object in IE < 9. * @@ -1210,14 +1301,9 @@ * @returns {number} Returns the string size. */ function stringSize(string) { - if (!(string && reHasComplexSymbol.test(string))) { - return string.length; - } - var result = reComplexSymbol.lastIndex = 0; - while (reComplexSymbol.test(string)) { - result++; - } - return result; + return hasUnicode(string) + ? unicodeSize(string) + : asciiSize(string); } /** @@ -1228,7 +1314,9 @@ * @returns {Array} Returns the converted array. */ function stringToArray(string) { - return string.match(reComplexSymbol); + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string); } /** @@ -1240,6 +1328,43 @@ */ var unescapeHtmlChar = basePropertyOf(htmlUnescapes); + /** + * Gets the size of a Unicode `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + function unicodeSize(string) { + var result = reUnicode.lastIndex = 0; + while (reUnicode.test(string)) { + result++; + } + return result; + } + + /** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function unicodeToArray(string) { + return string.match(reUnicode) || []; + } + + /** + * Splits a Unicode `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function unicodeWords(string) { + return string.match(reUnicodeWord) || []; + } + /*--------------------------------------------------------------------------*/ /** @@ -1279,19 +1404,23 @@ * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; */ function runInContext(context) { - context = context ? _.defaults({}, context, _.pick(root, contextProps)) : root; + context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root; /** Built-in constructor references. */ var Array = context.Array, + Date = context.Date, Error = context.Error, + Function = context.Function, Math = context.Math, + Object = context.Object, RegExp = context.RegExp, + String = context.String, TypeError = context.TypeError; /** Used for built-in method references. */ - var arrayProto = context.Array.prototype, - objectProto = context.Object.prototype, - stringProto = context.String.prototype; + var arrayProto = Array.prototype, + funcProto = Function.prototype, + objectProto = Object.prototype; /** Used to detect overreaching core-js shims. */ var coreJsData = context['__core-js_shared__']; @@ -1303,7 +1432,7 @@ }()); /** Used to resolve the decompiled source of functions. */ - var funcToString = context.Function.prototype.toString; + var funcToString = funcProto.toString; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; @@ -1336,14 +1465,14 @@ Uint8Array = context.Uint8Array, getPrototype = overArg(Object.getPrototypeOf, Object), iteratorSymbol = Symbol ? Symbol.iterator : undefined, - objectCreate = context.Object.create, + objectCreate = Object.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; /** Mocked built-ins. */ var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, - ctxNow = context.Date && context.Date.now !== root.Date.now && context.Date.now, + ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -1358,9 +1487,7 @@ nativeMin = Math.min, nativeParseInt = context.parseInt, nativeRandom = Math.random, - nativeReplace = stringProto.replace, - nativeReverse = arrayProto.reverse, - nativeSplit = stringProto.split; + nativeReverse = arrayProto.reverse; /* Built-in method references that are verified to be native. */ var DataView = getNative(context, 'DataView'), @@ -1368,11 +1495,11 @@ Promise = getNative(context, 'Promise'), Set = getNative(context, 'Set'), WeakMap = getNative(context, 'WeakMap'), - nativeCreate = getNative(context.Object, 'create'); + nativeCreate = getNative(Object, 'create'); /* Used to set `toString` methods. */ var defineProperty = (function() { - var func = getNative(context.Object, 'defineProperty'), + var func = getNative(Object, 'defineProperty'), name = getNative.name; return (name && name.length > 2) ? func : undefined; @@ -2209,7 +2336,9 @@ * @returns {Array} Returns the array of property names. */ function arrayLikeKeys(value, inherited) { - var result = (isArray(value) || isString(value) || isArguments(value)) + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. + // Safari 9 makes `arguments.length` enumerable in strict mode. + var result = (isArray(value) || isArguments(value)) ? baseTimes(value.length, String) : []; @@ -2281,7 +2410,7 @@ * Gets the index at which the `key` is found in `array` of key-value pairs. * * @private - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} key The key to search for. * @returns {number} Returns the index of the matched value, else `-1`. */ @@ -3706,7 +3835,7 @@ * The base implementation of `_.set`. * * @private - * @param {Object} object The object to query. + * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. * @param {*} value The value to set. * @param {Function} [customizer] The function to customize path creation. @@ -4036,7 +4165,7 @@ * The base implementation of `_.update`. * * @private - * @param {Object} object The object to query. + * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to update. * @param {Function} updater The function to produce the updated value. * @param {Function} [customizer] The function to customize path creation. @@ -4647,7 +4776,7 @@ return function(string) { string = toString(string); - var strSymbols = reHasComplexSymbol.test(string) + var strSymbols = hasUnicode(string) ? stringToArray(string) : undefined; @@ -4990,7 +5119,7 @@ return charsLength ? baseRepeat(chars, length) : chars; } var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); - return reHasComplexSymbol.test(chars) + return hasUnicode(chars) ? castSlice(stringToArray(result), 0, length).join('') : result.slice(0, length); } @@ -5657,7 +5786,7 @@ var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11, - // for data views in Edge, and promises in Node.js. + // for data views in Edge < 14, and promises in Node.js. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || (Map && getTag(new Map) != mapTag) || (Promise && getTag(Promise.resolve()) != promiseTag) || @@ -5749,7 +5878,7 @@ } var length = object ? object.length : 0; return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isString(object) || isArguments(object)); + (isArray(object) || isArguments(object)); } /** @@ -6730,7 +6859,7 @@ * @memberOf _ * @since 1.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. @@ -6778,7 +6907,7 @@ * @memberOf _ * @since 2.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=array.length-1] The index to search from. @@ -6947,7 +7076,7 @@ * @memberOf _ * @since 0.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. @@ -7132,7 +7261,7 @@ * @memberOf _ * @since 0.1.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=array.length-1] The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. @@ -7510,7 +7639,7 @@ * @memberOf _ * @since 4.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @returns {number} Returns the index of the matched value, else `-1`. * @example @@ -7589,7 +7718,7 @@ * @memberOf _ * @since 4.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @returns {number} Returns the index of the matched value, else `-1`. * @example @@ -8718,7 +8847,7 @@ * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=0] The index to search from. @@ -8756,7 +8885,7 @@ * @memberOf _ * @since 2.0.0 * @category Collection - * @param {Array|Object} collection The collection to search. + * @param {Array|Object} collection The collection to inspect. * @param {Function} [predicate=_.identity] * The function invoked per iteration. * @param {number} [fromIndex=collection.length-1] The index to search from. @@ -8951,7 +9080,7 @@ * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object|string} collection The collection to search. + * @param {Array|Object|string} collection The collection to inspect. * @param {*} value The value to search for. * @param {number} [fromIndex=0] The index to search from. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. @@ -9384,7 +9513,7 @@ * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object} collection The collection to inspect. + * @param {Array|Object|string} collection The collection to inspect. * @returns {number} Returns the collection size. * @example * @@ -9402,14 +9531,11 @@ return 0; } if (isArrayLike(collection)) { - var result = collection.length; - return (result && isString(collection)) ? stringSize(collection) : result; + return isString(collection) ? stringSize(collection) : collection.length; } - if (isObjectLike(collection)) { - var tag = getTag(collection); - if (tag == mapTag || tag == setTag) { - return collection.size; - } + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; } return baseKeys(collection).length; } @@ -10818,7 +10944,7 @@ * // => false */ function isArguments(value) { - // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); } @@ -11041,24 +11167,23 @@ */ function isEmpty(value) { if (isArrayLike(value) && - (isArray(value) || isString(value) || isFunction(value.splice) || - isArguments(value) || isBuffer(value))) { + (isArray(value) || typeof value == 'string' || + typeof value.splice == 'function' || isBuffer(value) || isArguments(value))) { return !value.length; } - if (isObjectLike(value)) { - var tag = getTag(value); - if (tag == mapTag || tag == setTag) { - return !value.size; - } + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + if (nonEnumShadows || isPrototype(value)) { + return !nativeKeys(value).length; } - var isProto = isPrototype(value); for (var key in value) { - if (hasOwnProperty.call(value, key) && - !(isProto && key == 'constructor')) { + if (hasOwnProperty.call(value, key)) { return false; } } - return !(nonEnumShadows && nativeKeys(value).length); + return true; } /** @@ -11206,8 +11331,7 @@ */ function isFunction(value) { // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8 which returns 'object' for typed array and weak map constructors, - // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + // in Safari 8-9 which returns 'object' for typed array and other constructors. var tag = isObject(value) ? objectToString.call(value) : ''; return tag == funcTag || tag == genTag; } @@ -12021,7 +12145,7 @@ return NAN; } if (isObject(value)) { - var other = isFunction(value.valueOf) ? value.valueOf() : value; + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { @@ -12379,7 +12503,7 @@ * @memberOf _ * @since 1.1.0 * @category Object - * @param {Object} object The object to search. + * @param {Object} object The object to inspect. * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. @@ -12418,7 +12542,7 @@ * @memberOf _ * @since 2.0.0 * @category Object - * @param {Object} object The object to search. + * @param {Object} object The object to inspect. * @param {Function} [predicate=_.identity] The function invoked per iteration. * @returns {string|undefined} Returns the key of the matched element, * else `undefined`. @@ -13660,8 +13784,9 @@ /** * Deburrs `string` by converting - * [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) - * to basic latin letters and removing + * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) + * letters to basic Latin letters and removing * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). * * @static @@ -13677,7 +13802,7 @@ */ function deburr(string) { string = toString(string); - return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, ''); + return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); } /** @@ -13687,7 +13812,7 @@ * @memberOf _ * @since 3.0.0 * @category String - * @param {string} [string=''] The string to search. + * @param {string} [string=''] The string to inspect. * @param {string} [target] The string to search for. * @param {number} [position=string.length] The position to search up to. * @returns {boolean} Returns `true` if `string` ends with `target`, @@ -14043,7 +14168,7 @@ var args = arguments, string = toString(args[0]); - return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]); + return args.length < 3 ? string : string.replace(args[1], args[2]); } /** @@ -14104,11 +14229,11 @@ (separator != null && !isRegExp(separator)) )) { separator = baseToString(separator); - if (separator == '' && reHasComplexSymbol.test(string)) { + if (!separator && hasUnicode(string)) { return castSlice(stringToArray(string), 0, limit); } } - return nativeSplit.call(string, separator, limit); + return string.split(separator, limit); } /** @@ -14143,7 +14268,7 @@ * @memberOf _ * @since 3.0.0 * @category String - * @param {string} [string=''] The string to search. + * @param {string} [string=''] The string to inspect. * @param {string} [target] The string to search for. * @param {number} [position=0] The position to search from. * @returns {boolean} Returns `true` if `string` starts with `target`, @@ -14580,7 +14705,7 @@ string = toString(string); var strLength = string.length; - if (reHasComplexSymbol.test(string)) { + if (hasUnicode(string)) { var strSymbols = stringToArray(string); strLength = strSymbols.length; } @@ -14717,7 +14842,7 @@ pattern = guard ? undefined : pattern; if (pattern === undefined) { - pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord; + return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string); } return string.match(pattern) || []; } diff --git a/package.json b/package.json index 34f2ef2ea..357b9a8e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.14.2", + "version": "4.15.0", "description": "Lodash exported as AMD modules.", "keywords": "amd, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/replace.js b/replace.js index 27ecae38a..0cb10da6a 100644 --- a/replace.js +++ b/replace.js @@ -1,11 +1,5 @@ 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`. * @@ -29,7 +23,7 @@ define(['./toString'], function(toString) { var args = arguments, string = toString(args[0]); - return args.length < 3 ? string : nativeReplace.call(string, args[1], args[2]); + return args.length < 3 ? string : string.replace(args[1], args[2]); } return replace; diff --git a/size.js b/size.js index 5f6b36d9d..a17378f8d 100644 --- a/size.js +++ b/size.js @@ -1,4 +1,4 @@ -define(['./_baseKeys', './_getTag', './isArrayLike', './isObjectLike', './isString', './_stringSize'], function(baseKeys, getTag, isArrayLike, isObjectLike, isString, stringSize) { +define(['./_baseKeys', './_getTag', './isArrayLike', './isString', './_stringSize'], function(baseKeys, getTag, isArrayLike, isString, stringSize) { /** `Object#toString` result references. */ var mapTag = '[object Map]', @@ -12,7 +12,7 @@ define(['./_baseKeys', './_getTag', './isArrayLike', './isObjectLike', './isStri * @memberOf _ * @since 0.1.0 * @category Collection - * @param {Array|Object} collection The collection to inspect. + * @param {Array|Object|string} collection The collection to inspect. * @returns {number} Returns the collection size. * @example * @@ -30,14 +30,11 @@ define(['./_baseKeys', './_getTag', './isArrayLike', './isObjectLike', './isStri return 0; } if (isArrayLike(collection)) { - var result = collection.length; - return (result && isString(collection)) ? stringSize(collection) : result; + return isString(collection) ? stringSize(collection) : collection.length; } - if (isObjectLike(collection)) { - var tag = getTag(collection); - if (tag == mapTag || tag == setTag) { - return collection.size; - } + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; } return baseKeys(collection).length; } diff --git a/sortedIndexOf.js b/sortedIndexOf.js index ebcb905cc..9f70eaa09 100644 --- a/sortedIndexOf.js +++ b/sortedIndexOf.js @@ -8,7 +8,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * @memberOf _ * @since 4.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @returns {number} Returns the index of the matched value, else `-1`. * @example diff --git a/sortedLastIndexOf.js b/sortedLastIndexOf.js index 512e881a2..d1b3341f8 100644 --- a/sortedLastIndexOf.js +++ b/sortedLastIndexOf.js @@ -8,7 +8,7 @@ define(['./_baseSortedIndex', './eq'], function(baseSortedIndex, eq) { * @memberOf _ * @since 4.0.0 * @category Array - * @param {Array} array The array to search. + * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @returns {number} Returns the index of the matched value, else `-1`. * @example diff --git a/split.js b/split.js index 7f0dafe7b..1556a1928 100644 --- a/split.js +++ b/split.js @@ -1,4 +1,4 @@ -define(['./_baseToString', './_castSlice', './_isIterateeCall', './isRegExp', './_reHasComplexSymbol', './_stringToArray', './toString'], function(baseToString, castSlice, isIterateeCall, isRegExp, reHasComplexSymbol, stringToArray, toString) { +define(['./_baseToString', './_castSlice', './_hasUnicode', './_isIterateeCall', './isRegExp', './_stringToArray', './toString'], function(baseToString, castSlice, hasUnicode, isIterateeCall, isRegExp, stringToArray, toString) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -6,12 +6,6 @@ define(['./_baseToString', './_castSlice', './_isIterateeCall', './isRegExp', '. /** 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`. * @@ -45,11 +39,11 @@ define(['./_baseToString', './_castSlice', './_isIterateeCall', './isRegExp', '. (separator != null && !isRegExp(separator)) )) { separator = baseToString(separator); - if (separator == '' && reHasComplexSymbol.test(string)) { + if (!separator && hasUnicode(string)) { return castSlice(stringToArray(string), 0, limit); } } - return nativeSplit.call(string, separator, limit); + return string.split(separator, limit); } return split; diff --git a/startsWith.js b/startsWith.js index 537796aaf..8bcefd6f6 100644 --- a/startsWith.js +++ b/startsWith.js @@ -7,7 +7,7 @@ define(['./_baseClamp', './_baseToString', './toInteger', './toString'], functio * @memberOf _ * @since 3.0.0 * @category String - * @param {string} [string=''] The string to search. + * @param {string} [string=''] The string to inspect. * @param {string} [target] The string to search for. * @param {number} [position=0] The position to search from. * @returns {boolean} Returns `true` if `string` starts with `target`, diff --git a/toNumber.js b/toNumber.js index f0a1f3432..e4dcad758 100644 --- a/toNumber.js +++ b/toNumber.js @@ -1,4 +1,4 @@ -define(['./isFunction', './isObject', './isSymbol'], function(isFunction, isObject, isSymbol) { +define(['./isObject', './isSymbol'], function(isObject, isSymbol) { /** Used as references for various `Number` constants. */ var NAN = 0 / 0; @@ -49,7 +49,7 @@ define(['./isFunction', './isObject', './isSymbol'], function(isFunction, isObje return NAN; } if (isObject(value)) { - var other = isFunction(value.valueOf) ? value.valueOf() : value; + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject(other) ? (other + '') : other; } if (typeof value != 'string') { diff --git a/truncate.js b/truncate.js index 01a1d82b8..d6d42c4c5 100644 --- a/truncate.js +++ b/truncate.js @@ -1,4 +1,4 @@ -define(['./_baseToString', './_castSlice', './isObject', './isRegExp', './_reHasComplexSymbol', './_stringSize', './_stringToArray', './toInteger', './toString'], function(baseToString, castSlice, isObject, isRegExp, reHasComplexSymbol, stringSize, stringToArray, toInteger, toString) { +define(['./_baseToString', './_castSlice', './_hasUnicode', './isObject', './isRegExp', './_stringSize', './_stringToArray', './toInteger', './toString'], function(baseToString, castSlice, hasUnicode, isObject, isRegExp, stringSize, stringToArray, toInteger, toString) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -59,7 +59,7 @@ define(['./_baseToString', './_castSlice', './isObject', './isRegExp', './_reHas string = toString(string); var strLength = string.length; - if (reHasComplexSymbol.test(string)) { + if (hasUnicode(string)) { var strSymbols = stringToArray(string); strLength = strSymbols.length; } diff --git a/words.js b/words.js index f3bb48aff..ddf9e92f7 100644 --- a/words.js +++ b/words.js @@ -1,65 +1,8 @@ -define(['./toString'], function(toString) { +define(['./_asciiWords', './_hasUnicodeWord', './toString', './_unicodeWords'], function(asciiWords, hasUnicodeWord, toString, unicodeWords) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; - /** Used to match non-compound words composed of alphanumeric characters. */ - var reBasicWord = /[a-zA-Z0-9]+/g; - - /** Used to compose unicode character classes. */ - var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsDingbatRange = '\\u2700-\\u27bf', - rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', - rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', - rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', - rsPunctuationRange = '\\u2000-\\u206f', - rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', - rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', - rsVarRange = '\\ufe0e\\ufe0f', - rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; - - /** Used to compose unicode capture groups. */ - var rsApos = "['\u2019]", - rsBreak = '[' + rsBreakRange + ']', - rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']', - rsDigits = '\\d+', - rsDingbat = '[' + rsDingbatRange + ']', - rsLower = '[' + rsLowerRange + ']', - rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', - rsFitz = '\\ud83c[\\udffb-\\udfff]', - rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', - rsNonAstral = '[^' + rsAstralRange + ']', - rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', - rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', - rsUpper = '[' + rsUpperRange + ']', - rsZWJ = '\\u200d'; - - /** 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 + ')*', - rsSeq = rsOptVar + reOptMod + rsOptJoin, - rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; - - /** Used to match complex or compound words. */ - var reComplexWord = RegExp([ - rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', - rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')', - rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr, - rsUpper + '+' + rsOptUpperContr, - rsDigits, - rsEmoji - ].join('|'), 'g'); - - /** Used to detect strings that need a more robust regexp to match words. */ - var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; - /** * Splits `string` into an array of its words. * @@ -84,7 +27,7 @@ define(['./toString'], function(toString) { pattern = guard ? undefined : pattern; if (pattern === undefined) { - pattern = reHasComplexWord.test(string) ? reComplexWord : reBasicWord; + return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string); } return string.match(pattern) || []; }