[6a3a178] | 1 | /**
|
---|
| 2 | * lodash (Custom Build) <https://lodash.com/>
|
---|
| 3 | * Build: `lodash modularize exports="npm" -o ./`
|
---|
| 4 | * Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
---|
| 5 | * Released under MIT license <https://lodash.com/license>
|
---|
| 6 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
---|
| 7 | * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | /** Used as the size to enable large array optimizations. */
|
---|
| 11 | var LARGE_ARRAY_SIZE = 200;
|
---|
| 12 |
|
---|
| 13 | /** Used to stand-in for `undefined` hash values. */
|
---|
| 14 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
---|
| 15 |
|
---|
| 16 | /** Used as references for various `Number` constants. */
|
---|
| 17 | var INFINITY = 1 / 0;
|
---|
| 18 |
|
---|
| 19 | /** `Object#toString` result references. */
|
---|
| 20 | var funcTag = '[object Function]',
|
---|
| 21 | genTag = '[object GeneratorFunction]';
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Used to match `RegExp`
|
---|
| 25 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
---|
| 26 | */
|
---|
| 27 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
---|
| 28 |
|
---|
| 29 | /** Used to detect host constructors (Safari). */
|
---|
| 30 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
---|
| 31 |
|
---|
| 32 | /** Detect free variable `global` from Node.js. */
|
---|
| 33 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
---|
| 34 |
|
---|
| 35 | /** Detect free variable `self`. */
|
---|
| 36 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
---|
| 37 |
|
---|
| 38 | /** Used as a reference to the global object. */
|
---|
| 39 | var root = freeGlobal || freeSelf || Function('return this')();
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * A specialized version of `_.includes` for arrays without support for
|
---|
| 43 | * specifying an index to search from.
|
---|
| 44 | *
|
---|
| 45 | * @private
|
---|
| 46 | * @param {Array} [array] The array to inspect.
|
---|
| 47 | * @param {*} target The value to search for.
|
---|
| 48 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
---|
| 49 | */
|
---|
| 50 | function arrayIncludes(array, value) {
|
---|
| 51 | var length = array ? array.length : 0;
|
---|
| 52 | return !!length && baseIndexOf(array, value, 0) > -1;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * This function is like `arrayIncludes` except that it accepts a comparator.
|
---|
| 57 | *
|
---|
| 58 | * @private
|
---|
| 59 | * @param {Array} [array] The array to inspect.
|
---|
| 60 | * @param {*} target The value to search for.
|
---|
| 61 | * @param {Function} comparator The comparator invoked per element.
|
---|
| 62 | * @returns {boolean} Returns `true` if `target` is found, else `false`.
|
---|
| 63 | */
|
---|
| 64 | function arrayIncludesWith(array, value, comparator) {
|
---|
| 65 | var index = -1,
|
---|
| 66 | length = array ? array.length : 0;
|
---|
| 67 |
|
---|
| 68 | while (++index < length) {
|
---|
| 69 | if (comparator(value, array[index])) {
|
---|
| 70 | return true;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | return false;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
---|
| 78 | * support for iteratee shorthands.
|
---|
| 79 | *
|
---|
| 80 | * @private
|
---|
| 81 | * @param {Array} array The array to inspect.
|
---|
| 82 | * @param {Function} predicate The function invoked per iteration.
|
---|
| 83 | * @param {number} fromIndex The index to search from.
|
---|
| 84 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
---|
| 85 | * @returns {number} Returns the index of the matched value, else `-1`.
|
---|
| 86 | */
|
---|
| 87 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
---|
| 88 | var length = array.length,
|
---|
| 89 | index = fromIndex + (fromRight ? 1 : -1);
|
---|
| 90 |
|
---|
| 91 | while ((fromRight ? index-- : ++index < length)) {
|
---|
| 92 | if (predicate(array[index], index, array)) {
|
---|
| 93 | return index;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | return -1;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
|
---|
| 101 | *
|
---|
| 102 | * @private
|
---|
| 103 | * @param {Array} array The array to inspect.
|
---|
| 104 | * @param {*} value The value to search for.
|
---|
| 105 | * @param {number} fromIndex The index to search from.
|
---|
| 106 | * @returns {number} Returns the index of the matched value, else `-1`.
|
---|
| 107 | */
|
---|
| 108 | function baseIndexOf(array, value, fromIndex) {
|
---|
| 109 | if (value !== value) {
|
---|
| 110 | return baseFindIndex(array, baseIsNaN, fromIndex);
|
---|
| 111 | }
|
---|
| 112 | var index = fromIndex - 1,
|
---|
| 113 | length = array.length;
|
---|
| 114 |
|
---|
| 115 | while (++index < length) {
|
---|
| 116 | if (array[index] === value) {
|
---|
| 117 | return index;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | return -1;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /**
|
---|
| 124 | * The base implementation of `_.isNaN` without support for number objects.
|
---|
| 125 | *
|
---|
| 126 | * @private
|
---|
| 127 | * @param {*} value The value to check.
|
---|
| 128 | * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
---|
| 129 | */
|
---|
| 130 | function baseIsNaN(value) {
|
---|
| 131 | return value !== value;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /**
|
---|
| 135 | * Checks if a cache value for `key` exists.
|
---|
| 136 | *
|
---|
| 137 | * @private
|
---|
| 138 | * @param {Object} cache The cache to query.
|
---|
| 139 | * @param {string} key The key of the entry to check.
|
---|
| 140 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
---|
| 141 | */
|
---|
| 142 | function cacheHas(cache, key) {
|
---|
| 143 | return cache.has(key);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /**
|
---|
| 147 | * Gets the value at `key` of `object`.
|
---|
| 148 | *
|
---|
| 149 | * @private
|
---|
| 150 | * @param {Object} [object] The object to query.
|
---|
| 151 | * @param {string} key The key of the property to get.
|
---|
| 152 | * @returns {*} Returns the property value.
|
---|
| 153 | */
|
---|
| 154 | function getValue(object, key) {
|
---|
| 155 | return object == null ? undefined : object[key];
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | /**
|
---|
| 159 | * Checks if `value` is a host object in IE < 9.
|
---|
| 160 | *
|
---|
| 161 | * @private
|
---|
| 162 | * @param {*} value The value to check.
|
---|
| 163 | * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
|
---|
| 164 | */
|
---|
| 165 | function isHostObject(value) {
|
---|
| 166 | // Many host objects are `Object` objects that can coerce to strings
|
---|
| 167 | // despite having improperly defined `toString` methods.
|
---|
| 168 | var result = false;
|
---|
| 169 | if (value != null && typeof value.toString != 'function') {
|
---|
| 170 | try {
|
---|
| 171 | result = !!(value + '');
|
---|
| 172 | } catch (e) {}
|
---|
| 173 | }
|
---|
| 174 | return result;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | /**
|
---|
| 178 | * Converts `set` to an array of its values.
|
---|
| 179 | *
|
---|
| 180 | * @private
|
---|
| 181 | * @param {Object} set The set to convert.
|
---|
| 182 | * @returns {Array} Returns the values.
|
---|
| 183 | */
|
---|
| 184 | function setToArray(set) {
|
---|
| 185 | var index = -1,
|
---|
| 186 | result = Array(set.size);
|
---|
| 187 |
|
---|
| 188 | set.forEach(function(value) {
|
---|
| 189 | result[++index] = value;
|
---|
| 190 | });
|
---|
| 191 | return result;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | /** Used for built-in method references. */
|
---|
| 195 | var arrayProto = Array.prototype,
|
---|
| 196 | funcProto = Function.prototype,
|
---|
| 197 | objectProto = Object.prototype;
|
---|
| 198 |
|
---|
| 199 | /** Used to detect overreaching core-js shims. */
|
---|
| 200 | var coreJsData = root['__core-js_shared__'];
|
---|
| 201 |
|
---|
| 202 | /** Used to detect methods masquerading as native. */
|
---|
| 203 | var maskSrcKey = (function() {
|
---|
| 204 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
---|
| 205 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
---|
| 206 | }());
|
---|
| 207 |
|
---|
| 208 | /** Used to resolve the decompiled source of functions. */
|
---|
| 209 | var funcToString = funcProto.toString;
|
---|
| 210 |
|
---|
| 211 | /** Used to check objects for own properties. */
|
---|
| 212 | var hasOwnProperty = objectProto.hasOwnProperty;
|
---|
| 213 |
|
---|
| 214 | /**
|
---|
| 215 | * Used to resolve the
|
---|
| 216 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
---|
| 217 | * of values.
|
---|
| 218 | */
|
---|
| 219 | var objectToString = objectProto.toString;
|
---|
| 220 |
|
---|
| 221 | /** Used to detect if a method is native. */
|
---|
| 222 | var reIsNative = RegExp('^' +
|
---|
| 223 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
---|
| 224 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
---|
| 225 | );
|
---|
| 226 |
|
---|
| 227 | /** Built-in value references. */
|
---|
| 228 | var splice = arrayProto.splice;
|
---|
| 229 |
|
---|
| 230 | /* Built-in method references that are verified to be native. */
|
---|
| 231 | var Map = getNative(root, 'Map'),
|
---|
| 232 | Set = getNative(root, 'Set'),
|
---|
| 233 | nativeCreate = getNative(Object, 'create');
|
---|
| 234 |
|
---|
| 235 | /**
|
---|
| 236 | * Creates a hash object.
|
---|
| 237 | *
|
---|
| 238 | * @private
|
---|
| 239 | * @constructor
|
---|
| 240 | * @param {Array} [entries] The key-value pairs to cache.
|
---|
| 241 | */
|
---|
| 242 | function Hash(entries) {
|
---|
| 243 | var index = -1,
|
---|
| 244 | length = entries ? entries.length : 0;
|
---|
| 245 |
|
---|
| 246 | this.clear();
|
---|
| 247 | while (++index < length) {
|
---|
| 248 | var entry = entries[index];
|
---|
| 249 | this.set(entry[0], entry[1]);
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | /**
|
---|
| 254 | * Removes all key-value entries from the hash.
|
---|
| 255 | *
|
---|
| 256 | * @private
|
---|
| 257 | * @name clear
|
---|
| 258 | * @memberOf Hash
|
---|
| 259 | */
|
---|
| 260 | function hashClear() {
|
---|
| 261 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | /**
|
---|
| 265 | * Removes `key` and its value from the hash.
|
---|
| 266 | *
|
---|
| 267 | * @private
|
---|
| 268 | * @name delete
|
---|
| 269 | * @memberOf Hash
|
---|
| 270 | * @param {Object} hash The hash to modify.
|
---|
| 271 | * @param {string} key The key of the value to remove.
|
---|
| 272 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
---|
| 273 | */
|
---|
| 274 | function hashDelete(key) {
|
---|
| 275 | return this.has(key) && delete this.__data__[key];
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | /**
|
---|
| 279 | * Gets the hash value for `key`.
|
---|
| 280 | *
|
---|
| 281 | * @private
|
---|
| 282 | * @name get
|
---|
| 283 | * @memberOf Hash
|
---|
| 284 | * @param {string} key The key of the value to get.
|
---|
| 285 | * @returns {*} Returns the entry value.
|
---|
| 286 | */
|
---|
| 287 | function hashGet(key) {
|
---|
| 288 | var data = this.__data__;
|
---|
| 289 | if (nativeCreate) {
|
---|
| 290 | var result = data[key];
|
---|
| 291 | return result === HASH_UNDEFINED ? undefined : result;
|
---|
| 292 | }
|
---|
| 293 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | /**
|
---|
| 297 | * Checks if a hash value for `key` exists.
|
---|
| 298 | *
|
---|
| 299 | * @private
|
---|
| 300 | * @name has
|
---|
| 301 | * @memberOf Hash
|
---|
| 302 | * @param {string} key The key of the entry to check.
|
---|
| 303 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
---|
| 304 | */
|
---|
| 305 | function hashHas(key) {
|
---|
| 306 | var data = this.__data__;
|
---|
| 307 | return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /**
|
---|
| 311 | * Sets the hash `key` to `value`.
|
---|
| 312 | *
|
---|
| 313 | * @private
|
---|
| 314 | * @name set
|
---|
| 315 | * @memberOf Hash
|
---|
| 316 | * @param {string} key The key of the value to set.
|
---|
| 317 | * @param {*} value The value to set.
|
---|
| 318 | * @returns {Object} Returns the hash instance.
|
---|
| 319 | */
|
---|
| 320 | function hashSet(key, value) {
|
---|
| 321 | var data = this.__data__;
|
---|
| 322 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
---|
| 323 | return this;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | // Add methods to `Hash`.
|
---|
| 327 | Hash.prototype.clear = hashClear;
|
---|
| 328 | Hash.prototype['delete'] = hashDelete;
|
---|
| 329 | Hash.prototype.get = hashGet;
|
---|
| 330 | Hash.prototype.has = hashHas;
|
---|
| 331 | Hash.prototype.set = hashSet;
|
---|
| 332 |
|
---|
| 333 | /**
|
---|
| 334 | * Creates an list cache object.
|
---|
| 335 | *
|
---|
| 336 | * @private
|
---|
| 337 | * @constructor
|
---|
| 338 | * @param {Array} [entries] The key-value pairs to cache.
|
---|
| 339 | */
|
---|
| 340 | function ListCache(entries) {
|
---|
| 341 | var index = -1,
|
---|
| 342 | length = entries ? entries.length : 0;
|
---|
| 343 |
|
---|
| 344 | this.clear();
|
---|
| 345 | while (++index < length) {
|
---|
| 346 | var entry = entries[index];
|
---|
| 347 | this.set(entry[0], entry[1]);
|
---|
| 348 | }
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | /**
|
---|
| 352 | * Removes all key-value entries from the list cache.
|
---|
| 353 | *
|
---|
| 354 | * @private
|
---|
| 355 | * @name clear
|
---|
| 356 | * @memberOf ListCache
|
---|
| 357 | */
|
---|
| 358 | function listCacheClear() {
|
---|
| 359 | this.__data__ = [];
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | /**
|
---|
| 363 | * Removes `key` and its value from the list cache.
|
---|
| 364 | *
|
---|
| 365 | * @private
|
---|
| 366 | * @name delete
|
---|
| 367 | * @memberOf ListCache
|
---|
| 368 | * @param {string} key The key of the value to remove.
|
---|
| 369 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
---|
| 370 | */
|
---|
| 371 | function listCacheDelete(key) {
|
---|
| 372 | var data = this.__data__,
|
---|
| 373 | index = assocIndexOf(data, key);
|
---|
| 374 |
|
---|
| 375 | if (index < 0) {
|
---|
| 376 | return false;
|
---|
| 377 | }
|
---|
| 378 | var lastIndex = data.length - 1;
|
---|
| 379 | if (index == lastIndex) {
|
---|
| 380 | data.pop();
|
---|
| 381 | } else {
|
---|
| 382 | splice.call(data, index, 1);
|
---|
| 383 | }
|
---|
| 384 | return true;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | /**
|
---|
| 388 | * Gets the list cache value for `key`.
|
---|
| 389 | *
|
---|
| 390 | * @private
|
---|
| 391 | * @name get
|
---|
| 392 | * @memberOf ListCache
|
---|
| 393 | * @param {string} key The key of the value to get.
|
---|
| 394 | * @returns {*} Returns the entry value.
|
---|
| 395 | */
|
---|
| 396 | function listCacheGet(key) {
|
---|
| 397 | var data = this.__data__,
|
---|
| 398 | index = assocIndexOf(data, key);
|
---|
| 399 |
|
---|
| 400 | return index < 0 ? undefined : data[index][1];
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | /**
|
---|
| 404 | * Checks if a list cache value for `key` exists.
|
---|
| 405 | *
|
---|
| 406 | * @private
|
---|
| 407 | * @name has
|
---|
| 408 | * @memberOf ListCache
|
---|
| 409 | * @param {string} key The key of the entry to check.
|
---|
| 410 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
---|
| 411 | */
|
---|
| 412 | function listCacheHas(key) {
|
---|
| 413 | return assocIndexOf(this.__data__, key) > -1;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | /**
|
---|
| 417 | * Sets the list cache `key` to `value`.
|
---|
| 418 | *
|
---|
| 419 | * @private
|
---|
| 420 | * @name set
|
---|
| 421 | * @memberOf ListCache
|
---|
| 422 | * @param {string} key The key of the value to set.
|
---|
| 423 | * @param {*} value The value to set.
|
---|
| 424 | * @returns {Object} Returns the list cache instance.
|
---|
| 425 | */
|
---|
| 426 | function listCacheSet(key, value) {
|
---|
| 427 | var data = this.__data__,
|
---|
| 428 | index = assocIndexOf(data, key);
|
---|
| 429 |
|
---|
| 430 | if (index < 0) {
|
---|
| 431 | data.push([key, value]);
|
---|
| 432 | } else {
|
---|
| 433 | data[index][1] = value;
|
---|
| 434 | }
|
---|
| 435 | return this;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | // Add methods to `ListCache`.
|
---|
| 439 | ListCache.prototype.clear = listCacheClear;
|
---|
| 440 | ListCache.prototype['delete'] = listCacheDelete;
|
---|
| 441 | ListCache.prototype.get = listCacheGet;
|
---|
| 442 | ListCache.prototype.has = listCacheHas;
|
---|
| 443 | ListCache.prototype.set = listCacheSet;
|
---|
| 444 |
|
---|
| 445 | /**
|
---|
| 446 | * Creates a map cache object to store key-value pairs.
|
---|
| 447 | *
|
---|
| 448 | * @private
|
---|
| 449 | * @constructor
|
---|
| 450 | * @param {Array} [entries] The key-value pairs to cache.
|
---|
| 451 | */
|
---|
| 452 | function MapCache(entries) {
|
---|
| 453 | var index = -1,
|
---|
| 454 | length = entries ? entries.length : 0;
|
---|
| 455 |
|
---|
| 456 | this.clear();
|
---|
| 457 | while (++index < length) {
|
---|
| 458 | var entry = entries[index];
|
---|
| 459 | this.set(entry[0], entry[1]);
|
---|
| 460 | }
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | /**
|
---|
| 464 | * Removes all key-value entries from the map.
|
---|
| 465 | *
|
---|
| 466 | * @private
|
---|
| 467 | * @name clear
|
---|
| 468 | * @memberOf MapCache
|
---|
| 469 | */
|
---|
| 470 | function mapCacheClear() {
|
---|
| 471 | this.__data__ = {
|
---|
| 472 | 'hash': new Hash,
|
---|
| 473 | 'map': new (Map || ListCache),
|
---|
| 474 | 'string': new Hash
|
---|
| 475 | };
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | /**
|
---|
| 479 | * Removes `key` and its value from the map.
|
---|
| 480 | *
|
---|
| 481 | * @private
|
---|
| 482 | * @name delete
|
---|
| 483 | * @memberOf MapCache
|
---|
| 484 | * @param {string} key The key of the value to remove.
|
---|
| 485 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
---|
| 486 | */
|
---|
| 487 | function mapCacheDelete(key) {
|
---|
| 488 | return getMapData(this, key)['delete'](key);
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | /**
|
---|
| 492 | * Gets the map value for `key`.
|
---|
| 493 | *
|
---|
| 494 | * @private
|
---|
| 495 | * @name get
|
---|
| 496 | * @memberOf MapCache
|
---|
| 497 | * @param {string} key The key of the value to get.
|
---|
| 498 | * @returns {*} Returns the entry value.
|
---|
| 499 | */
|
---|
| 500 | function mapCacheGet(key) {
|
---|
| 501 | return getMapData(this, key).get(key);
|
---|
| 502 | }
|
---|
| 503 |
|
---|
| 504 | /**
|
---|
| 505 | * Checks if a map value for `key` exists.
|
---|
| 506 | *
|
---|
| 507 | * @private
|
---|
| 508 | * @name has
|
---|
| 509 | * @memberOf MapCache
|
---|
| 510 | * @param {string} key The key of the entry to check.
|
---|
| 511 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
---|
| 512 | */
|
---|
| 513 | function mapCacheHas(key) {
|
---|
| 514 | return getMapData(this, key).has(key);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | /**
|
---|
| 518 | * Sets the map `key` to `value`.
|
---|
| 519 | *
|
---|
| 520 | * @private
|
---|
| 521 | * @name set
|
---|
| 522 | * @memberOf MapCache
|
---|
| 523 | * @param {string} key The key of the value to set.
|
---|
| 524 | * @param {*} value The value to set.
|
---|
| 525 | * @returns {Object} Returns the map cache instance.
|
---|
| 526 | */
|
---|
| 527 | function mapCacheSet(key, value) {
|
---|
| 528 | getMapData(this, key).set(key, value);
|
---|
| 529 | return this;
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | // Add methods to `MapCache`.
|
---|
| 533 | MapCache.prototype.clear = mapCacheClear;
|
---|
| 534 | MapCache.prototype['delete'] = mapCacheDelete;
|
---|
| 535 | MapCache.prototype.get = mapCacheGet;
|
---|
| 536 | MapCache.prototype.has = mapCacheHas;
|
---|
| 537 | MapCache.prototype.set = mapCacheSet;
|
---|
| 538 |
|
---|
| 539 | /**
|
---|
| 540 | *
|
---|
| 541 | * Creates an array cache object to store unique values.
|
---|
| 542 | *
|
---|
| 543 | * @private
|
---|
| 544 | * @constructor
|
---|
| 545 | * @param {Array} [values] The values to cache.
|
---|
| 546 | */
|
---|
| 547 | function SetCache(values) {
|
---|
| 548 | var index = -1,
|
---|
| 549 | length = values ? values.length : 0;
|
---|
| 550 |
|
---|
| 551 | this.__data__ = new MapCache;
|
---|
| 552 | while (++index < length) {
|
---|
| 553 | this.add(values[index]);
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 | /**
|
---|
| 558 | * Adds `value` to the array cache.
|
---|
| 559 | *
|
---|
| 560 | * @private
|
---|
| 561 | * @name add
|
---|
| 562 | * @memberOf SetCache
|
---|
| 563 | * @alias push
|
---|
| 564 | * @param {*} value The value to cache.
|
---|
| 565 | * @returns {Object} Returns the cache instance.
|
---|
| 566 | */
|
---|
| 567 | function setCacheAdd(value) {
|
---|
| 568 | this.__data__.set(value, HASH_UNDEFINED);
|
---|
| 569 | return this;
|
---|
| 570 | }
|
---|
| 571 |
|
---|
| 572 | /**
|
---|
| 573 | * Checks if `value` is in the array cache.
|
---|
| 574 | *
|
---|
| 575 | * @private
|
---|
| 576 | * @name has
|
---|
| 577 | * @memberOf SetCache
|
---|
| 578 | * @param {*} value The value to search for.
|
---|
| 579 | * @returns {number} Returns `true` if `value` is found, else `false`.
|
---|
| 580 | */
|
---|
| 581 | function setCacheHas(value) {
|
---|
| 582 | return this.__data__.has(value);
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | // Add methods to `SetCache`.
|
---|
| 586 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
---|
| 587 | SetCache.prototype.has = setCacheHas;
|
---|
| 588 |
|
---|
| 589 | /**
|
---|
| 590 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
---|
| 591 | *
|
---|
| 592 | * @private
|
---|
| 593 | * @param {Array} array The array to inspect.
|
---|
| 594 | * @param {*} key The key to search for.
|
---|
| 595 | * @returns {number} Returns the index of the matched value, else `-1`.
|
---|
| 596 | */
|
---|
| 597 | function assocIndexOf(array, key) {
|
---|
| 598 | var length = array.length;
|
---|
| 599 | while (length--) {
|
---|
| 600 | if (eq(array[length][0], key)) {
|
---|
| 601 | return length;
|
---|
| 602 | }
|
---|
| 603 | }
|
---|
| 604 | return -1;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | /**
|
---|
| 608 | * The base implementation of `_.isNative` without bad shim checks.
|
---|
| 609 | *
|
---|
| 610 | * @private
|
---|
| 611 | * @param {*} value The value to check.
|
---|
| 612 | * @returns {boolean} Returns `true` if `value` is a native function,
|
---|
| 613 | * else `false`.
|
---|
| 614 | */
|
---|
| 615 | function baseIsNative(value) {
|
---|
| 616 | if (!isObject(value) || isMasked(value)) {
|
---|
| 617 | return false;
|
---|
| 618 | }
|
---|
| 619 | var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
---|
| 620 | return pattern.test(toSource(value));
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | /**
|
---|
| 624 | * The base implementation of `_.uniqBy` without support for iteratee shorthands.
|
---|
| 625 | *
|
---|
| 626 | * @private
|
---|
| 627 | * @param {Array} array The array to inspect.
|
---|
| 628 | * @param {Function} [iteratee] The iteratee invoked per element.
|
---|
| 629 | * @param {Function} [comparator] The comparator invoked per element.
|
---|
| 630 | * @returns {Array} Returns the new duplicate free array.
|
---|
| 631 | */
|
---|
| 632 | function baseUniq(array, iteratee, comparator) {
|
---|
| 633 | var index = -1,
|
---|
| 634 | includes = arrayIncludes,
|
---|
| 635 | length = array.length,
|
---|
| 636 | isCommon = true,
|
---|
| 637 | result = [],
|
---|
| 638 | seen = result;
|
---|
| 639 |
|
---|
| 640 | if (comparator) {
|
---|
| 641 | isCommon = false;
|
---|
| 642 | includes = arrayIncludesWith;
|
---|
| 643 | }
|
---|
| 644 | else if (length >= LARGE_ARRAY_SIZE) {
|
---|
| 645 | var set = iteratee ? null : createSet(array);
|
---|
| 646 | if (set) {
|
---|
| 647 | return setToArray(set);
|
---|
| 648 | }
|
---|
| 649 | isCommon = false;
|
---|
| 650 | includes = cacheHas;
|
---|
| 651 | seen = new SetCache;
|
---|
| 652 | }
|
---|
| 653 | else {
|
---|
| 654 | seen = iteratee ? [] : result;
|
---|
| 655 | }
|
---|
| 656 | outer:
|
---|
| 657 | while (++index < length) {
|
---|
| 658 | var value = array[index],
|
---|
| 659 | computed = iteratee ? iteratee(value) : value;
|
---|
| 660 |
|
---|
| 661 | value = (comparator || value !== 0) ? value : 0;
|
---|
| 662 | if (isCommon && computed === computed) {
|
---|
| 663 | var seenIndex = seen.length;
|
---|
| 664 | while (seenIndex--) {
|
---|
| 665 | if (seen[seenIndex] === computed) {
|
---|
| 666 | continue outer;
|
---|
| 667 | }
|
---|
| 668 | }
|
---|
| 669 | if (iteratee) {
|
---|
| 670 | seen.push(computed);
|
---|
| 671 | }
|
---|
| 672 | result.push(value);
|
---|
| 673 | }
|
---|
| 674 | else if (!includes(seen, computed, comparator)) {
|
---|
| 675 | if (seen !== result) {
|
---|
| 676 | seen.push(computed);
|
---|
| 677 | }
|
---|
| 678 | result.push(value);
|
---|
| 679 | }
|
---|
| 680 | }
|
---|
| 681 | return result;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | /**
|
---|
| 685 | * Creates a set object of `values`.
|
---|
| 686 | *
|
---|
| 687 | * @private
|
---|
| 688 | * @param {Array} values The values to add to the set.
|
---|
| 689 | * @returns {Object} Returns the new set.
|
---|
| 690 | */
|
---|
| 691 | var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
|
---|
| 692 | return new Set(values);
|
---|
| 693 | };
|
---|
| 694 |
|
---|
| 695 | /**
|
---|
| 696 | * Gets the data for `map`.
|
---|
| 697 | *
|
---|
| 698 | * @private
|
---|
| 699 | * @param {Object} map The map to query.
|
---|
| 700 | * @param {string} key The reference key.
|
---|
| 701 | * @returns {*} Returns the map data.
|
---|
| 702 | */
|
---|
| 703 | function getMapData(map, key) {
|
---|
| 704 | var data = map.__data__;
|
---|
| 705 | return isKeyable(key)
|
---|
| 706 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
---|
| 707 | : data.map;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
| 710 | /**
|
---|
| 711 | * Gets the native function at `key` of `object`.
|
---|
| 712 | *
|
---|
| 713 | * @private
|
---|
| 714 | * @param {Object} object The object to query.
|
---|
| 715 | * @param {string} key The key of the method to get.
|
---|
| 716 | * @returns {*} Returns the function if it's native, else `undefined`.
|
---|
| 717 | */
|
---|
| 718 | function getNative(object, key) {
|
---|
| 719 | var value = getValue(object, key);
|
---|
| 720 | return baseIsNative(value) ? value : undefined;
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | /**
|
---|
| 724 | * Checks if `value` is suitable for use as unique object key.
|
---|
| 725 | *
|
---|
| 726 | * @private
|
---|
| 727 | * @param {*} value The value to check.
|
---|
| 728 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
---|
| 729 | */
|
---|
| 730 | function isKeyable(value) {
|
---|
| 731 | var type = typeof value;
|
---|
| 732 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
---|
| 733 | ? (value !== '__proto__')
|
---|
| 734 | : (value === null);
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | /**
|
---|
| 738 | * Checks if `func` has its source masked.
|
---|
| 739 | *
|
---|
| 740 | * @private
|
---|
| 741 | * @param {Function} func The function to check.
|
---|
| 742 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
---|
| 743 | */
|
---|
| 744 | function isMasked(func) {
|
---|
| 745 | return !!maskSrcKey && (maskSrcKey in func);
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | /**
|
---|
| 749 | * Converts `func` to its source code.
|
---|
| 750 | *
|
---|
| 751 | * @private
|
---|
| 752 | * @param {Function} func The function to process.
|
---|
| 753 | * @returns {string} Returns the source code.
|
---|
| 754 | */
|
---|
| 755 | function toSource(func) {
|
---|
| 756 | if (func != null) {
|
---|
| 757 | try {
|
---|
| 758 | return funcToString.call(func);
|
---|
| 759 | } catch (e) {}
|
---|
| 760 | try {
|
---|
| 761 | return (func + '');
|
---|
| 762 | } catch (e) {}
|
---|
| 763 | }
|
---|
| 764 | return '';
|
---|
| 765 | }
|
---|
| 766 |
|
---|
| 767 | /**
|
---|
| 768 | * Creates a duplicate-free version of an array, using
|
---|
| 769 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
---|
| 770 | * for equality comparisons, in which only the first occurrence of each
|
---|
| 771 | * element is kept.
|
---|
| 772 | *
|
---|
| 773 | * @static
|
---|
| 774 | * @memberOf _
|
---|
| 775 | * @since 0.1.0
|
---|
| 776 | * @category Array
|
---|
| 777 | * @param {Array} array The array to inspect.
|
---|
| 778 | * @returns {Array} Returns the new duplicate free array.
|
---|
| 779 | * @example
|
---|
| 780 | *
|
---|
| 781 | * _.uniq([2, 1, 2]);
|
---|
| 782 | * // => [2, 1]
|
---|
| 783 | */
|
---|
| 784 | function uniq(array) {
|
---|
| 785 | return (array && array.length)
|
---|
| 786 | ? baseUniq(array)
|
---|
| 787 | : [];
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | /**
|
---|
| 791 | * Performs a
|
---|
| 792 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
---|
| 793 | * comparison between two values to determine if they are equivalent.
|
---|
| 794 | *
|
---|
| 795 | * @static
|
---|
| 796 | * @memberOf _
|
---|
| 797 | * @since 4.0.0
|
---|
| 798 | * @category Lang
|
---|
| 799 | * @param {*} value The value to compare.
|
---|
| 800 | * @param {*} other The other value to compare.
|
---|
| 801 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
---|
| 802 | * @example
|
---|
| 803 | *
|
---|
| 804 | * var object = { 'a': 1 };
|
---|
| 805 | * var other = { 'a': 1 };
|
---|
| 806 | *
|
---|
| 807 | * _.eq(object, object);
|
---|
| 808 | * // => true
|
---|
| 809 | *
|
---|
| 810 | * _.eq(object, other);
|
---|
| 811 | * // => false
|
---|
| 812 | *
|
---|
| 813 | * _.eq('a', 'a');
|
---|
| 814 | * // => true
|
---|
| 815 | *
|
---|
| 816 | * _.eq('a', Object('a'));
|
---|
| 817 | * // => false
|
---|
| 818 | *
|
---|
| 819 | * _.eq(NaN, NaN);
|
---|
| 820 | * // => true
|
---|
| 821 | */
|
---|
| 822 | function eq(value, other) {
|
---|
| 823 | return value === other || (value !== value && other !== other);
|
---|
| 824 | }
|
---|
| 825 |
|
---|
| 826 | /**
|
---|
| 827 | * Checks if `value` is classified as a `Function` object.
|
---|
| 828 | *
|
---|
| 829 | * @static
|
---|
| 830 | * @memberOf _
|
---|
| 831 | * @since 0.1.0
|
---|
| 832 | * @category Lang
|
---|
| 833 | * @param {*} value The value to check.
|
---|
| 834 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
---|
| 835 | * @example
|
---|
| 836 | *
|
---|
| 837 | * _.isFunction(_);
|
---|
| 838 | * // => true
|
---|
| 839 | *
|
---|
| 840 | * _.isFunction(/abc/);
|
---|
| 841 | * // => false
|
---|
| 842 | */
|
---|
| 843 | function isFunction(value) {
|
---|
| 844 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
---|
| 845 | // in Safari 8-9 which returns 'object' for typed array and other constructors.
|
---|
| 846 | var tag = isObject(value) ? objectToString.call(value) : '';
|
---|
| 847 | return tag == funcTag || tag == genTag;
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | /**
|
---|
| 851 | * Checks if `value` is the
|
---|
| 852 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
---|
| 853 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
---|
| 854 | *
|
---|
| 855 | * @static
|
---|
| 856 | * @memberOf _
|
---|
| 857 | * @since 0.1.0
|
---|
| 858 | * @category Lang
|
---|
| 859 | * @param {*} value The value to check.
|
---|
| 860 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
---|
| 861 | * @example
|
---|
| 862 | *
|
---|
| 863 | * _.isObject({});
|
---|
| 864 | * // => true
|
---|
| 865 | *
|
---|
| 866 | * _.isObject([1, 2, 3]);
|
---|
| 867 | * // => true
|
---|
| 868 | *
|
---|
| 869 | * _.isObject(_.noop);
|
---|
| 870 | * // => true
|
---|
| 871 | *
|
---|
| 872 | * _.isObject(null);
|
---|
| 873 | * // => false
|
---|
| 874 | */
|
---|
| 875 | function isObject(value) {
|
---|
| 876 | var type = typeof value;
|
---|
| 877 | return !!value && (type == 'object' || type == 'function');
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | /**
|
---|
| 881 | * This method returns `undefined`.
|
---|
| 882 | *
|
---|
| 883 | * @static
|
---|
| 884 | * @memberOf _
|
---|
| 885 | * @since 2.3.0
|
---|
| 886 | * @category Util
|
---|
| 887 | * @example
|
---|
| 888 | *
|
---|
| 889 | * _.times(2, _.noop);
|
---|
| 890 | * // => [undefined, undefined]
|
---|
| 891 | */
|
---|
| 892 | function noop() {
|
---|
| 893 | // No operation performed.
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | module.exports = uniq;
|
---|