JAVASCRIPT   127

lodash.custom.js

Guest on 26th July 2021 04:39:32 PM

  1. /**
  2.  * @license
  3.  * Lodash (Custom Build) <https://lodash.com/>
  4.  * Build: `lodash include="get" -o js/lodash.custom.js`
  5.  * Copyright JS Foundation and other contributors <https://js.foundation/>
  6.  * Released under MIT license <https://lodash.com/license>
  7.  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  8.  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9.  */
  10. ;(function() {
  11.  
  12.   /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  13.   var undefined;
  14.  
  15.   /** Used as the semantic version number. */
  16.   var VERSION = '4.17.5';
  17.  
  18.   /** Error message constants. */
  19.   var FUNC_ERROR_TEXT = 'Expected a function';
  20.  
  21.   /** Used to stand-in for `undefined` hash values. */
  22.   var HASH_UNDEFINED = '__lodash_hash_undefined__';
  23.  
  24.   /** Used as the maximum memoize cache size. */
  25.   var MAX_MEMOIZE_SIZE = 500;
  26.  
  27.   /** Used as references for various `Number` constants. */
  28.   var INFINITY = 1 / 0;
  29.  
  30.   /** `Object#toString` result references. */
  31.   var asyncTag = '[object AsyncFunction]',
  32.       funcTag = '[object Function]',
  33.       genTag = '[object GeneratorFunction]',
  34.       nullTag = '[object Null]',
  35.       proxyTag = '[object Proxy]',
  36.       symbolTag = '[object Symbol]',
  37.       undefinedTag = '[object Undefined]';
  38.  
  39.   /** Used to match property names within property paths. */
  40.   var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  41.       reIsPlainProp = /^\w*$/,
  42.       rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  43.  
  44.   /**
  45.    * Used to match `RegExp`
  46.    * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  47.    */
  48.   var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  49.  
  50.   /** Used to match backslashes in property paths. */
  51.   var reEscapeChar = /\\(\\)?/g;
  52.  
  53.   /** Used to detect host constructors (Safari). */
  54.   var reIsHostCtor = /^\[object .+?Constructor\]$/;
  55.  
  56.   /** Detect free variable `global` from Node.js. */
  57.   var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  58.  
  59.   /** Detect free variable `self`. */
  60.   var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  61.  
  62.   /** Used as a reference to the global object. */
  63.   var root = freeGlobal || freeSelf || Function('return this')();
  64.  
  65.   /** Detect free variable `exports`. */
  66.   var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  67.  
  68.   /** Detect free variable `module`. */
  69.   var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  70.  
  71.   /*--------------------------------------------------------------------------*/
  72.  
  73.   /**
  74.    * A specialized version of `_.map` for arrays without support for iteratee
  75.    * shorthands.
  76.    *
  77.    * @private
  78.    * @param {Array} [array] The array to iterate over.
  79.    * @param {Function} iteratee The function invoked per iteration.
  80.    * @returns {Array} Returns the new mapped array.
  81.    */
  82.   function arrayMap(array, iteratee) {
  83.     var index = -1,
  84.         length = array == null ? 0 : array.length,
  85.         result = Array(length);
  86.  
  87.     while (++index < length) {
  88.       result[index] = iteratee(array[index], index, array);
  89.     }
  90.     return result;
  91.   }
  92.  
  93.   /**
  94.    * Gets the value at `key` of `object`.
  95.    *
  96.    * @private
  97.    * @param {Object} [object] The object to query.
  98.    * @param {string} key The key of the property to get.
  99.    * @returns {*} Returns the property value.
  100.    */
  101.   function getValue(object, key) {
  102.     return object == null ? undefined : object[key];
  103.   }
  104.  
  105.   /*--------------------------------------------------------------------------*/
  106.  
  107.   /** Used for built-in method references. */
  108.   var arrayProto = Array.prototype,
  109.       funcProto = Function.prototype,
  110.       objectProto = Object.prototype;
  111.  
  112.   /** Used to detect overreaching core-js shims. */
  113.   var coreJsData = root['__core-js_shared__'];
  114.  
  115.   /** Used to resolve the decompiled source of functions. */
  116.   var funcToString = funcProto.toString;
  117.  
  118.   /** Used to check objects for own properties. */
  119.   var hasOwnProperty = objectProto.hasOwnProperty;
  120.  
  121.   /** Used to detect methods masquerading as native. */
  122.   var maskSrcKey = (function() {
  123.     var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  124.     return uid ? ('Symbol(src)_1.' + uid) : '';
  125.   }());
  126.  
  127.   /**
  128.    * Used to resolve the
  129.    * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  130.    * of values.
  131.    */
  132.   var nativeObjectToString = objectProto.toString;
  133.  
  134.   /** Used to detect if a method is native. */
  135.   var reIsNative = RegExp('^' +
  136.     funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  137.     .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  138.   );
  139.  
  140.   /** Built-in value references. */
  141.   var Symbol = root.Symbol,
  142.       splice = arrayProto.splice,
  143.       symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  144.  
  145.   /* Built-in method references that are verified to be native. */
  146.   var Map = getNative(root, 'Map'),
  147.       nativeCreate = getNative(Object, 'create');
  148.  
  149.   /** Used to lookup unminified function names. */
  150.   var realNames = {};
  151.  
  152.   /** Used to convert symbols to primitives and strings. */
  153.   var symbolProto = Symbol ? Symbol.prototype : undefined,
  154.       symbolToString = symbolProto ? symbolProto.toString : undefined;
  155.  
  156.   /*------------------------------------------------------------------------*/
  157.  
  158.   /**
  159.    * Creates a `lodash` object which wraps `value` to enable implicit method
  160.    * chain sequences. Methods that operate on and return arrays, collections,
  161.    * and functions can be chained together. Methods that retrieve a single value
  162.    * or may return a primitive value will automatically end the chain sequence
  163.    * and return the unwrapped value. Otherwise, the value must be unwrapped
  164.    * with `_#value`.
  165.    *
  166.    * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  167.    * enabled using `_.chain`.
  168.    *
  169.    * The execution of chained methods is lazy, that is, it's deferred until
  170.    * `_#value` is implicitly or explicitly called.
  171.    *
  172.    * Lazy evaluation allows several methods to support shortcut fusion.
  173.    * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  174.    * the creation of intermediate arrays and can greatly reduce the number of
  175.    * iteratee executions. Sections of a chain sequence qualify for shortcut
  176.    * fusion if the section is applied to an array and iteratees accept only
  177.    * one argument. The heuristic for whether a section qualifies for shortcut
  178.    * fusion is subject to change.
  179.    *
  180.    * Chaining is supported in custom builds as long as the `_#value` method is
  181.    * directly or indirectly included in the build.
  182.    *
  183.    * In addition to lodash methods, wrappers have `Array` and `String` methods.
  184.    *
  185.    * The wrapper `Array` methods are:
  186.    * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  187.    *
  188.    * The wrapper `String` methods are:
  189.    * `replace` and `split`
  190.    *
  191.    * The wrapper methods that support shortcut fusion are:
  192.    * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  193.    * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  194.    * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  195.    *
  196.    * The chainable wrapper methods are:
  197.    * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  198.    * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  199.    * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  200.    * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  201.    * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  202.    * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  203.    * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  204.    * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  205.    * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  206.    * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  207.    * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  208.    * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  209.    * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  210.    * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  211.    * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  212.    * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  213.    * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  214.    * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  215.    * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  216.    * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  217.    * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  218.    * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  219.    * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  220.    * `zipObject`, `zipObjectDeep`, and `zipWith`
  221.    *
  222.    * The wrapper methods that are **not** chainable by default are:
  223.    * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  224.    * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  225.    * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  226.    * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  227.    * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  228.    * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  229.    * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  230.    * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  231.    * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  232.    * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  233.    * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  234.    * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  235.    * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  236.    * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  237.    * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  238.    * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  239.    * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  240.    * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  241.    * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  242.    * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  243.    * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  244.    * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  245.    * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  246.    * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  247.    * `upperFirst`, `value`, and `words`
  248.    *
  249.    * @name _
  250.    * @constructor
  251.    * @category Seq
  252.    * @param {*} value The value to wrap in a `lodash` instance.
  253.    * @returns {Object} Returns the new `lodash` wrapper instance.
  254.    * @example
  255.    *
  256.    * function square(n) {
  257.    *   return n * n;
  258.    * }
  259.    *
  260.    * var wrapped = _([1, 2, 3]);
  261.    *
  262.    * // Returns an unwrapped value.
  263.    * wrapped.reduce(_.add);
  264.    * // => 6
  265.    *
  266.    * // Returns a wrapped value.
  267.    * var squares = wrapped.map(square);
  268.    *
  269.    * _.isArray(squares);
  270.    * // => false
  271.    *
  272.    * _.isArray(squares.value());
  273.    * // => true
  274.    */
  275.   function lodash() {
  276.     // No operation performed.
  277.   }
  278.  
  279.   /*------------------------------------------------------------------------*/
  280.  
  281.   /**
  282.    * Creates a hash object.
  283.    *
  284.    * @private
  285.    * @constructor
  286.    * @param {Array} [entries] The key-value pairs to cache.
  287.    */
  288.   function Hash(entries) {
  289.     var index = -1,
  290.         length = entries == null ? 0 : entries.length;
  291.  
  292.     this.clear();
  293.     while (++index < length) {
  294.       var entry = entries[index];
  295.       this.set(entry[0], entry[1]);
  296.     }
  297.   }
  298.  
  299.   /**
  300.    * Removes all key-value entries from the hash.
  301.    *
  302.    * @private
  303.    * @name clear
  304.    * @memberOf Hash
  305.    */
  306.   function hashClear() {
  307.     this.__data__ = nativeCreate ? nativeCreate(null) : {};
  308.     this.size = 0;
  309.   }
  310.  
  311.   /**
  312.    * Removes `key` and its value from the hash.
  313.    *
  314.    * @private
  315.    * @name delete
  316.    * @memberOf Hash
  317.    * @param {Object} hash The hash to modify.
  318.    * @param {string} key The key of the value to remove.
  319.    * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  320.    */
  321.   function hashDelete(key) {
  322.     var result = this.has(key) && delete this.__data__[key];
  323.     this.size -= result ? 1 : 0;
  324.     return result;
  325.   }
  326.  
  327.   /**
  328.    * Gets the hash value for `key`.
  329.    *
  330.    * @private
  331.    * @name get
  332.    * @memberOf Hash
  333.    * @param {string} key The key of the value to get.
  334.    * @returns {*} Returns the entry value.
  335.    */
  336.   function hashGet(key) {
  337.     var data = this.__data__;
  338.     if (nativeCreate) {
  339.       var result = data[key];
  340.       return result === HASH_UNDEFINED ? undefined : result;
  341.     }
  342.     return hasOwnProperty.call(data, key) ? data[key] : undefined;
  343.   }
  344.  
  345.   /**
  346.    * Checks if a hash value for `key` exists.
  347.    *
  348.    * @private
  349.    * @name has
  350.    * @memberOf Hash
  351.    * @param {string} key The key of the entry to check.
  352.    * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  353.    */
  354.   function hashHas(key) {
  355.     var data = this.__data__;
  356.     return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  357.   }
  358.  
  359.   /**
  360.    * Sets the hash `key` to `value`.
  361.    *
  362.    * @private
  363.    * @name set
  364.    * @memberOf Hash
  365.    * @param {string} key The key of the value to set.
  366.    * @param {*} value The value to set.
  367.    * @returns {Object} Returns the hash instance.
  368.    */
  369.   function hashSet(key, value) {
  370.     var data = this.__data__;
  371.     this.size += this.has(key) ? 0 : 1;
  372.     data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  373.     return this;
  374.   }
  375.  
  376.   // Add methods to `Hash`.
  377.   Hash.prototype.clear = hashClear;
  378.   Hash.prototype['delete'] = hashDelete;
  379.   Hash.prototype.get = hashGet;
  380.   Hash.prototype.has = hashHas;
  381.   Hash.prototype.set = hashSet;
  382.  
  383.   /*------------------------------------------------------------------------*/
  384.  
  385.   /**
  386.    * Creates an list cache object.
  387.    *
  388.    * @private
  389.    * @constructor
  390.    * @param {Array} [entries] The key-value pairs to cache.
  391.    */
  392.   function ListCache(entries) {
  393.     var index = -1,
  394.         length = entries == null ? 0 : entries.length;
  395.  
  396.     this.clear();
  397.     while (++index < length) {
  398.       var entry = entries[index];
  399.       this.set(entry[0], entry[1]);
  400.     }
  401.   }
  402.  
  403.   /**
  404.    * Removes all key-value entries from the list cache.
  405.    *
  406.    * @private
  407.    * @name clear
  408.    * @memberOf ListCache
  409.    */
  410.   function listCacheClear() {
  411.     this.__data__ = [];
  412.     this.size = 0;
  413.   }
  414.  
  415.   /**
  416.    * Removes `key` and its value from the list cache.
  417.    *
  418.    * @private
  419.    * @name delete
  420.    * @memberOf ListCache
  421.    * @param {string} key The key of the value to remove.
  422.    * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  423.    */
  424.   function listCacheDelete(key) {
  425.     var data = this.__data__,
  426.         index = assocIndexOf(data, key);
  427.  
  428.     if (index < 0) {
  429.       return false;
  430.     }
  431.     var lastIndex = data.length - 1;
  432.     if (index == lastIndex) {
  433.       data.pop();
  434.     } else {
  435.       splice.call(data, index, 1);
  436.     }
  437.     --this.size;
  438.     return true;
  439.   }
  440.  
  441.   /**
  442.    * Gets the list cache value for `key`.
  443.    *
  444.    * @private
  445.    * @name get
  446.    * @memberOf ListCache
  447.    * @param {string} key The key of the value to get.
  448.    * @returns {*} Returns the entry value.
  449.    */
  450.   function listCacheGet(key) {
  451.     var data = this.__data__,
  452.         index = assocIndexOf(data, key);
  453.  
  454.     return index < 0 ? undefined : data[index][1];
  455.   }
  456.  
  457.   /**
  458.    * Checks if a list cache value for `key` exists.
  459.    *
  460.    * @private
  461.    * @name has
  462.    * @memberOf ListCache
  463.    * @param {string} key The key of the entry to check.
  464.    * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  465.    */
  466.   function listCacheHas(key) {
  467.     return assocIndexOf(this.__data__, key) > -1;
  468.   }
  469.  
  470.   /**
  471.    * Sets the list cache `key` to `value`.
  472.    *
  473.    * @private
  474.    * @name set
  475.    * @memberOf ListCache
  476.    * @param {string} key The key of the value to set.
  477.    * @param {*} value The value to set.
  478.    * @returns {Object} Returns the list cache instance.
  479.    */
  480.   function listCacheSet(key, value) {
  481.     var data = this.__data__,
  482.         index = assocIndexOf(data, key);
  483.  
  484.     if (index < 0) {
  485.       ++this.size;
  486.       data.push([key, value]);
  487.     } else {
  488.       data[index][1] = value;
  489.     }
  490.     return this;
  491.   }
  492.  
  493.   // Add methods to `ListCache`.
  494.   ListCache.prototype.clear = listCacheClear;
  495.   ListCache.prototype['delete'] = listCacheDelete;
  496.   ListCache.prototype.get = listCacheGet;
  497.   ListCache.prototype.has = listCacheHas;
  498.   ListCache.prototype.set = listCacheSet;
  499.  
  500.   /*------------------------------------------------------------------------*/
  501.  
  502.   /**
  503.    * Creates a map cache object to store key-value pairs.
  504.    *
  505.    * @private
  506.    * @constructor
  507.    * @param {Array} [entries] The key-value pairs to cache.
  508.    */
  509.   function MapCache(entries) {
  510.     var index = -1,
  511.         length = entries == null ? 0 : entries.length;
  512.  
  513.     this.clear();
  514.     while (++index < length) {
  515.       var entry = entries[index];
  516.       this.set(entry[0], entry[1]);
  517.     }
  518.   }
  519.  
  520.   /**
  521.    * Removes all key-value entries from the map.
  522.    *
  523.    * @private
  524.    * @name clear
  525.    * @memberOf MapCache
  526.    */
  527.   function mapCacheClear() {
  528.     this.size = 0;
  529.     this.__data__ = {
  530.       'hash': new Hash,
  531.       'map': new (Map || ListCache),
  532.       'string': new Hash
  533.     };
  534.   }
  535.  
  536.   /**
  537.    * Removes `key` and its value from the map.
  538.    *
  539.    * @private
  540.    * @name delete
  541.    * @memberOf MapCache
  542.    * @param {string} key The key of the value to remove.
  543.    * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  544.    */
  545.   function mapCacheDelete(key) {
  546.     var result = getMapData(this, key)['delete'](key);
  547.     this.size -= result ? 1 : 0;
  548.     return result;
  549.   }
  550.  
  551.   /**
  552.    * Gets the map value for `key`.
  553.    *
  554.    * @private
  555.    * @name get
  556.    * @memberOf MapCache
  557.    * @param {string} key The key of the value to get.
  558.    * @returns {*} Returns the entry value.
  559.    */
  560.   function mapCacheGet(key) {
  561.     return getMapData(this, key).get(key);
  562.   }
  563.  
  564.   /**
  565.    * Checks if a map value for `key` exists.
  566.    *
  567.    * @private
  568.    * @name has
  569.    * @memberOf MapCache
  570.    * @param {string} key The key of the entry to check.
  571.    * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  572.    */
  573.   function mapCacheHas(key) {
  574.     return getMapData(this, key).has(key);
  575.   }
  576.  
  577.   /**
  578.    * Sets the map `key` to `value`.
  579.    *
  580.    * @private
  581.    * @name set
  582.    * @memberOf MapCache
  583.    * @param {string} key The key of the value to set.
  584.    * @param {*} value The value to set.
  585.    * @returns {Object} Returns the map cache instance.
  586.    */
  587.   function mapCacheSet(key, value) {
  588.     var data = getMapData(this, key),
  589.         size = data.size;
  590.  
  591.     data.set(key, value);
  592.     this.size += data.size == size ? 0 : 1;
  593.     return this;
  594.   }
  595.  
  596.   // Add methods to `MapCache`.
  597.   MapCache.prototype.clear = mapCacheClear;
  598.   MapCache.prototype['delete'] = mapCacheDelete;
  599.   MapCache.prototype.get = mapCacheGet;
  600.   MapCache.prototype.has = mapCacheHas;
  601.   MapCache.prototype.set = mapCacheSet;
  602.  
  603.   /*------------------------------------------------------------------------*/
  604.  
  605.   /**
  606.    * Gets the index at which the `key` is found in `array` of key-value pairs.
  607.    *
  608.    * @private
  609.    * @param {Array} array The array to inspect.
  610.    * @param {*} key The key to search for.
  611.    * @returns {number} Returns the index of the matched value, else `-1`.
  612.    */
  613.   function assocIndexOf(array, key) {
  614.     var length = array.length;
  615.     while (length--) {
  616.       if (eq(array[length][0], key)) {
  617.         return length;
  618.       }
  619.     }
  620.     return -1;
  621.   }
  622.  
  623.   /**
  624.    * The base implementation of `_.get` without support for default values.
  625.    *
  626.    * @private
  627.    * @param {Object} object The object to query.
  628.    * @param {Array|string} path The path of the property to get.
  629.    * @returns {*} Returns the resolved value.
  630.    */
  631.   function baseGet(object, path) {
  632.     path = castPath(path, object);
  633.  
  634.     var index = 0,
  635.         length = path.length;
  636.  
  637.     while (object != null && index < length) {
  638.       object = object[toKey(path[index++])];
  639.     }
  640.     return (index && index == length) ? object : undefined;
  641.   }
  642.  
  643.   /**
  644.    * The base implementation of `getTag` without fallbacks for buggy environments.
  645.    *
  646.    * @private
  647.    * @param {*} value The value to query.
  648.    * @returns {string} Returns the `toStringTag`.
  649.    */
  650.   function baseGetTag(value) {
  651.     if (value == null) {
  652.       return value === undefined ? undefinedTag : nullTag;
  653.     }
  654.     return (symToStringTag && symToStringTag in Object(value))
  655.       ? getRawTag(value)
  656.       : objectToString(value);
  657.   }
  658.  
  659.   /**
  660.    * The base implementation of `_.isNative` without bad shim checks.
  661.    *
  662.    * @private
  663.    * @param {*} value The value to check.
  664.    * @returns {boolean} Returns `true` if `value` is a native function,
  665.    *  else `false`.
  666.    */
  667.   function baseIsNative(value) {
  668.     if (!isObject(value) || isMasked(value)) {
  669.       return false;
  670.     }
  671.     var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  672.     return pattern.test(toSource(value));
  673.   }
  674.  
  675.   /**
  676.    * The base implementation of `_.toString` which doesn't convert nullish
  677.    * values to empty strings.
  678.    *
  679.    * @private
  680.    * @param {*} value The value to process.
  681.    * @returns {string} Returns the string.
  682.    */
  683.   function baseToString(value) {
  684.     // Exit early for strings to avoid a performance hit in some environments.
  685.     if (typeof value == 'string') {
  686.       return value;
  687.     }
  688.     if (isArray(value)) {
  689.       // Recursively convert values (susceptible to call stack limits).
  690.       return arrayMap(value, baseToString) + '';
  691.     }
  692.     if (isSymbol(value)) {
  693.       return symbolToString ? symbolToString.call(value) : '';
  694.     }
  695.     var result = (value + '');
  696.     return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  697.   }
  698.  
  699.   /**
  700.    * Casts `value` to a path array if it's not one.
  701.    *
  702.    * @private
  703.    * @param {*} value The value to inspect.
  704.    * @param {Object} [object] The object to query keys on.
  705.    * @returns {Array} Returns the cast property path array.
  706.    */
  707.   function castPath(value, object) {
  708.     if (isArray(value)) {
  709.       return value;
  710.     }
  711.     return isKey(value, object) ? [value] : stringToPath(toString(value));
  712.   }
  713.  
  714.   /**
  715.    * Gets the data for `map`.
  716.    *
  717.    * @private
  718.    * @param {Object} map The map to query.
  719.    * @param {string} key The reference key.
  720.    * @returns {*} Returns the map data.
  721.    */
  722.   function getMapData(map, key) {
  723.     var data = map.__data__;
  724.     return isKeyable(key)
  725.       ? data[typeof key == 'string' ? 'string' : 'hash']
  726.       : data.map;
  727.   }
  728.  
  729.   /**
  730.    * Gets the native function at `key` of `object`.
  731.    *
  732.    * @private
  733.    * @param {Object} object The object to query.
  734.    * @param {string} key The key of the method to get.
  735.    * @returns {*} Returns the function if it's native, else `undefined`.
  736.    */
  737.   function getNative(object, key) {
  738.     var value = getValue(object, key);
  739.     return baseIsNative(value) ? value : undefined;
  740.   }
  741.  
  742.   /**
  743.    * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  744.    *
  745.    * @private
  746.    * @param {*} value The value to query.
  747.    * @returns {string} Returns the raw `toStringTag`.
  748.    */
  749.   function getRawTag(value) {
  750.     var isOwn = hasOwnProperty.call(value, symToStringTag),
  751.         tag = value[symToStringTag];
  752.  
  753.     try {
  754.       value[symToStringTag] = undefined;
  755.       var unmasked = true;
  756.     } catch (e) {}
  757.  
  758.     var result = nativeObjectToString.call(value);
  759.     if (unmasked) {
  760.       if (isOwn) {
  761.         value[symToStringTag] = tag;
  762.       } else {
  763.         delete value[symToStringTag];
  764.       }
  765.     }
  766.     return result;
  767.   }
  768.  
  769.   /**
  770.    * Checks if `value` is a property name and not a property path.
  771.    *
  772.    * @private
  773.    * @param {*} value The value to check.
  774.    * @param {Object} [object] The object to query keys on.
  775.    * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  776.    */
  777.   function isKey(value, object) {
  778.     if (isArray(value)) {
  779.       return false;
  780.     }
  781.     var type = typeof value;
  782.     if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  783.         value == null || isSymbol(value)) {
  784.       return true;
  785.     }
  786.     return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  787.       (object != null && value in Object(object));
  788.   }
  789.  
  790.   /**
  791.    * Checks if `value` is suitable for use as unique object key.
  792.    *
  793.    * @private
  794.    * @param {*} value The value to check.
  795.    * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  796.    */
  797.   function isKeyable(value) {
  798.     var type = typeof value;
  799.     return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  800.       ? (value !== '__proto__')
  801.       : (value === null);
  802.   }
  803.  
  804.   /**
  805.    * Checks if `func` has its source masked.
  806.    *
  807.    * @private
  808.    * @param {Function} func The function to check.
  809.    * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  810.    */
  811.   function isMasked(func) {
  812.     return !!maskSrcKey && (maskSrcKey in func);
  813.   }
  814.  
  815.   /**
  816.    * A specialized version of `_.memoize` which clears the memoized function's
  817.    * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  818.    *
  819.    * @private
  820.    * @param {Function} func The function to have its output memoized.
  821.    * @returns {Function} Returns the new memoized function.
  822.    */
  823.   function memoizeCapped(func) {
  824.     var result = memoize(func, function(key) {
  825.       if (cache.size === MAX_MEMOIZE_SIZE) {
  826.         cache.clear();
  827.       }
  828.       return key;
  829.     });
  830.  
  831.     var cache = result.cache;
  832.     return result;
  833.   }
  834.  
  835.   /**
  836.    * Converts `value` to a string using `Object.prototype.toString`.
  837.    *
  838.    * @private
  839.    * @param {*} value The value to convert.
  840.    * @returns {string} Returns the converted string.
  841.    */
  842.   function objectToString(value) {
  843.     return nativeObjectToString.call(value);
  844.   }
  845.  
  846.   /**
  847.    * Converts `string` to a property path array.
  848.    *
  849.    * @private
  850.    * @param {string} string The string to convert.
  851.    * @returns {Array} Returns the property path array.
  852.    */
  853.   var stringToPath = memoizeCapped(function(string) {
  854.     var result = [];
  855.     if (string.charCodeAt(0) === 46 /* . */) {
  856.       result.push('');
  857.     }
  858.     string.replace(rePropName, function(match, number, quote, subString) {
  859.       result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  860.     });
  861.     return result;
  862.   });
  863.  
  864.   /**
  865.    * Converts `value` to a string key if it's not a string or symbol.
  866.    *
  867.    * @private
  868.    * @param {*} value The value to inspect.
  869.    * @returns {string|symbol} Returns the key.
  870.    */
  871.   function toKey(value) {
  872.     if (typeof value == 'string' || isSymbol(value)) {
  873.       return value;
  874.     }
  875.     var result = (value + '');
  876.     return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  877.   }
  878.  
  879.   /**
  880.    * Converts `func` to its source code.
  881.    *
  882.    * @private
  883.    * @param {Function} func The function to convert.
  884.    * @returns {string} Returns the source code.
  885.    */
  886.   function toSource(func) {
  887.     if (func != null) {
  888.       try {
  889.         return funcToString.call(func);
  890.       } catch (e) {}
  891.       try {
  892.         return (func + '');
  893.       } catch (e) {}
  894.     }
  895.     return '';
  896.   }
  897.  
  898.   /*------------------------------------------------------------------------*/
  899.  
  900.   /**
  901.    * Creates a function that memoizes the result of `func`. If `resolver` is
  902.    * provided, it determines the cache key for storing the result based on the
  903.    * arguments provided to the memoized function. By default, the first argument
  904.    * provided to the memoized function is used as the map cache key. The `func`
  905.    * is invoked with the `this` binding of the memoized function.
  906.    *
  907.    * **Note:** The cache is exposed as the `cache` property on the memoized
  908.    * function. Its creation may be customized by replacing the `_.memoize.Cache`
  909.    * constructor with one whose instances implement the
  910.    * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  911.    * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  912.    *
  913.    * @static
  914.    * @memberOf _
  915.    * @since 0.1.0
  916.    * @category Function
  917.    * @param {Function} func The function to have its output memoized.
  918.    * @param {Function} [resolver] The function to resolve the cache key.
  919.    * @returns {Function} Returns the new memoized function.
  920.    * @example
  921.    *
  922.    * var object = { 'a': 1, 'b': 2 };
  923.    * var other = { 'c': 3, 'd': 4 };
  924.    *
  925.    * var values = _.memoize(_.values);
  926.    * values(object);
  927.    * // => [1, 2]
  928.    *
  929.    * values(other);
  930.    * // => [3, 4]
  931.    *
  932.    * object.a = 2;
  933.    * values(object);
  934.    * // => [1, 2]
  935.    *
  936.    * // Modify the result cache.
  937.    * values.cache.set(object, ['a', 'b']);
  938.    * values(object);
  939.    * // => ['a', 'b']
  940.    *
  941.    * // Replace `_.memoize.Cache`.
  942.    * _.memoize.Cache = WeakMap;
  943.    */
  944.   function memoize(func, resolver) {
  945.     if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  946.       throw new TypeError(FUNC_ERROR_TEXT);
  947.     }
  948.     var memoized = function() {
  949.       var args = arguments,
  950.           key = resolver ? resolver.apply(this, args) : args[0],
  951.           cache = memoized.cache;
  952.  
  953.       if (cache.has(key)) {
  954.         return cache.get(key);
  955.       }
  956.       var result = func.apply(this, args);
  957.       memoized.cache = cache.set(key, result) || cache;
  958.       return result;
  959.     };
  960.     memoized.cache = new (memoize.Cache || MapCache);
  961.     return memoized;
  962.   }
  963.  
  964.   // Expose `MapCache`.
  965.   memoize.Cache = MapCache;
  966.  
  967.   /*------------------------------------------------------------------------*/
  968.  
  969.   /**
  970.    * Performs a
  971.    * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  972.    * comparison between two values to determine if they are equivalent.
  973.    *
  974.    * @static
  975.    * @memberOf _
  976.    * @since 4.0.0
  977.    * @category Lang
  978.    * @param {*} value The value to compare.
  979.    * @param {*} other The other value to compare.
  980.    * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  981.    * @example
  982.    *
  983.    * var object = { 'a': 1 };
  984.    * var other = { 'a': 1 };
  985.    *
  986.    * _.eq(object, object);
  987.    * // => true
  988.    *
  989.    * _.eq(object, other);
  990.    * // => false
  991.    *
  992.    * _.eq('a', 'a');
  993.    * // => true
  994.    *
  995.    * _.eq('a', Object('a'));
  996.    * // => false
  997.    *
  998.    * _.eq(NaN, NaN);
  999.    * // => true
  1000.    */
  1001.   function eq(value, other) {
  1002.     return value === other || (value !== value && other !== other);
  1003.   }
  1004.  
  1005.   /**
  1006.    * Checks if `value` is classified as an `Array` object.
  1007.    *
  1008.    * @static
  1009.    * @memberOf _
  1010.    * @since 0.1.0
  1011.    * @category Lang
  1012.    * @param {*} value The value to check.
  1013.    * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  1014.    * @example
  1015.    *
  1016.    * _.isArray([1, 2, 3]);
  1017.    * // => true
  1018.    *
  1019.    * _.isArray(document.body.children);
  1020.    * // => false
  1021.    *
  1022.    * _.isArray('abc');
  1023.    * // => false
  1024.    *
  1025.    * _.isArray(_.noop);
  1026.    * // => false
  1027.    */
  1028.   var isArray = Array.isArray;
  1029.  
  1030.   /**
  1031.    * Checks if `value` is classified as a `Function` object.
  1032.    *
  1033.    * @static
  1034.    * @memberOf _
  1035.    * @since 0.1.0
  1036.    * @category Lang
  1037.    * @param {*} value The value to check.
  1038.    * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  1039.    * @example
  1040.    *
  1041.    * _.isFunction(_);
  1042.    * // => true
  1043.    *
  1044.    * _.isFunction(/abc/);
  1045.    * // => false
  1046.    */
  1047.   function isFunction(value) {
  1048.     if (!isObject(value)) {
  1049.       return false;
  1050.     }
  1051.     // The use of `Object#toString` avoids issues with the `typeof` operator
  1052.     // in Safari 9 which returns 'object' for typed arrays and other constructors.
  1053.     var tag = baseGetTag(value);
  1054.     return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  1055.   }
  1056.  
  1057.   /**
  1058.    * Checks if `value` is the
  1059.    * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1060.    * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1061.    *
  1062.    * @static
  1063.    * @memberOf _
  1064.    * @since 0.1.0
  1065.    * @category Lang
  1066.    * @param {*} value The value to check.
  1067.    * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1068.    * @example
  1069.    *
  1070.    * _.isObject({});
  1071.    * // => true
  1072.    *
  1073.    * _.isObject([1, 2, 3]);
  1074.    * // => true
  1075.    *
  1076.    * _.isObject(_.noop);
  1077.    * // => true
  1078.    *
  1079.    * _.isObject(null);
  1080.    * // => false
  1081.    */
  1082.   function isObject(value) {
  1083.     var type = typeof value;
  1084.     return value != null && (type == 'object' || type == 'function');
  1085.   }
  1086.  
  1087.   /**
  1088.    * Checks if `value` is object-like. A value is object-like if it's not `null`
  1089.    * and has a `typeof` result of "object".
  1090.    *
  1091.    * @static
  1092.    * @memberOf _
  1093.    * @since 4.0.0
  1094.    * @category Lang
  1095.    * @param {*} value The value to check.
  1096.    * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1097.    * @example
  1098.    *
  1099.    * _.isObjectLike({});
  1100.    * // => true
  1101.    *
  1102.    * _.isObjectLike([1, 2, 3]);
  1103.    * // => true
  1104.    *
  1105.    * _.isObjectLike(_.noop);
  1106.    * // => false
  1107.    *
  1108.    * _.isObjectLike(null);
  1109.    * // => false
  1110.    */
  1111.   function isObjectLike(value) {
  1112.     return value != null && typeof value == 'object';
  1113.   }
  1114.  
  1115.   /**
  1116.    * Checks if `value` is classified as a `Symbol` primitive or object.
  1117.    *
  1118.    * @static
  1119.    * @memberOf _
  1120.    * @since 4.0.0
  1121.    * @category Lang
  1122.    * @param {*} value The value to check.
  1123.    * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1124.    * @example
  1125.    *
  1126.    * _.isSymbol(Symbol.iterator);
  1127.    * // => true
  1128.    *
  1129.    * _.isSymbol('abc');
  1130.    * // => false
  1131.    */
  1132.   function isSymbol(value) {
  1133.     return typeof value == 'symbol' ||
  1134.       (isObjectLike(value) && baseGetTag(value) == symbolTag);
  1135.   }
  1136.  
  1137.   /**
  1138.    * Converts `value` to a string. An empty string is returned for `null`
  1139.    * and `undefined` values. The sign of `-0` is preserved.
  1140.    *
  1141.    * @static
  1142.    * @memberOf _
  1143.    * @since 4.0.0
  1144.    * @category Lang
  1145.    * @param {*} value The value to convert.
  1146.    * @returns {string} Returns the converted string.
  1147.    * @example
  1148.    *
  1149.    * _.toString(null);
  1150.    * // => ''
  1151.    *
  1152.    * _.toString(-0);
  1153.    * // => '-0'
  1154.    *
  1155.    * _.toString([1, 2, 3]);
  1156.    * // => '1,2,3'
  1157.    */
  1158.   function toString(value) {
  1159.     return value == null ? '' : baseToString(value);
  1160.   }
  1161.  
  1162.   /*------------------------------------------------------------------------*/
  1163.  
  1164.   /**
  1165.    * Gets the value at `path` of `object`. If the resolved value is
  1166.    * `undefined`, the `defaultValue` is returned in its place.
  1167.    *
  1168.    * @static
  1169.    * @memberOf _
  1170.    * @since 3.7.0
  1171.    * @category Object
  1172.    * @param {Object} object The object to query.
  1173.    * @param {Array|string} path The path of the property to get.
  1174.    * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  1175.    * @returns {*} Returns the resolved value.
  1176.    * @example
  1177.    *
  1178.    * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  1179.    *
  1180.    * _.get(object, 'a[0].b.c');
  1181.    * // => 3
  1182.    *
  1183.    * _.get(object, ['a', '0', 'b', 'c']);
  1184.    * // => 3
  1185.    *
  1186.    * _.get(object, 'a.b.c', 'default');
  1187.    * // => 'default'
  1188.    */
  1189.   function get(object, path, defaultValue) {
  1190.     var result = object == null ? undefined : baseGet(object, path);
  1191.     return result === undefined ? defaultValue : result;
  1192.   }
  1193.  
  1194.   /*------------------------------------------------------------------------*/
  1195.  
  1196.   // Add methods that return wrapped values in chain sequences.
  1197.   lodash.memoize = memoize;
  1198.  
  1199.   /*------------------------------------------------------------------------*/
  1200.  
  1201.   // Add methods that return unwrapped values in chain sequences.
  1202.   lodash.eq = eq;
  1203.   lodash.get = get;
  1204.   lodash.isArray = isArray;
  1205.   lodash.isFunction = isFunction;
  1206.   lodash.isObject = isObject;
  1207.   lodash.isObjectLike = isObjectLike;
  1208.   lodash.isSymbol = isSymbol;
  1209.   lodash.toString = toString;
  1210.  
  1211.   /*------------------------------------------------------------------------*/
  1212.  
  1213.   /**
  1214.    * The semantic version number.
  1215.    *
  1216.    * @static
  1217.    * @memberOf _
  1218.    * @type {string}
  1219.    */
  1220.   lodash.VERSION = VERSION;
  1221.  
  1222.   /*--------------------------------------------------------------------------*/
  1223.  
  1224.   // Some AMD build optimizers, like r.js, check for condition patterns like:
  1225.   if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  1226.     // Expose Lodash on the global object to prevent errors when Lodash is
  1227.     // loaded by a script tag in the presence of an AMD loader.
  1228.     // See http://requirejs.org/docs/errors.html#mismatch for more details.
  1229.     // Use `_.noConflict` to remove Lodash from the global object.
  1230.     root._ = lodash;
  1231.  
  1232.     // Define as an anonymous module so, through path mapping, it can be
  1233.     // referenced as the "underscore" module.
  1234.     define(function() {
  1235.       return lodash;
  1236.     });
  1237.   }
  1238.   // Check for `exports` after `define` in case a build optimizer adds it.
  1239.   else if (freeModule) {
  1240.     // Export for Node.js.
  1241.     (freeModule.exports = lodash)._ = lodash;
  1242.     // Export for CommonJS support.
  1243.     freeExports._ = lodash;
  1244.   }
  1245.   else {
  1246.     // Export to the global object.
  1247.     root._ = lodash;
  1248.   }
  1249. }.call(this));

Raw Paste


Login or Register to edit or fork this paste. It's free.