wp/wp-includes/js/underscore.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     5     var current = global._;
     5     var current = global._;
     6     var exports = global._ = factory();
     6     var exports = global._ = factory();
     7     exports.noConflict = function () { global._ = current; return exports; };
     7     exports.noConflict = function () { global._ = current; return exports; };
     8   }()));
     8   }()));
     9 }(this, (function () {
     9 }(this, (function () {
    10   //     Underscore.js 1.13.1
    10   //     Underscore.js 1.13.3
    11   //     https://underscorejs.org
    11   //     https://underscorejs.org
    12   //     (c) 2009-2021 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors
    12   //     (c) 2009-2022 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors
    13   //     Underscore may be freely distributed under the MIT license.
    13   //     Underscore may be freely distributed under the MIT license.
    14 
    14 
    15   // Current version.
    15   // Current version.
    16   var VERSION = '1.13.1';
    16   var VERSION = '1.13.3';
    17 
    17 
    18   // Establish the root object, `window` (`self`) in the browser, `global`
    18   // Establish the root object, `window` (`self`) in the browser, `global`
    19   // on the server, or `this` in some virtual machines. We use `self`
    19   // on the server, or `this` in some virtual machines. We use `self`
    20   // instead of `window` for `WebWorker` support.
    20   // instead of `window` for `WebWorker` support.
    21   var root = typeof self == 'object' && self.self === self && self ||
    21   var root = (typeof self == 'object' && self.self === self && self) ||
    22             typeof global == 'object' && global.global === global && global ||
    22             (typeof global == 'object' && global.global === global && global) ||
    23             Function('return this')() ||
    23             Function('return this')() ||
    24             {};
    24             {};
    25 
    25 
    26   // Save bytes in the minified (but not gzipped) version:
    26   // Save bytes in the minified (but not gzipped) version:
    27   var ArrayProto = Array.prototype, ObjProto = Object.prototype;
    27   var ArrayProto = Array.prototype, ObjProto = Object.prototype;
    85   }
    85   }
    86 
    86 
    87   // Is a given variable an object?
    87   // Is a given variable an object?
    88   function isObject(obj) {
    88   function isObject(obj) {
    89     var type = typeof obj;
    89     var type = typeof obj;
    90     return type === 'function' || type === 'object' && !!obj;
    90     return type === 'function' || (type === 'object' && !!obj);
    91   }
    91   }
    92 
    92 
    93   // Is a given value equal to null?
    93   // Is a given value equal to null?
    94   function isNull(obj) {
    94   function isNull(obj) {
    95     return obj === null;
    95     return obj === null;
   247   // arrays of strings.
   247   // arrays of strings.
   248   function emulatedSet(keys) {
   248   function emulatedSet(keys) {
   249     var hash = {};
   249     var hash = {};
   250     for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
   250     for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
   251     return {
   251     return {
   252       contains: function(key) { return hash[key]; },
   252       contains: function(key) { return hash[key] === true; },
   253       push: function(key) {
   253       push: function(key) {
   254         hash[key] = true;
   254         hash[key] = true;
   255         return keys.push(key);
   255         return keys.push(key);
   256       }
   256       }
   257     };
   257     };
   262   // needed.
   262   // needed.
   263   function collectNonEnumProps(obj, keys) {
   263   function collectNonEnumProps(obj, keys) {
   264     keys = emulatedSet(keys);
   264     keys = emulatedSet(keys);
   265     var nonEnumIdx = nonEnumerableProps.length;
   265     var nonEnumIdx = nonEnumerableProps.length;
   266     var constructor = obj.constructor;
   266     var constructor = obj.constructor;
   267     var proto = isFunction$1(constructor) && constructor.prototype || ObjProto;
   267     var proto = (isFunction$1(constructor) && constructor.prototype) || ObjProto;
   268 
   268 
   269     // Constructor is a special case.
   269     // Constructor is a special case.
   270     var prop = 'constructor';
   270     var prop = 'constructor';
   271     if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop);
   271     if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop);
   272 
   272 
  1465 
  1465 
  1466   // Return the maximum element (or element-based computation).
  1466   // Return the maximum element (or element-based computation).
  1467   function max(obj, iteratee, context) {
  1467   function max(obj, iteratee, context) {
  1468     var result = -Infinity, lastComputed = -Infinity,
  1468     var result = -Infinity, lastComputed = -Infinity,
  1469         value, computed;
  1469         value, computed;
  1470     if (iteratee == null || typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null) {
  1470     if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
  1471       obj = isArrayLike(obj) ? obj : values(obj);
  1471       obj = isArrayLike(obj) ? obj : values(obj);
  1472       for (var i = 0, length = obj.length; i < length; i++) {
  1472       for (var i = 0, length = obj.length; i < length; i++) {
  1473         value = obj[i];
  1473         value = obj[i];
  1474         if (value != null && value > result) {
  1474         if (value != null && value > result) {
  1475           result = value;
  1475           result = value;
  1477       }
  1477       }
  1478     } else {
  1478     } else {
  1479       iteratee = cb(iteratee, context);
  1479       iteratee = cb(iteratee, context);
  1480       each(obj, function(v, index, list) {
  1480       each(obj, function(v, index, list) {
  1481         computed = iteratee(v, index, list);
  1481         computed = iteratee(v, index, list);
  1482         if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  1482         if (computed > lastComputed || (computed === -Infinity && result === -Infinity)) {
  1483           result = v;
  1483           result = v;
  1484           lastComputed = computed;
  1484           lastComputed = computed;
  1485         }
  1485         }
  1486       });
  1486       });
  1487     }
  1487     }
  1490 
  1490 
  1491   // Return the minimum element (or element-based computation).
  1491   // Return the minimum element (or element-based computation).
  1492   function min(obj, iteratee, context) {
  1492   function min(obj, iteratee, context) {
  1493     var result = Infinity, lastComputed = Infinity,
  1493     var result = Infinity, lastComputed = Infinity,
  1494         value, computed;
  1494         value, computed;
  1495     if (iteratee == null || typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null) {
  1495     if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
  1496       obj = isArrayLike(obj) ? obj : values(obj);
  1496       obj = isArrayLike(obj) ? obj : values(obj);
  1497       for (var i = 0, length = obj.length; i < length; i++) {
  1497       for (var i = 0, length = obj.length; i < length; i++) {
  1498         value = obj[i];
  1498         value = obj[i];
  1499         if (value != null && value < result) {
  1499         if (value != null && value < result) {
  1500           result = value;
  1500           result = value;
  1502       }
  1502       }
  1503     } else {
  1503     } else {
  1504       iteratee = cb(iteratee, context);
  1504       iteratee = cb(iteratee, context);
  1505       each(obj, function(v, index, list) {
  1505       each(obj, function(v, index, list) {
  1506         computed = iteratee(v, index, list);
  1506         computed = iteratee(v, index, list);
  1507         if (computed < lastComputed || computed === Infinity && result === Infinity) {
  1507         if (computed < lastComputed || (computed === Infinity && result === Infinity)) {
  1508           result = v;
  1508           result = v;
  1509           lastComputed = computed;
  1509           lastComputed = computed;
  1510         }
  1510         }
  1511       });
  1511       });
  1512     }
  1512     }
  1513     return result;
  1513     return result;
       
  1514   }
       
  1515 
       
  1516   // Safely create a real, live array from anything iterable.
       
  1517   var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
       
  1518   function toArray(obj) {
       
  1519     if (!obj) return [];
       
  1520     if (isArray(obj)) return slice.call(obj);
       
  1521     if (isString(obj)) {
       
  1522       // Keep surrogate pair characters together.
       
  1523       return obj.match(reStrSymbol);
       
  1524     }
       
  1525     if (isArrayLike(obj)) return map(obj, identity);
       
  1526     return values(obj);
  1514   }
  1527   }
  1515 
  1528 
  1516   // Sample **n** random values from a collection using the modern version of the
  1529   // Sample **n** random values from a collection using the modern version of the
  1517   // [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  1530   // [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  1518   // If **n** is not specified, returns a single random element.
  1531   // If **n** is not specified, returns a single random element.
  1520   function sample(obj, n, guard) {
  1533   function sample(obj, n, guard) {
  1521     if (n == null || guard) {
  1534     if (n == null || guard) {
  1522       if (!isArrayLike(obj)) obj = values(obj);
  1535       if (!isArrayLike(obj)) obj = values(obj);
  1523       return obj[random(obj.length - 1)];
  1536       return obj[random(obj.length - 1)];
  1524     }
  1537     }
  1525     var sample = isArrayLike(obj) ? clone(obj) : values(obj);
  1538     var sample = toArray(obj);
  1526     var length = getLength(sample);
  1539     var length = getLength(sample);
  1527     n = Math.max(Math.min(n, length), 0);
  1540     n = Math.max(Math.min(n, length), 0);
  1528     var last = length - 1;
  1541     var last = length - 1;
  1529     for (var index = 0; index < n; index++) {
  1542     for (var index = 0; index < n; index++) {
  1530       var rand = random(index, last);
  1543       var rand = random(index, last);
  1597   // truth test, and one whose elements all do not pass the truth test.
  1610   // truth test, and one whose elements all do not pass the truth test.
  1598   var partition = group(function(result, value, pass) {
  1611   var partition = group(function(result, value, pass) {
  1599     result[pass ? 0 : 1].push(value);
  1612     result[pass ? 0 : 1].push(value);
  1600   }, true);
  1613   }, true);
  1601 
  1614 
  1602   // Safely create a real, live array from anything iterable.
       
  1603   var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
       
  1604   function toArray(obj) {
       
  1605     if (!obj) return [];
       
  1606     if (isArray(obj)) return slice.call(obj);
       
  1607     if (isString(obj)) {
       
  1608       // Keep surrogate pair characters together.
       
  1609       return obj.match(reStrSymbol);
       
  1610     }
       
  1611     if (isArrayLike(obj)) return map(obj, identity);
       
  1612     return values(obj);
       
  1613   }
       
  1614 
       
  1615   // Return the number of elements in a collection.
  1615   // Return the number of elements in a collection.
  1616   function size(obj) {
  1616   function size(obj) {
  1617     if (obj == null) return 0;
  1617     if (obj == null) return 0;
  1618     return isArrayLike(obj) ? obj.length : keys(obj).length;
  1618     return isArrayLike(obj) ? obj.length : keys(obj).length;
  1619   }
  1619   }
  1770   }
  1770   }
  1771 
  1771 
  1772   // Complement of zip. Unzip accepts an array of arrays and groups
  1772   // Complement of zip. Unzip accepts an array of arrays and groups
  1773   // each array's elements on shared indices.
  1773   // each array's elements on shared indices.
  1774   function unzip(array) {
  1774   function unzip(array) {
  1775     var length = array && max(array, getLength).length || 0;
  1775     var length = (array && max(array, getLength).length) || 0;
  1776     var result = Array(length);
  1776     var result = Array(length);
  1777 
  1777 
  1778     for (var index = 0; index < length; index++) {
  1778     for (var index = 0; index < length; index++) {
  1779       result[index] = pluck(array, index);
  1779       result[index] = pluck(array, index);
  1780     }
  1780     }