wp/wp-includes/js/dist/vendor/lodash.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    10 
    10 
    11   /** Used as a safe reference for `undefined` in pre-ES5 environments. */
    11   /** Used as a safe reference for `undefined` in pre-ES5 environments. */
    12   var undefined;
    12   var undefined;
    13 
    13 
    14   /** Used as the semantic version number. */
    14   /** Used as the semantic version number. */
    15   var VERSION = '4.17.19';
    15   var VERSION = '4.17.21';
    16 
    16 
    17   /** Used as the size to enable large array optimizations. */
    17   /** Used as the size to enable large array optimizations. */
    18   var LARGE_ARRAY_SIZE = 200;
    18   var LARGE_ARRAY_SIZE = 200;
    19 
    19 
    20   /** Error message constants. */
    20   /** Error message constants. */
    21   var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
    21   var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
    22       FUNC_ERROR_TEXT = 'Expected a function';
    22       FUNC_ERROR_TEXT = 'Expected a function',
       
    23       INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
    23 
    24 
    24   /** Used to stand-in for `undefined` hash values. */
    25   /** Used to stand-in for `undefined` hash values. */
    25   var HASH_UNDEFINED = '__lodash_hash_undefined__';
    26   var HASH_UNDEFINED = '__lodash_hash_undefined__';
    26 
    27 
    27   /** Used as the maximum memoize cache size. */
    28   /** Used as the maximum memoize cache size. */
   150    * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
   151    * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
   151    */
   152    */
   152   var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
   153   var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
   153       reHasRegExpChar = RegExp(reRegExpChar.source);
   154       reHasRegExpChar = RegExp(reRegExpChar.source);
   154 
   155 
   155   /** Used to match leading and trailing whitespace. */
   156   /** Used to match leading whitespace. */
   156   var reTrim = /^\s+|\s+$/g,
   157   var reTrimStart = /^\s+/;
   157       reTrimStart = /^\s+/,
   158 
   158       reTrimEnd = /\s+$/;
   159   /** Used to match a single whitespace character. */
       
   160   var reWhitespace = /\s/;
   159 
   161 
   160   /** Used to match wrap detail comments. */
   162   /** Used to match wrap detail comments. */
   161   var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
   163   var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
   162       reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
   164       reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
   163       reSplitDetails = /,? & /;
   165       reSplitDetails = /,? & /;
   164 
   166 
   165   /** Used to match words composed of alphanumeric characters. */
   167   /** Used to match words composed of alphanumeric characters. */
   166   var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
   168   var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
       
   169 
       
   170   /**
       
   171    * Used to validate the `validate` option in `_.template` variable.
       
   172    *
       
   173    * Forbids characters which could potentially change the meaning of the function argument definition:
       
   174    * - "()," (modification of function parameters)
       
   175    * - "=" (default value)
       
   176    * - "[]{}" (destructuring of function parameters)
       
   177    * - "/" (beginning of a comment)
       
   178    * - whitespace
       
   179    */
       
   180   var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
   167 
   181 
   168   /** Used to match backslashes in property paths. */
   182   /** Used to match backslashes in property paths. */
   169   var reEscapeChar = /\\(\\)?/g;
   183   var reEscapeChar = /\\(\\)?/g;
   170 
   184 
   171   /**
   185   /**
   992       return [key, object[key]];
  1006       return [key, object[key]];
   993     });
  1007     });
   994   }
  1008   }
   995 
  1009 
   996   /**
  1010   /**
       
  1011    * The base implementation of `_.trim`.
       
  1012    *
       
  1013    * @private
       
  1014    * @param {string} string The string to trim.
       
  1015    * @returns {string} Returns the trimmed string.
       
  1016    */
       
  1017   function baseTrim(string) {
       
  1018     return string
       
  1019       ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
       
  1020       : string;
       
  1021   }
       
  1022 
       
  1023   /**
   997    * The base implementation of `_.unary` without support for storing metadata.
  1024    * The base implementation of `_.unary` without support for storing metadata.
   998    *
  1025    *
   999    * @private
  1026    * @private
  1000    * @param {Function} func The function to cap arguments for.
  1027    * @param {Function} func The function to cap arguments for.
  1001    * @returns {Function} Returns the new capped function.
  1028    * @returns {Function} Returns the new capped function.
  1322    */
  1349    */
  1323   function stringToArray(string) {
  1350   function stringToArray(string) {
  1324     return hasUnicode(string)
  1351     return hasUnicode(string)
  1325       ? unicodeToArray(string)
  1352       ? unicodeToArray(string)
  1326       : asciiToArray(string);
  1353       : asciiToArray(string);
       
  1354   }
       
  1355 
       
  1356   /**
       
  1357    * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
       
  1358    * character of `string`.
       
  1359    *
       
  1360    * @private
       
  1361    * @param {string} string The string to inspect.
       
  1362    * @returns {number} Returns the index of the last non-whitespace character.
       
  1363    */
       
  1364   function trimmedEndIndex(string) {
       
  1365     var index = string.length;
       
  1366 
       
  1367     while (index-- && reWhitespace.test(string.charAt(index))) {}
       
  1368     return index;
  1327   }
  1369   }
  1328 
  1370 
  1329   /**
  1371   /**
  1330    * Used by `_.unescape` to convert HTML entities to characters.
  1372    * Used by `_.unescape` to convert HTML entities to characters.
  1331    *
  1373    *
 12492         value = isObject(other) ? (other + '') : other;
 12534         value = isObject(other) ? (other + '') : other;
 12493       }
 12535       }
 12494       if (typeof value != 'string') {
 12536       if (typeof value != 'string') {
 12495         return value === 0 ? value : +value;
 12537         return value === 0 ? value : +value;
 12496       }
 12538       }
 12497       value = value.replace(reTrim, '');
 12539       value = baseTrim(value);
 12498       var isBinary = reIsBinary.test(value);
 12540       var isBinary = reIsBinary.test(value);
 12499       return (isBinary || reIsOctal.test(value))
 12541       return (isBinary || reIsOctal.test(value))
 12500         ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
 12542         ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
 12501         : (reIsBadHex.test(value) ? NAN : +value);
 12543         : (reIsBadHex.test(value) ? NAN : +value);
 12502     }
 12544     }
 14864       // code to add the data object to the top of the scope chain.
 14906       // code to add the data object to the top of the scope chain.
 14865       var variable = hasOwnProperty.call(options, 'variable') && options.variable;
 14907       var variable = hasOwnProperty.call(options, 'variable') && options.variable;
 14866       if (!variable) {
 14908       if (!variable) {
 14867         source = 'with (obj) {\n' + source + '\n}\n';
 14909         source = 'with (obj) {\n' + source + '\n}\n';
 14868       }
 14910       }
       
 14911       // Throw an error if a forbidden character was found in `variable`, to prevent
       
 14912       // potential command injection attacks.
       
 14913       else if (reForbiddenIdentifierChars.test(variable)) {
       
 14914         throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
       
 14915       }
       
 14916 
 14869       // Cleanup code by stripping empty strings.
 14917       // Cleanup code by stripping empty strings.
 14870       source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
 14918       source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
 14871         .replace(reEmptyStringMiddle, '$1')
 14919         .replace(reEmptyStringMiddle, '$1')
 14872         .replace(reEmptyStringTrailing, '$1;');
 14920         .replace(reEmptyStringTrailing, '$1;');
 14873 
 14921 
 14977      * // => ['foo', 'bar']
 15025      * // => ['foo', 'bar']
 14978      */
 15026      */
 14979     function trim(string, chars, guard) {
 15027     function trim(string, chars, guard) {
 14980       string = toString(string);
 15028       string = toString(string);
 14981       if (string && (guard || chars === undefined)) {
 15029       if (string && (guard || chars === undefined)) {
 14982         return string.replace(reTrim, '');
 15030         return baseTrim(string);
 14983       }
 15031       }
 14984       if (!string || !(chars = baseToString(chars))) {
 15032       if (!string || !(chars = baseToString(chars))) {
 14985         return string;
 15033         return string;
 14986       }
 15034       }
 14987       var strSymbols = stringToArray(string),
 15035       var strSymbols = stringToArray(string),
 15012      * // => '-_-abc'
 15060      * // => '-_-abc'
 15013      */
 15061      */
 15014     function trimEnd(string, chars, guard) {
 15062     function trimEnd(string, chars, guard) {
 15015       string = toString(string);
 15063       string = toString(string);
 15016       if (string && (guard || chars === undefined)) {
 15064       if (string && (guard || chars === undefined)) {
 15017         return string.replace(reTrimEnd, '');
 15065         return string.slice(0, trimmedEndIndex(string) + 1);
 15018       }
 15066       }
 15019       if (!string || !(chars = baseToString(chars))) {
 15067       if (!string || !(chars = baseToString(chars))) {
 15020         return string;
 15068         return string;
 15021       }
 15069       }
 15022       var strSymbols = stringToArray(string),
 15070       var strSymbols = stringToArray(string),
 15586      *
 15634      *
 15587      * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
 15635      * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
 15588      * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
 15636      * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
 15589      *
 15637      *
 15590      * // Checking for several possible values
 15638      * // Checking for several possible values
 15591      * _.filter(users, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
 15639      * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
 15592      * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
 15640      * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
 15593      */
 15641      */
 15594     function matches(source) {
 15642     function matches(source) {
 15595       return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
 15643       return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
 15596     }
 15644     }
 15623      *
 15671      *
 15624      * _.find(objects, _.matchesProperty('a', 4));
 15672      * _.find(objects, _.matchesProperty('a', 4));
 15625      * // => { 'a': 4, 'b': 5, 'c': 6 }
 15673      * // => { 'a': 4, 'b': 5, 'c': 6 }
 15626      *
 15674      *
 15627      * // Checking for several possible values
 15675      * // Checking for several possible values
 15628      * _.filter(users, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
 15676      * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
 15629      * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
 15677      * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
 15630      */
 15678      */
 15631     function matchesProperty(path, srcValue) {
 15679     function matchesProperty(path, srcValue) {
 15632       return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
 15680       return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
 15633     }
 15681     }