forIn-9f737b26.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. 'use strict';
  7. const debounce = require('./debounce-94d2834e.js');
  8. /**
  9. * Checks if `value` is classified as an `Array` object.
  10. *
  11. * @static
  12. * @memberOf _
  13. * @since 0.1.0
  14. * @category Lang
  15. * @param {*} value The value to check.
  16. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  17. * @example
  18. *
  19. * _.isArray([1, 2, 3]);
  20. * // => true
  21. *
  22. * _.isArray(document.body.children);
  23. * // => false
  24. *
  25. * _.isArray('abc');
  26. * // => false
  27. *
  28. * _.isArray(_.noop);
  29. * // => false
  30. */
  31. var isArray = Array.isArray;
  32. /**
  33. * This method returns the first argument it receives.
  34. *
  35. * @static
  36. * @since 0.1.0
  37. * @memberOf _
  38. * @category Util
  39. * @param {*} value Any value.
  40. * @returns {*} Returns `value`.
  41. * @example
  42. *
  43. * var object = { 'a': 1 };
  44. *
  45. * console.log(_.identity(object) === object);
  46. * // => true
  47. */
  48. function identity(value) {
  49. return value;
  50. }
  51. /** `Object#toString` result references. */
  52. var asyncTag = '[object AsyncFunction]',
  53. funcTag$1 = '[object Function]',
  54. genTag = '[object GeneratorFunction]',
  55. proxyTag = '[object Proxy]';
  56. /**
  57. * Checks if `value` is classified as a `Function` object.
  58. *
  59. * @static
  60. * @memberOf _
  61. * @since 0.1.0
  62. * @category Lang
  63. * @param {*} value The value to check.
  64. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  65. * @example
  66. *
  67. * _.isFunction(_);
  68. * // => true
  69. *
  70. * _.isFunction(/abc/);
  71. * // => false
  72. */
  73. function isFunction(value) {
  74. if (!debounce.isObject(value)) {
  75. return false;
  76. }
  77. // The use of `Object#toString` avoids issues with the `typeof` operator
  78. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  79. var tag = debounce.baseGetTag(value);
  80. return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag;
  81. }
  82. /** Used as references for various `Number` constants. */
  83. var MAX_SAFE_INTEGER$1 = 9007199254740991;
  84. /** Used to detect unsigned integer values. */
  85. var reIsUint = /^(?:0|[1-9]\d*)$/;
  86. /**
  87. * Checks if `value` is a valid array-like index.
  88. *
  89. * @private
  90. * @param {*} value The value to check.
  91. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  92. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  93. */
  94. function isIndex(value, length) {
  95. var type = typeof value;
  96. length = length == null ? MAX_SAFE_INTEGER$1 : length;
  97. return !!length &&
  98. (type == 'number' ||
  99. (type != 'symbol' && reIsUint.test(value))) &&
  100. (value > -1 && value % 1 == 0 && value < length);
  101. }
  102. /** Used as references for various `Number` constants. */
  103. var MAX_SAFE_INTEGER = 9007199254740991;
  104. /**
  105. * Checks if `value` is a valid array-like length.
  106. *
  107. * **Note:** This method is loosely based on
  108. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  109. *
  110. * @static
  111. * @memberOf _
  112. * @since 4.0.0
  113. * @category Lang
  114. * @param {*} value The value to check.
  115. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  116. * @example
  117. *
  118. * _.isLength(3);
  119. * // => true
  120. *
  121. * _.isLength(Number.MIN_VALUE);
  122. * // => false
  123. *
  124. * _.isLength(Infinity);
  125. * // => false
  126. *
  127. * _.isLength('3');
  128. * // => false
  129. */
  130. function isLength(value) {
  131. return typeof value == 'number' &&
  132. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  133. }
  134. /**
  135. * Checks if `value` is array-like. A value is considered array-like if it's
  136. * not a function and has a `value.length` that's an integer greater than or
  137. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  138. *
  139. * @static
  140. * @memberOf _
  141. * @since 4.0.0
  142. * @category Lang
  143. * @param {*} value The value to check.
  144. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  145. * @example
  146. *
  147. * _.isArrayLike([1, 2, 3]);
  148. * // => true
  149. *
  150. * _.isArrayLike(document.body.children);
  151. * // => true
  152. *
  153. * _.isArrayLike('abc');
  154. * // => true
  155. *
  156. * _.isArrayLike(_.noop);
  157. * // => false
  158. */
  159. function isArrayLike(value) {
  160. return value != null && isLength(value.length) && !isFunction(value);
  161. }
  162. /** Used for built-in method references. */
  163. var objectProto$3 = Object.prototype;
  164. /**
  165. * Checks if `value` is likely a prototype object.
  166. *
  167. * @private
  168. * @param {*} value The value to check.
  169. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  170. */
  171. function isPrototype(value) {
  172. var Ctor = value && value.constructor,
  173. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$3;
  174. return value === proto;
  175. }
  176. /**
  177. * The base implementation of `_.times` without support for iteratee shorthands
  178. * or max array length checks.
  179. *
  180. * @private
  181. * @param {number} n The number of times to invoke `iteratee`.
  182. * @param {Function} iteratee The function invoked per iteration.
  183. * @returns {Array} Returns the array of results.
  184. */
  185. function baseTimes(n, iteratee) {
  186. var index = -1,
  187. result = Array(n);
  188. while (++index < n) {
  189. result[index] = iteratee(index);
  190. }
  191. return result;
  192. }
  193. /** `Object#toString` result references. */
  194. var argsTag$1 = '[object Arguments]';
  195. /**
  196. * The base implementation of `_.isArguments`.
  197. *
  198. * @private
  199. * @param {*} value The value to check.
  200. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  201. */
  202. function baseIsArguments(value) {
  203. return debounce.isObjectLike(value) && debounce.baseGetTag(value) == argsTag$1;
  204. }
  205. /** Used for built-in method references. */
  206. var objectProto$2 = Object.prototype;
  207. /** Used to check objects for own properties. */
  208. var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
  209. /** Built-in value references. */
  210. var propertyIsEnumerable = objectProto$2.propertyIsEnumerable;
  211. /**
  212. * Checks if `value` is likely an `arguments` object.
  213. *
  214. * @static
  215. * @memberOf _
  216. * @since 0.1.0
  217. * @category Lang
  218. * @param {*} value The value to check.
  219. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  220. * else `false`.
  221. * @example
  222. *
  223. * _.isArguments(function() { return arguments; }());
  224. * // => true
  225. *
  226. * _.isArguments([1, 2, 3]);
  227. * // => false
  228. */
  229. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  230. return debounce.isObjectLike(value) && hasOwnProperty$2.call(value, 'callee') &&
  231. !propertyIsEnumerable.call(value, 'callee');
  232. };
  233. /**
  234. * This method returns `false`.
  235. *
  236. * @static
  237. * @memberOf _
  238. * @since 4.13.0
  239. * @category Util
  240. * @returns {boolean} Returns `false`.
  241. * @example
  242. *
  243. * _.times(2, _.stubFalse);
  244. * // => [false, false]
  245. */
  246. function stubFalse() {
  247. return false;
  248. }
  249. /** Detect free variable `exports`. */
  250. var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
  251. /** Detect free variable `module`. */
  252. var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
  253. /** Detect the popular CommonJS extension `module.exports`. */
  254. var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
  255. /** Built-in value references. */
  256. var Buffer = moduleExports$1 ? debounce.root.Buffer : undefined;
  257. /* Built-in method references for those with the same name as other `lodash` methods. */
  258. var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
  259. /**
  260. * Checks if `value` is a buffer.
  261. *
  262. * @static
  263. * @memberOf _
  264. * @since 4.3.0
  265. * @category Lang
  266. * @param {*} value The value to check.
  267. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  268. * @example
  269. *
  270. * _.isBuffer(new Buffer(2));
  271. * // => true
  272. *
  273. * _.isBuffer(new Uint8Array(2));
  274. * // => false
  275. */
  276. var isBuffer = nativeIsBuffer || stubFalse;
  277. /** `Object#toString` result references. */
  278. var argsTag = '[object Arguments]',
  279. arrayTag = '[object Array]',
  280. boolTag = '[object Boolean]',
  281. dateTag = '[object Date]',
  282. errorTag = '[object Error]',
  283. funcTag = '[object Function]',
  284. mapTag = '[object Map]',
  285. numberTag = '[object Number]',
  286. objectTag = '[object Object]',
  287. regexpTag = '[object RegExp]',
  288. setTag = '[object Set]',
  289. stringTag = '[object String]',
  290. weakMapTag = '[object WeakMap]';
  291. var arrayBufferTag = '[object ArrayBuffer]',
  292. dataViewTag = '[object DataView]',
  293. float32Tag = '[object Float32Array]',
  294. float64Tag = '[object Float64Array]',
  295. int8Tag = '[object Int8Array]',
  296. int16Tag = '[object Int16Array]',
  297. int32Tag = '[object Int32Array]',
  298. uint8Tag = '[object Uint8Array]',
  299. uint8ClampedTag = '[object Uint8ClampedArray]',
  300. uint16Tag = '[object Uint16Array]',
  301. uint32Tag = '[object Uint32Array]';
  302. /** Used to identify `toStringTag` values of typed arrays. */
  303. var typedArrayTags = {};
  304. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  305. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  306. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  307. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  308. typedArrayTags[uint32Tag] = true;
  309. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  310. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  311. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  312. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  313. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  314. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  315. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  316. typedArrayTags[weakMapTag] = false;
  317. /**
  318. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  319. *
  320. * @private
  321. * @param {*} value The value to check.
  322. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  323. */
  324. function baseIsTypedArray(value) {
  325. return debounce.isObjectLike(value) &&
  326. isLength(value.length) && !!typedArrayTags[debounce.baseGetTag(value)];
  327. }
  328. /**
  329. * The base implementation of `_.unary` without support for storing metadata.
  330. *
  331. * @private
  332. * @param {Function} func The function to cap arguments for.
  333. * @returns {Function} Returns the new capped function.
  334. */
  335. function baseUnary(func) {
  336. return function(value) {
  337. return func(value);
  338. };
  339. }
  340. /** Detect free variable `exports`. */
  341. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  342. /** Detect free variable `module`. */
  343. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  344. /** Detect the popular CommonJS extension `module.exports`. */
  345. var moduleExports = freeModule && freeModule.exports === freeExports;
  346. /** Detect free variable `process` from Node.js. */
  347. var freeProcess = moduleExports && debounce.freeGlobal.process;
  348. /** Used to access faster Node.js helpers. */
  349. var nodeUtil = (function() {
  350. try {
  351. // Use `util.types` for Node.js 10+.
  352. var types = freeModule && freeModule.require && freeModule.require('util').types;
  353. if (types) {
  354. return types;
  355. }
  356. // Legacy `process.binding('util')` for Node.js < 10.
  357. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  358. } catch (e) {}
  359. }());
  360. /* Node.js helper references. */
  361. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  362. /**
  363. * Checks if `value` is classified as a typed array.
  364. *
  365. * @static
  366. * @memberOf _
  367. * @since 3.0.0
  368. * @category Lang
  369. * @param {*} value The value to check.
  370. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  371. * @example
  372. *
  373. * _.isTypedArray(new Uint8Array);
  374. * // => true
  375. *
  376. * _.isTypedArray([]);
  377. * // => false
  378. */
  379. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  380. /** Used for built-in method references. */
  381. var objectProto$1 = Object.prototype;
  382. /** Used to check objects for own properties. */
  383. var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
  384. /**
  385. * Creates an array of the enumerable property names of the array-like `value`.
  386. *
  387. * @private
  388. * @param {*} value The value to query.
  389. * @param {boolean} inherited Specify returning inherited property names.
  390. * @returns {Array} Returns the array of property names.
  391. */
  392. function arrayLikeKeys(value, inherited) {
  393. var isArr = isArray(value),
  394. isArg = !isArr && isArguments(value),
  395. isBuff = !isArr && !isArg && isBuffer(value),
  396. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  397. skipIndexes = isArr || isArg || isBuff || isType,
  398. result = skipIndexes ? baseTimes(value.length, String) : [],
  399. length = result.length;
  400. for (var key in value) {
  401. if ((inherited || hasOwnProperty$1.call(value, key)) &&
  402. !(skipIndexes && (
  403. // Safari 9 has enumerable `arguments.length` in strict mode.
  404. key == 'length' ||
  405. // Node.js 0.10 has enumerable non-index properties on buffers.
  406. (isBuff && (key == 'offset' || key == 'parent')) ||
  407. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  408. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  409. // Skip index properties.
  410. isIndex(key, length)
  411. ))) {
  412. result.push(key);
  413. }
  414. }
  415. return result;
  416. }
  417. /**
  418. * This function is like
  419. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  420. * except that it includes inherited enumerable properties.
  421. *
  422. * @private
  423. * @param {Object} object The object to query.
  424. * @returns {Array} Returns the array of property names.
  425. */
  426. function nativeKeysIn(object) {
  427. var result = [];
  428. if (object != null) {
  429. for (var key in Object(object)) {
  430. result.push(key);
  431. }
  432. }
  433. return result;
  434. }
  435. /** Used for built-in method references. */
  436. var objectProto = Object.prototype;
  437. /** Used to check objects for own properties. */
  438. var hasOwnProperty = objectProto.hasOwnProperty;
  439. /**
  440. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  441. *
  442. * @private
  443. * @param {Object} object The object to query.
  444. * @returns {Array} Returns the array of property names.
  445. */
  446. function baseKeysIn(object) {
  447. if (!debounce.isObject(object)) {
  448. return nativeKeysIn(object);
  449. }
  450. var isProto = isPrototype(object),
  451. result = [];
  452. for (var key in object) {
  453. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  454. result.push(key);
  455. }
  456. }
  457. return result;
  458. }
  459. /**
  460. * Creates an array of the own and inherited enumerable property names of `object`.
  461. *
  462. * **Note:** Non-object values are coerced to objects.
  463. *
  464. * @static
  465. * @memberOf _
  466. * @since 3.0.0
  467. * @category Object
  468. * @param {Object} object The object to query.
  469. * @returns {Array} Returns the array of property names.
  470. * @example
  471. *
  472. * function Foo() {
  473. * this.a = 1;
  474. * this.b = 2;
  475. * }
  476. *
  477. * Foo.prototype.c = 3;
  478. *
  479. * _.keysIn(new Foo);
  480. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  481. */
  482. function keysIn(object) {
  483. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  484. }
  485. /**
  486. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  487. *
  488. * @private
  489. * @param {boolean} [fromRight] Specify iterating from right to left.
  490. * @returns {Function} Returns the new base function.
  491. */
  492. function createBaseFor(fromRight) {
  493. return function(object, iteratee, keysFunc) {
  494. var index = -1,
  495. iterable = Object(object),
  496. props = keysFunc(object),
  497. length = props.length;
  498. while (length--) {
  499. var key = props[fromRight ? length : ++index];
  500. if (iteratee(iterable[key], key, iterable) === false) {
  501. break;
  502. }
  503. }
  504. return object;
  505. };
  506. }
  507. /**
  508. * The base implementation of `baseForOwn` which iterates over `object`
  509. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  510. * Iteratee functions may exit iteration early by explicitly returning `false`.
  511. *
  512. * @private
  513. * @param {Object} object The object to iterate over.
  514. * @param {Function} iteratee The function invoked per iteration.
  515. * @param {Function} keysFunc The function to get the keys of `object`.
  516. * @returns {Object} Returns `object`.
  517. */
  518. var baseFor = createBaseFor();
  519. /**
  520. * Casts `value` to `identity` if it's not a function.
  521. *
  522. * @private
  523. * @param {*} value The value to inspect.
  524. * @returns {Function} Returns cast function.
  525. */
  526. function castFunction(value) {
  527. return typeof value == 'function' ? value : identity;
  528. }
  529. /**
  530. * Iterates over own and inherited enumerable string keyed properties of an
  531. * object and invokes `iteratee` for each property. The iteratee is invoked
  532. * with three arguments: (value, key, object). Iteratee functions may exit
  533. * iteration early by explicitly returning `false`.
  534. *
  535. * @static
  536. * @memberOf _
  537. * @since 0.3.0
  538. * @category Object
  539. * @param {Object} object The object to iterate over.
  540. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  541. * @returns {Object} Returns `object`.
  542. * @see _.forInRight
  543. * @example
  544. *
  545. * function Foo() {
  546. * this.a = 1;
  547. * this.b = 2;
  548. * }
  549. *
  550. * Foo.prototype.c = 3;
  551. *
  552. * _.forIn(new Foo, function(value, key) {
  553. * console.log(key);
  554. * });
  555. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  556. */
  557. function forIn(object, iteratee) {
  558. return object == null
  559. ? object
  560. : baseFor(object, castFunction(iteratee), keysIn);
  561. }
  562. exports.forIn = forIn;
  563. exports.isArray = isArray;