You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19440 lines
596 KiB

2 months ago
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  40. /******/ }
  41. /******/ };
  42. /******/
  43. /******/ // define __esModule on exports
  44. /******/ __webpack_require__.r = function(exports) {
  45. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  46. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  47. /******/ }
  48. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  49. /******/ };
  50. /******/
  51. /******/ // create a fake namespace object
  52. /******/ // mode & 1: value is a module id, require it
  53. /******/ // mode & 2: merge all properties of value into the ns
  54. /******/ // mode & 4: return value when already ns object
  55. /******/ // mode & 8|1: behave like require
  56. /******/ __webpack_require__.t = function(value, mode) {
  57. /******/ if(mode & 1) value = __webpack_require__(value);
  58. /******/ if(mode & 8) return value;
  59. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  60. /******/ var ns = Object.create(null);
  61. /******/ __webpack_require__.r(ns);
  62. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  63. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  64. /******/ return ns;
  65. /******/ };
  66. /******/
  67. /******/ // getDefaultExport function for compatibility with non-harmony modules
  68. /******/ __webpack_require__.n = function(module) {
  69. /******/ var getter = module && module.__esModule ?
  70. /******/ function getDefault() { return module['default']; } :
  71. /******/ function getModuleExports() { return module; };
  72. /******/ __webpack_require__.d(getter, 'a', getter);
  73. /******/ return getter;
  74. /******/ };
  75. /******/
  76. /******/ // Object.prototype.hasOwnProperty.call
  77. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  78. /******/
  79. /******/ // __webpack_public_path__
  80. /******/ __webpack_require__.p = "/";
  81. /******/
  82. /******/
  83. /******/ // Load entry module and return exports
  84. /******/ return __webpack_require__(__webpack_require__.s = 0);
  85. /******/ })
  86. /************************************************************************/
  87. /******/ ({
  88. /***/ "./node_modules/axios/index.js":
  89. /*!*************************************!*\
  90. !*** ./node_modules/axios/index.js ***!
  91. \*************************************/
  92. /*! no static exports found */
  93. /***/ (function(module, exports, __webpack_require__) {
  94. module.exports = __webpack_require__(/*! ./lib/axios */ "./node_modules/axios/lib/axios.js");
  95. /***/ }),
  96. /***/ "./node_modules/axios/lib/adapters/xhr.js":
  97. /*!************************************************!*\
  98. !*** ./node_modules/axios/lib/adapters/xhr.js ***!
  99. \************************************************/
  100. /*! no static exports found */
  101. /***/ (function(module, exports, __webpack_require__) {
  102. "use strict";
  103. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  104. var settle = __webpack_require__(/*! ./../core/settle */ "./node_modules/axios/lib/core/settle.js");
  105. var buildURL = __webpack_require__(/*! ./../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  106. var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./node_modules/axios/lib/core/buildFullPath.js");
  107. var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./node_modules/axios/lib/helpers/parseHeaders.js");
  108. var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./node_modules/axios/lib/helpers/isURLSameOrigin.js");
  109. var createError = __webpack_require__(/*! ../core/createError */ "./node_modules/axios/lib/core/createError.js");
  110. module.exports = function xhrAdapter(config) {
  111. return new Promise(function dispatchXhrRequest(resolve, reject) {
  112. var requestData = config.data;
  113. var requestHeaders = config.headers;
  114. if (utils.isFormData(requestData)) {
  115. delete requestHeaders['Content-Type']; // Let the browser set it
  116. }
  117. var request = new XMLHttpRequest();
  118. // HTTP basic authentication
  119. if (config.auth) {
  120. var username = config.auth.username || '';
  121. var password = config.auth.password || '';
  122. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  123. }
  124. var fullPath = buildFullPath(config.baseURL, config.url);
  125. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  126. // Set the request timeout in MS
  127. request.timeout = config.timeout;
  128. // Listen for ready state
  129. request.onreadystatechange = function handleLoad() {
  130. if (!request || request.readyState !== 4) {
  131. return;
  132. }
  133. // The request errored out and we didn't get a response, this will be
  134. // handled by onerror instead
  135. // With one exception: request that using file: protocol, most browsers
  136. // will return status as 0 even though it's a successful request
  137. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  138. return;
  139. }
  140. // Prepare the response
  141. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  142. var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
  143. var response = {
  144. data: responseData,
  145. status: request.status,
  146. statusText: request.statusText,
  147. headers: responseHeaders,
  148. config: config,
  149. request: request
  150. };
  151. settle(resolve, reject, response);
  152. // Clean up request
  153. request = null;
  154. };
  155. // Handle browser request cancellation (as opposed to a manual cancellation)
  156. request.onabort = function handleAbort() {
  157. if (!request) {
  158. return;
  159. }
  160. reject(createError('Request aborted', config, 'ECONNABORTED', request));
  161. // Clean up request
  162. request = null;
  163. };
  164. // Handle low level network errors
  165. request.onerror = function handleError() {
  166. // Real errors are hidden from us by the browser
  167. // onerror should only fire if it's a network error
  168. reject(createError('Network Error', config, null, request));
  169. // Clean up request
  170. request = null;
  171. };
  172. // Handle timeout
  173. request.ontimeout = function handleTimeout() {
  174. var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
  175. if (config.timeoutErrorMessage) {
  176. timeoutErrorMessage = config.timeoutErrorMessage;
  177. }
  178. reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
  179. request));
  180. // Clean up request
  181. request = null;
  182. };
  183. // Add xsrf header
  184. // This is only done if running in a standard browser environment.
  185. // Specifically not if we're in a web worker, or react-native.
  186. if (utils.isStandardBrowserEnv()) {
  187. var cookies = __webpack_require__(/*! ./../helpers/cookies */ "./node_modules/axios/lib/helpers/cookies.js");
  188. // Add xsrf header
  189. var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
  190. cookies.read(config.xsrfCookieName) :
  191. undefined;
  192. if (xsrfValue) {
  193. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  194. }
  195. }
  196. // Add headers to the request
  197. if ('setRequestHeader' in request) {
  198. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  199. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  200. // Remove Content-Type if data is undefined
  201. delete requestHeaders[key];
  202. } else {
  203. // Otherwise add header to the request
  204. request.setRequestHeader(key, val);
  205. }
  206. });
  207. }
  208. // Add withCredentials to request if needed
  209. if (!utils.isUndefined(config.withCredentials)) {
  210. request.withCredentials = !!config.withCredentials;
  211. }
  212. // Add responseType to request if needed
  213. if (config.responseType) {
  214. try {
  215. request.responseType = config.responseType;
  216. } catch (e) {
  217. // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
  218. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
  219. if (config.responseType !== 'json') {
  220. throw e;
  221. }
  222. }
  223. }
  224. // Handle progress if needed
  225. if (typeof config.onDownloadProgress === 'function') {
  226. request.addEventListener('progress', config.onDownloadProgress);
  227. }
  228. // Not all browsers support upload events
  229. if (typeof config.onUploadProgress === 'function' && request.upload) {
  230. request.upload.addEventListener('progress', config.onUploadProgress);
  231. }
  232. if (config.cancelToken) {
  233. // Handle cancellation
  234. config.cancelToken.promise.then(function onCanceled(cancel) {
  235. if (!request) {
  236. return;
  237. }
  238. request.abort();
  239. reject(cancel);
  240. // Clean up request
  241. request = null;
  242. });
  243. }
  244. if (requestData === undefined) {
  245. requestData = null;
  246. }
  247. // Send the request
  248. request.send(requestData);
  249. });
  250. };
  251. /***/ }),
  252. /***/ "./node_modules/axios/lib/axios.js":
  253. /*!*****************************************!*\
  254. !*** ./node_modules/axios/lib/axios.js ***!
  255. \*****************************************/
  256. /*! no static exports found */
  257. /***/ (function(module, exports, __webpack_require__) {
  258. "use strict";
  259. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  260. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  261. var Axios = __webpack_require__(/*! ./core/Axios */ "./node_modules/axios/lib/core/Axios.js");
  262. var mergeConfig = __webpack_require__(/*! ./core/mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  263. var defaults = __webpack_require__(/*! ./defaults */ "./node_modules/axios/lib/defaults.js");
  264. /**
  265. * Create an instance of Axios
  266. *
  267. * @param {Object} defaultConfig The default config for the instance
  268. * @return {Axios} A new instance of Axios
  269. */
  270. function createInstance(defaultConfig) {
  271. var context = new Axios(defaultConfig);
  272. var instance = bind(Axios.prototype.request, context);
  273. // Copy axios.prototype to instance
  274. utils.extend(instance, Axios.prototype, context);
  275. // Copy context to instance
  276. utils.extend(instance, context);
  277. return instance;
  278. }
  279. // Create the default instance to be exported
  280. var axios = createInstance(defaults);
  281. // Expose Axios class to allow class inheritance
  282. axios.Axios = Axios;
  283. // Factory for creating new instances
  284. axios.create = function create(instanceConfig) {
  285. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  286. };
  287. // Expose Cancel & CancelToken
  288. axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  289. axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./node_modules/axios/lib/cancel/CancelToken.js");
  290. axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  291. // Expose all/spread
  292. axios.all = function all(promises) {
  293. return Promise.all(promises);
  294. };
  295. axios.spread = __webpack_require__(/*! ./helpers/spread */ "./node_modules/axios/lib/helpers/spread.js");
  296. module.exports = axios;
  297. // Allow use of default import syntax in TypeScript
  298. module.exports.default = axios;
  299. /***/ }),
  300. /***/ "./node_modules/axios/lib/cancel/Cancel.js":
  301. /*!*************************************************!*\
  302. !*** ./node_modules/axios/lib/cancel/Cancel.js ***!
  303. \*************************************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports, __webpack_require__) {
  306. "use strict";
  307. /**
  308. * A `Cancel` is an object that is thrown when an operation is canceled.
  309. *
  310. * @class
  311. * @param {string=} message The message.
  312. */
  313. function Cancel(message) {
  314. this.message = message;
  315. }
  316. Cancel.prototype.toString = function toString() {
  317. return 'Cancel' + (this.message ? ': ' + this.message : '');
  318. };
  319. Cancel.prototype.__CANCEL__ = true;
  320. module.exports = Cancel;
  321. /***/ }),
  322. /***/ "./node_modules/axios/lib/cancel/CancelToken.js":
  323. /*!******************************************************!*\
  324. !*** ./node_modules/axios/lib/cancel/CancelToken.js ***!
  325. \******************************************************/
  326. /*! no static exports found */
  327. /***/ (function(module, exports, __webpack_require__) {
  328. "use strict";
  329. var Cancel = __webpack_require__(/*! ./Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  330. /**
  331. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  332. *
  333. * @class
  334. * @param {Function} executor The executor function.
  335. */
  336. function CancelToken(executor) {
  337. if (typeof executor !== 'function') {
  338. throw new TypeError('executor must be a function.');
  339. }
  340. var resolvePromise;
  341. this.promise = new Promise(function promiseExecutor(resolve) {
  342. resolvePromise = resolve;
  343. });
  344. var token = this;
  345. executor(function cancel(message) {
  346. if (token.reason) {
  347. // Cancellation has already been requested
  348. return;
  349. }
  350. token.reason = new Cancel(message);
  351. resolvePromise(token.reason);
  352. });
  353. }
  354. /**
  355. * Throws a `Cancel` if cancellation has been requested.
  356. */
  357. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  358. if (this.reason) {
  359. throw this.reason;
  360. }
  361. };
  362. /**
  363. * Returns an object that contains a new `CancelToken` and a function that, when called,
  364. * cancels the `CancelToken`.
  365. */
  366. CancelToken.source = function source() {
  367. var cancel;
  368. var token = new CancelToken(function executor(c) {
  369. cancel = c;
  370. });
  371. return {
  372. token: token,
  373. cancel: cancel
  374. };
  375. };
  376. module.exports = CancelToken;
  377. /***/ }),
  378. /***/ "./node_modules/axios/lib/cancel/isCancel.js":
  379. /*!***************************************************!*\
  380. !*** ./node_modules/axios/lib/cancel/isCancel.js ***!
  381. \***************************************************/
  382. /*! no static exports found */
  383. /***/ (function(module, exports, __webpack_require__) {
  384. "use strict";
  385. module.exports = function isCancel(value) {
  386. return !!(value && value.__CANCEL__);
  387. };
  388. /***/ }),
  389. /***/ "./node_modules/axios/lib/core/Axios.js":
  390. /*!**********************************************!*\
  391. !*** ./node_modules/axios/lib/core/Axios.js ***!
  392. \**********************************************/
  393. /*! no static exports found */
  394. /***/ (function(module, exports, __webpack_require__) {
  395. "use strict";
  396. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  397. var buildURL = __webpack_require__(/*! ../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  398. var InterceptorManager = __webpack_require__(/*! ./InterceptorManager */ "./node_modules/axios/lib/core/InterceptorManager.js");
  399. var dispatchRequest = __webpack_require__(/*! ./dispatchRequest */ "./node_modules/axios/lib/core/dispatchRequest.js");
  400. var mergeConfig = __webpack_require__(/*! ./mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  401. /**
  402. * Create a new instance of Axios
  403. *
  404. * @param {Object} instanceConfig The default config for the instance
  405. */
  406. function Axios(instanceConfig) {
  407. this.defaults = instanceConfig;
  408. this.interceptors = {
  409. request: new InterceptorManager(),
  410. response: new InterceptorManager()
  411. };
  412. }
  413. /**
  414. * Dispatch a request
  415. *
  416. * @param {Object} config The config specific for this request (merged with this.defaults)
  417. */
  418. Axios.prototype.request = function request(config) {
  419. /*eslint no-param-reassign:0*/
  420. // Allow for axios('example/url'[, config]) a la fetch API
  421. if (typeof config === 'string') {
  422. config = arguments[1] || {};
  423. config.url = arguments[0];
  424. } else {
  425. config = config || {};
  426. }
  427. config = mergeConfig(this.defaults, config);
  428. // Set config.method
  429. if (config.method) {
  430. config.method = config.method.toLowerCase();
  431. } else if (this.defaults.method) {
  432. config.method = this.defaults.method.toLowerCase();
  433. } else {
  434. config.method = 'get';
  435. }
  436. // Hook up interceptors middleware
  437. var chain = [dispatchRequest, undefined];
  438. var promise = Promise.resolve(config);
  439. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  440. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  441. });
  442. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  443. chain.push(interceptor.fulfilled, interceptor.rejected);
  444. });
  445. while (chain.length) {
  446. promise = promise.then(chain.shift(), chain.shift());
  447. }
  448. return promise;
  449. };
  450. Axios.prototype.getUri = function getUri(config) {
  451. config = mergeConfig(this.defaults, config);
  452. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  453. };
  454. // Provide aliases for supported request methods
  455. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  456. /*eslint func-names:0*/
  457. Axios.prototype[method] = function(url, config) {
  458. return this.request(utils.merge(config || {}, {
  459. method: method,
  460. url: url
  461. }));
  462. };
  463. });
  464. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  465. /*eslint func-names:0*/
  466. Axios.prototype[method] = function(url, data, config) {
  467. return this.request(utils.merge(config || {}, {
  468. method: method,
  469. url: url,
  470. data: data
  471. }));
  472. };
  473. });
  474. module.exports = Axios;
  475. /***/ }),
  476. /***/ "./node_modules/axios/lib/core/InterceptorManager.js":
  477. /*!***********************************************************!*\
  478. !*** ./node_modules/axios/lib/core/InterceptorManager.js ***!
  479. \***********************************************************/
  480. /*! no static exports found */
  481. /***/ (function(module, exports, __webpack_require__) {
  482. "use strict";
  483. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  484. function InterceptorManager() {
  485. this.handlers = [];
  486. }
  487. /**
  488. * Add a new interceptor to the stack
  489. *
  490. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  491. * @param {Function} rejected The function to handle `reject` for a `Promise`
  492. *
  493. * @return {Number} An ID used to remove interceptor later
  494. */
  495. InterceptorManager.prototype.use = function use(fulfilled, rejected) {
  496. this.handlers.push({
  497. fulfilled: fulfilled,
  498. rejected: rejected
  499. });
  500. return this.handlers.length - 1;
  501. };
  502. /**
  503. * Remove an interceptor from the stack
  504. *
  505. * @param {Number} id The ID that was returned by `use`
  506. */
  507. InterceptorManager.prototype.eject = function eject(id) {
  508. if (this.handlers[id]) {
  509. this.handlers[id] = null;
  510. }
  511. };
  512. /**
  513. * Iterate over all the registered interceptors
  514. *
  515. * This method is particularly useful for skipping over any
  516. * interceptors that may have become `null` calling `eject`.
  517. *
  518. * @param {Function} fn The function to call for each interceptor
  519. */
  520. InterceptorManager.prototype.forEach = function forEach(fn) {
  521. utils.forEach(this.handlers, function forEachHandler(h) {
  522. if (h !== null) {
  523. fn(h);
  524. }
  525. });
  526. };
  527. module.exports = InterceptorManager;
  528. /***/ }),
  529. /***/ "./node_modules/axios/lib/core/buildFullPath.js":
  530. /*!******************************************************!*\
  531. !*** ./node_modules/axios/lib/core/buildFullPath.js ***!
  532. \******************************************************/
  533. /*! no static exports found */
  534. /***/ (function(module, exports, __webpack_require__) {
  535. "use strict";
  536. var isAbsoluteURL = __webpack_require__(/*! ../helpers/isAbsoluteURL */ "./node_modules/axios/lib/helpers/isAbsoluteURL.js");
  537. var combineURLs = __webpack_require__(/*! ../helpers/combineURLs */ "./node_modules/axios/lib/helpers/combineURLs.js");
  538. /**
  539. * Creates a new URL by combining the baseURL with the requestedURL,
  540. * only when the requestedURL is not already an absolute URL.
  541. * If the requestURL is absolute, this function returns the requestedURL untouched.
  542. *
  543. * @param {string} baseURL The base URL
  544. * @param {string} requestedURL Absolute or relative URL to combine
  545. * @returns {string} The combined full path
  546. */
  547. module.exports = function buildFullPath(baseURL, requestedURL) {
  548. if (baseURL && !isAbsoluteURL(requestedURL)) {
  549. return combineURLs(baseURL, requestedURL);
  550. }
  551. return requestedURL;
  552. };
  553. /***/ }),
  554. /***/ "./node_modules/axios/lib/core/createError.js":
  555. /*!****************************************************!*\
  556. !*** ./node_modules/axios/lib/core/createError.js ***!
  557. \****************************************************/
  558. /*! no static exports found */
  559. /***/ (function(module, exports, __webpack_require__) {
  560. "use strict";
  561. var enhanceError = __webpack_require__(/*! ./enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  562. /**
  563. * Create an Error with the specified message, config, error code, request and response.
  564. *
  565. * @param {string} message The error message.
  566. * @param {Object} config The config.
  567. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  568. * @param {Object} [request] The request.
  569. * @param {Object} [response] The response.
  570. * @returns {Error} The created error.
  571. */
  572. module.exports = function createError(message, config, code, request, response) {
  573. var error = new Error(message);
  574. return enhanceError(error, config, code, request, response);
  575. };
  576. /***/ }),
  577. /***/ "./node_modules/axios/lib/core/dispatchRequest.js":
  578. /*!********************************************************!*\
  579. !*** ./node_modules/axios/lib/core/dispatchRequest.js ***!
  580. \********************************************************/
  581. /*! no static exports found */
  582. /***/ (function(module, exports, __webpack_require__) {
  583. "use strict";
  584. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  585. var transformData = __webpack_require__(/*! ./transformData */ "./node_modules/axios/lib/core/transformData.js");
  586. var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  587. var defaults = __webpack_require__(/*! ../defaults */ "./node_modules/axios/lib/defaults.js");
  588. /**
  589. * Throws a `Cancel` if cancellation has been requested.
  590. */
  591. function throwIfCancellationRequested(config) {
  592. if (config.cancelToken) {
  593. config.cancelToken.throwIfRequested();
  594. }
  595. }
  596. /**
  597. * Dispatch a request to the server using the configured adapter.
  598. *
  599. * @param {object} config The config that is to be used for the request
  600. * @returns {Promise} The Promise to be fulfilled
  601. */
  602. module.exports = function dispatchRequest(config) {
  603. throwIfCancellationRequested(config);
  604. // Ensure headers exist
  605. config.headers = config.headers || {};
  606. // Transform request data
  607. config.data = transformData(
  608. config.data,
  609. config.headers,
  610. config.transformRequest
  611. );
  612. // Flatten headers
  613. config.headers = utils.merge(
  614. config.headers.common || {},
  615. config.headers[config.method] || {},
  616. config.headers
  617. );
  618. utils.forEach(
  619. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  620. function cleanHeaderConfig(method) {
  621. delete config.headers[method];
  622. }
  623. );
  624. var adapter = config.adapter || defaults.adapter;
  625. return adapter(config).then(function onAdapterResolution(response) {
  626. throwIfCancellationRequested(config);
  627. // Transform response data
  628. response.data = transformData(
  629. response.data,
  630. response.headers,
  631. config.transformResponse
  632. );
  633. return response;
  634. }, function onAdapterRejection(reason) {
  635. if (!isCancel(reason)) {
  636. throwIfCancellationRequested(config);
  637. // Transform response data
  638. if (reason && reason.response) {
  639. reason.response.data = transformData(
  640. reason.response.data,
  641. reason.response.headers,
  642. config.transformResponse
  643. );
  644. }
  645. }
  646. return Promise.reject(reason);
  647. });
  648. };
  649. /***/ }),
  650. /***/ "./node_modules/axios/lib/core/enhanceError.js":
  651. /*!*****************************************************!*\
  652. !*** ./node_modules/axios/lib/core/enhanceError.js ***!
  653. \*****************************************************/
  654. /*! no static exports found */
  655. /***/ (function(module, exports, __webpack_require__) {
  656. "use strict";
  657. /**
  658. * Update an Error with the specified config, error code, and response.
  659. *
  660. * @param {Error} error The error to update.
  661. * @param {Object} config The config.
  662. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  663. * @param {Object} [request] The request.
  664. * @param {Object} [response] The response.
  665. * @returns {Error} The error.
  666. */
  667. module.exports = function enhanceError(error, config, code, request, response) {
  668. error.config = config;
  669. if (code) {
  670. error.code = code;
  671. }
  672. error.request = request;
  673. error.response = response;
  674. error.isAxiosError = true;
  675. error.toJSON = function() {
  676. return {
  677. // Standard
  678. message: this.message,
  679. name: this.name,
  680. // Microsoft
  681. description: this.description,
  682. number: this.number,
  683. // Mozilla
  684. fileName: this.fileName,
  685. lineNumber: this.lineNumber,
  686. columnNumber: this.columnNumber,
  687. stack: this.stack,
  688. // Axios
  689. config: this.config,
  690. code: this.code
  691. };
  692. };
  693. return error;
  694. };
  695. /***/ }),
  696. /***/ "./node_modules/axios/lib/core/mergeConfig.js":
  697. /*!****************************************************!*\
  698. !*** ./node_modules/axios/lib/core/mergeConfig.js ***!
  699. \****************************************************/
  700. /*! no static exports found */
  701. /***/ (function(module, exports, __webpack_require__) {
  702. "use strict";
  703. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  704. /**
  705. * Config-specific merge-function which creates a new config-object
  706. * by merging two configuration objects together.
  707. *
  708. * @param {Object} config1
  709. * @param {Object} config2
  710. * @returns {Object} New object resulting from merging config2 to config1
  711. */
  712. module.exports = function mergeConfig(config1, config2) {
  713. // eslint-disable-next-line no-param-reassign
  714. config2 = config2 || {};
  715. var config = {};
  716. var valueFromConfig2Keys = ['url', 'method', 'params', 'data'];
  717. var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy'];
  718. var defaultToConfig2Keys = [
  719. 'baseURL', 'url', 'transformRequest', 'transformResponse', 'paramsSerializer',
  720. 'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
  721. 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress',
  722. 'maxContentLength', 'validateStatus', 'maxRedirects', 'httpAgent',
  723. 'httpsAgent', 'cancelToken', 'socketPath'
  724. ];
  725. utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
  726. if (typeof config2[prop] !== 'undefined') {
  727. config[prop] = config2[prop];
  728. }
  729. });
  730. utils.forEach(mergeDeepPropertiesKeys, function mergeDeepProperties(prop) {
  731. if (utils.isObject(config2[prop])) {
  732. config[prop] = utils.deepMerge(config1[prop], config2[prop]);
  733. } else if (typeof config2[prop] !== 'undefined') {
  734. config[prop] = config2[prop];
  735. } else if (utils.isObject(config1[prop])) {
  736. config[prop] = utils.deepMerge(config1[prop]);
  737. } else if (typeof config1[prop] !== 'undefined') {
  738. config[prop] = config1[prop];
  739. }
  740. });
  741. utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
  742. if (typeof config2[prop] !== 'undefined') {
  743. config[prop] = config2[prop];
  744. } else if (typeof config1[prop] !== 'undefined') {
  745. config[prop] = config1[prop];
  746. }
  747. });
  748. var axiosKeys = valueFromConfig2Keys
  749. .concat(mergeDeepPropertiesKeys)
  750. .concat(defaultToConfig2Keys);
  751. var otherKeys = Object
  752. .keys(config2)
  753. .filter(function filterAxiosKeys(key) {
  754. return axiosKeys.indexOf(key) === -1;
  755. });
  756. utils.forEach(otherKeys, function otherKeysDefaultToConfig2(prop) {
  757. if (typeof config2[prop] !== 'undefined') {
  758. config[prop] = config2[prop];
  759. } else if (typeof config1[prop] !== 'undefined') {
  760. config[prop] = config1[prop];
  761. }
  762. });
  763. return config;
  764. };
  765. /***/ }),
  766. /***/ "./node_modules/axios/lib/core/settle.js":
  767. /*!***********************************************!*\
  768. !*** ./node_modules/axios/lib/core/settle.js ***!
  769. \***********************************************/
  770. /*! no static exports found */
  771. /***/ (function(module, exports, __webpack_require__) {
  772. "use strict";
  773. var createError = __webpack_require__(/*! ./createError */ "./node_modules/axios/lib/core/createError.js");
  774. /**
  775. * Resolve or reject a Promise based on response status.
  776. *
  777. * @param {Function} resolve A function that resolves the promise.
  778. * @param {Function} reject A function that rejects the promise.
  779. * @param {object} response The response.
  780. */
  781. module.exports = function settle(resolve, reject, response) {
  782. var validateStatus = response.config.validateStatus;
  783. if (!validateStatus || validateStatus(response.status)) {
  784. resolve(response);
  785. } else {
  786. reject(createError(
  787. 'Request failed with status code ' + response.status,
  788. response.config,
  789. null,
  790. response.request,
  791. response
  792. ));
  793. }
  794. };
  795. /***/ }),
  796. /***/ "./node_modules/axios/lib/core/transformData.js":
  797. /*!******************************************************!*\
  798. !*** ./node_modules/axios/lib/core/transformData.js ***!
  799. \******************************************************/
  800. /*! no static exports found */
  801. /***/ (function(module, exports, __webpack_require__) {
  802. "use strict";
  803. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  804. /**
  805. * Transform the data for a request or a response
  806. *
  807. * @param {Object|String} data The data to be transformed
  808. * @param {Array} headers The headers for the request or response
  809. * @param {Array|Function} fns A single function or Array of functions
  810. * @returns {*} The resulting transformed data
  811. */
  812. module.exports = function transformData(data, headers, fns) {
  813. /*eslint no-param-reassign:0*/
  814. utils.forEach(fns, function transform(fn) {
  815. data = fn(data, headers);
  816. });
  817. return data;
  818. };
  819. /***/ }),
  820. /***/ "./node_modules/axios/lib/defaults.js":
  821. /*!********************************************!*\
  822. !*** ./node_modules/axios/lib/defaults.js ***!
  823. \********************************************/
  824. /*! no static exports found */
  825. /***/ (function(module, exports, __webpack_require__) {
  826. "use strict";
  827. /* WEBPACK VAR INJECTION */(function(process) {
  828. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  829. var normalizeHeaderName = __webpack_require__(/*! ./helpers/normalizeHeaderName */ "./node_modules/axios/lib/helpers/normalizeHeaderName.js");
  830. var DEFAULT_CONTENT_TYPE = {
  831. 'Content-Type': 'application/x-www-form-urlencoded'
  832. };
  833. function setContentTypeIfUnset(headers, value) {
  834. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  835. headers['Content-Type'] = value;
  836. }
  837. }
  838. function getDefaultAdapter() {
  839. var adapter;
  840. if (typeof XMLHttpRequest !== 'undefined') {
  841. // For browsers use XHR adapter
  842. adapter = __webpack_require__(/*! ./adapters/xhr */ "./node_modules/axios/lib/adapters/xhr.js");
  843. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  844. // For node use HTTP adapter
  845. adapter = __webpack_require__(/*! ./adapters/http */ "./node_modules/axios/lib/adapters/xhr.js");
  846. }
  847. return adapter;
  848. }
  849. var defaults = {
  850. adapter: getDefaultAdapter(),
  851. transformRequest: [function transformRequest(data, headers) {
  852. normalizeHeaderName(headers, 'Accept');
  853. normalizeHeaderName(headers, 'Content-Type');
  854. if (utils.isFormData(data) ||
  855. utils.isArrayBuffer(data) ||
  856. utils.isBuffer(data) ||
  857. utils.isStream(data) ||
  858. utils.isFile(data) ||
  859. utils.isBlob(data)
  860. ) {
  861. return data;
  862. }
  863. if (utils.isArrayBufferView(data)) {
  864. return data.buffer;
  865. }
  866. if (utils.isURLSearchParams(data)) {
  867. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  868. return data.toString();
  869. }
  870. if (utils.isObject(data)) {
  871. setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
  872. return JSON.stringify(data);
  873. }
  874. return data;
  875. }],
  876. transformResponse: [function transformResponse(data) {
  877. /*eslint no-param-reassign:0*/
  878. if (typeof data === 'string') {
  879. try {
  880. data = JSON.parse(data);
  881. } catch (e) { /* Ignore */ }
  882. }
  883. return data;
  884. }],
  885. /**
  886. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  887. * timeout is not created.
  888. */
  889. timeout: 0,
  890. xsrfCookieName: 'XSRF-TOKEN',
  891. xsrfHeaderName: 'X-XSRF-TOKEN',
  892. maxContentLength: -1,
  893. validateStatus: function validateStatus(status) {
  894. return status >= 200 && status < 300;
  895. }
  896. };
  897. defaults.headers = {
  898. common: {
  899. 'Accept': 'application/json, text/plain, */*'
  900. }
  901. };
  902. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  903. defaults.headers[method] = {};
  904. });
  905. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  906. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  907. });
  908. module.exports = defaults;
  909. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js")))
  910. /***/ }),
  911. /***/ "./node_modules/axios/lib/helpers/bind.js":
  912. /*!************************************************!*\
  913. !*** ./node_modules/axios/lib/helpers/bind.js ***!
  914. \************************************************/
  915. /*! no static exports found */
  916. /***/ (function(module, exports, __webpack_require__) {
  917. "use strict";
  918. module.exports = function bind(fn, thisArg) {
  919. return function wrap() {
  920. var args = new Array(arguments.length);
  921. for (var i = 0; i < args.length; i++) {
  922. args[i] = arguments[i];
  923. }
  924. return fn.apply(thisArg, args);
  925. };
  926. };
  927. /***/ }),
  928. /***/ "./node_modules/axios/lib/helpers/buildURL.js":
  929. /*!****************************************************!*\
  930. !*** ./node_modules/axios/lib/helpers/buildURL.js ***!
  931. \****************************************************/
  932. /*! no static exports found */
  933. /***/ (function(module, exports, __webpack_require__) {
  934. "use strict";
  935. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  936. function encode(val) {
  937. return encodeURIComponent(val).
  938. replace(/%40/gi, '@').
  939. replace(/%3A/gi, ':').
  940. replace(/%24/g, '$').
  941. replace(/%2C/gi, ',').
  942. replace(/%20/g, '+').
  943. replace(/%5B/gi, '[').
  944. replace(/%5D/gi, ']');
  945. }
  946. /**
  947. * Build a URL by appending params to the end
  948. *
  949. * @param {string} url The base of the url (e.g., http://www.google.com)
  950. * @param {object} [params] The params to be appended
  951. * @returns {string} The formatted url
  952. */
  953. module.exports = function buildURL(url, params, paramsSerializer) {
  954. /*eslint no-param-reassign:0*/
  955. if (!params) {
  956. return url;
  957. }
  958. var serializedParams;
  959. if (paramsSerializer) {
  960. serializedParams = paramsSerializer(params);
  961. } else if (utils.isURLSearchParams(params)) {
  962. serializedParams = params.toString();
  963. } else {
  964. var parts = [];
  965. utils.forEach(params, function serialize(val, key) {
  966. if (val === null || typeof val === 'undefined') {
  967. return;
  968. }
  969. if (utils.isArray(val)) {
  970. key = key + '[]';
  971. } else {
  972. val = [val];
  973. }
  974. utils.forEach(val, function parseValue(v) {
  975. if (utils.isDate(v)) {
  976. v = v.toISOString();
  977. } else if (utils.isObject(v)) {
  978. v = JSON.stringify(v);
  979. }
  980. parts.push(encode(key) + '=' + encode(v));
  981. });
  982. });
  983. serializedParams = parts.join('&');
  984. }
  985. if (serializedParams) {
  986. var hashmarkIndex = url.indexOf('#');
  987. if (hashmarkIndex !== -1) {
  988. url = url.slice(0, hashmarkIndex);
  989. }
  990. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  991. }
  992. return url;
  993. };
  994. /***/ }),
  995. /***/ "./node_modules/axios/lib/helpers/combineURLs.js":
  996. /*!*******************************************************!*\
  997. !*** ./node_modules/axios/lib/helpers/combineURLs.js ***!
  998. \*******************************************************/
  999. /*! no static exports found */
  1000. /***/ (function(module, exports, __webpack_require__) {
  1001. "use strict";
  1002. /**
  1003. * Creates a new URL by combining the specified URLs
  1004. *
  1005. * @param {string} baseURL The base URL
  1006. * @param {string} relativeURL The relative URL
  1007. * @returns {string} The combined URL
  1008. */
  1009. module.exports = function combineURLs(baseURL, relativeURL) {
  1010. return relativeURL
  1011. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  1012. : baseURL;
  1013. };
  1014. /***/ }),
  1015. /***/ "./node_modules/axios/lib/helpers/cookies.js":
  1016. /*!***************************************************!*\
  1017. !*** ./node_modules/axios/lib/helpers/cookies.js ***!
  1018. \***************************************************/
  1019. /*! no static exports found */
  1020. /***/ (function(module, exports, __webpack_require__) {
  1021. "use strict";
  1022. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1023. module.exports = (
  1024. utils.isStandardBrowserEnv() ?
  1025. // Standard browser envs support document.cookie
  1026. (function standardBrowserEnv() {
  1027. return {
  1028. write: function write(name, value, expires, path, domain, secure) {
  1029. var cookie = [];
  1030. cookie.push(name + '=' + encodeURIComponent(value));
  1031. if (utils.isNumber(expires)) {
  1032. cookie.push('expires=' + new Date(expires).toGMTString());
  1033. }
  1034. if (utils.isString(path)) {
  1035. cookie.push('path=' + path);
  1036. }
  1037. if (utils.isString(domain)) {
  1038. cookie.push('domain=' + domain);
  1039. }
  1040. if (secure === true) {
  1041. cookie.push('secure');
  1042. }
  1043. document.cookie = cookie.join('; ');
  1044. },
  1045. read: function read(name) {
  1046. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  1047. return (match ? decodeURIComponent(match[3]) : null);
  1048. },
  1049. remove: function remove(name) {
  1050. this.write(name, '', Date.now() - 86400000);
  1051. }
  1052. };
  1053. })() :
  1054. // Non standard browser env (web workers, react-native) lack needed support.
  1055. (function nonStandardBrowserEnv() {
  1056. return {
  1057. write: function write() {},
  1058. read: function read() { return null; },
  1059. remove: function remove() {}
  1060. };
  1061. })()
  1062. );
  1063. /***/ }),
  1064. /***/ "./node_modules/axios/lib/helpers/isAbsoluteURL.js":
  1065. /*!*********************************************************!*\
  1066. !*** ./node_modules/axios/lib/helpers/isAbsoluteURL.js ***!
  1067. \*********************************************************/
  1068. /*! no static exports found */
  1069. /***/ (function(module, exports, __webpack_require__) {
  1070. "use strict";
  1071. /**
  1072. * Determines whether the specified URL is absolute
  1073. *
  1074. * @param {string} url The URL to test
  1075. * @returns {boolean} True if the specified URL is absolute, otherwise false
  1076. */
  1077. module.exports = function isAbsoluteURL(url) {
  1078. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  1079. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  1080. // by any combination of letters, digits, plus, period, or hyphen.
  1081. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  1082. };
  1083. /***/ }),
  1084. /***/ "./node_modules/axios/lib/helpers/isURLSameOrigin.js":
  1085. /*!***********************************************************!*\
  1086. !*** ./node_modules/axios/lib/helpers/isURLSameOrigin.js ***!
  1087. \***********************************************************/
  1088. /*! no static exports found */
  1089. /***/ (function(module, exports, __webpack_require__) {
  1090. "use strict";
  1091. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1092. module.exports = (
  1093. utils.isStandardBrowserEnv() ?
  1094. // Standard browser envs have full support of the APIs needed to test
  1095. // whether the request URL is of the same origin as current location.
  1096. (function standardBrowserEnv() {
  1097. var msie = /(msie|trident)/i.test(navigator.userAgent);
  1098. var urlParsingNode = document.createElement('a');
  1099. var originURL;
  1100. /**
  1101. * Parse a URL to discover it's components
  1102. *
  1103. * @param {String} url The URL to be parsed
  1104. * @returns {Object}
  1105. */
  1106. function resolveURL(url) {
  1107. var href = url;
  1108. if (msie) {
  1109. // IE needs attribute set twice to normalize properties
  1110. urlParsingNode.setAttribute('href', href);
  1111. href = urlParsingNode.href;
  1112. }
  1113. urlParsingNode.setAttribute('href', href);
  1114. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  1115. return {
  1116. href: urlParsingNode.href,
  1117. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  1118. host: urlParsingNode.host,
  1119. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  1120. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  1121. hostname: urlParsingNode.hostname,
  1122. port: urlParsingNode.port,
  1123. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  1124. urlParsingNode.pathname :
  1125. '/' + urlParsingNode.pathname
  1126. };
  1127. }
  1128. originURL = resolveURL(window.location.href);
  1129. /**
  1130. * Determine if a URL shares the same origin as the current location
  1131. *
  1132. * @param {String} requestURL The URL to test
  1133. * @returns {boolean} True if URL shares the same origin, otherwise false
  1134. */
  1135. return function isURLSameOrigin(requestURL) {
  1136. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  1137. return (parsed.protocol === originURL.protocol &&
  1138. parsed.host === originURL.host);
  1139. };
  1140. })() :
  1141. // Non standard browser envs (web workers, react-native) lack needed support.
  1142. (function nonStandardBrowserEnv() {
  1143. return function isURLSameOrigin() {
  1144. return true;
  1145. };
  1146. })()
  1147. );
  1148. /***/ }),
  1149. /***/ "./node_modules/axios/lib/helpers/normalizeHeaderName.js":
  1150. /*!***************************************************************!*\
  1151. !*** ./node_modules/axios/lib/helpers/normalizeHeaderName.js ***!
  1152. \***************************************************************/
  1153. /*! no static exports found */
  1154. /***/ (function(module, exports, __webpack_require__) {
  1155. "use strict";
  1156. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  1157. module.exports = function normalizeHeaderName(headers, normalizedName) {
  1158. utils.forEach(headers, function processHeader(value, name) {
  1159. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  1160. headers[normalizedName] = value;
  1161. delete headers[name];
  1162. }
  1163. });
  1164. };
  1165. /***/ }),
  1166. /***/ "./node_modules/axios/lib/helpers/parseHeaders.js":
  1167. /*!********************************************************!*\
  1168. !*** ./node_modules/axios/lib/helpers/parseHeaders.js ***!
  1169. \********************************************************/
  1170. /*! no static exports found */
  1171. /***/ (function(module, exports, __webpack_require__) {
  1172. "use strict";
  1173. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1174. // Headers whose duplicates are ignored by node
  1175. // c.f. https://nodejs.org/api/http.html#http_message_headers
  1176. var ignoreDuplicateOf = [
  1177. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  1178. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  1179. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  1180. 'referer', 'retry-after', 'user-agent'
  1181. ];
  1182. /**
  1183. * Parse headers into an object
  1184. *
  1185. * ```
  1186. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  1187. * Content-Type: application/json
  1188. * Connection: keep-alive
  1189. * Transfer-Encoding: chunked
  1190. * ```
  1191. *
  1192. * @param {String} headers Headers needing to be parsed
  1193. * @returns {Object} Headers parsed into an object
  1194. */
  1195. module.exports = function parseHeaders(headers) {
  1196. var parsed = {};
  1197. var key;
  1198. var val;
  1199. var i;
  1200. if (!headers) { return parsed; }
  1201. utils.forEach(headers.split('\n'), function parser(line) {
  1202. i = line.indexOf(':');
  1203. key = utils.trim(line.substr(0, i)).toLowerCase();
  1204. val = utils.trim(line.substr(i + 1));
  1205. if (key) {
  1206. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  1207. return;
  1208. }
  1209. if (key === 'set-cookie') {
  1210. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  1211. } else {
  1212. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  1213. }
  1214. }
  1215. });
  1216. return parsed;
  1217. };
  1218. /***/ }),
  1219. /***/ "./node_modules/axios/lib/helpers/spread.js":
  1220. /*!**************************************************!*\
  1221. !*** ./node_modules/axios/lib/helpers/spread.js ***!
  1222. \**************************************************/
  1223. /*! no static exports found */
  1224. /***/ (function(module, exports, __webpack_require__) {
  1225. "use strict";
  1226. /**
  1227. * Syntactic sugar for invoking a function and expanding an array for arguments.
  1228. *
  1229. * Common use case would be to use `Function.prototype.apply`.
  1230. *
  1231. * ```js
  1232. * function f(x, y, z) {}
  1233. * var args = [1, 2, 3];
  1234. * f.apply(null, args);
  1235. * ```
  1236. *
  1237. * With `spread` this example can be re-written.
  1238. *
  1239. * ```js
  1240. * spread(function(x, y, z) {})([1, 2, 3]);
  1241. * ```
  1242. *
  1243. * @param {Function} callback
  1244. * @returns {Function}
  1245. */
  1246. module.exports = function spread(callback) {
  1247. return function wrap(arr) {
  1248. return callback.apply(null, arr);
  1249. };
  1250. };
  1251. /***/ }),
  1252. /***/ "./node_modules/axios/lib/utils.js":
  1253. /*!*****************************************!*\
  1254. !*** ./node_modules/axios/lib/utils.js ***!
  1255. \*****************************************/
  1256. /*! no static exports found */
  1257. /***/ (function(module, exports, __webpack_require__) {
  1258. "use strict";
  1259. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  1260. /*global toString:true*/
  1261. // utils is a library of generic helper functions non-specific to axios
  1262. var toString = Object.prototype.toString;
  1263. /**
  1264. * Determine if a value is an Array
  1265. *
  1266. * @param {Object} val The value to test
  1267. * @returns {boolean} True if value is an Array, otherwise false
  1268. */
  1269. function isArray(val) {
  1270. return toString.call(val) === '[object Array]';
  1271. }
  1272. /**
  1273. * Determine if a value is undefined
  1274. *
  1275. * @param {Object} val The value to test
  1276. * @returns {boolean} True if the value is undefined, otherwise false
  1277. */
  1278. function isUndefined(val) {
  1279. return typeof val === 'undefined';
  1280. }
  1281. /**
  1282. * Determine if a value is a Buffer
  1283. *
  1284. * @param {Object} val The value to test
  1285. * @returns {boolean} True if value is a Buffer, otherwise false
  1286. */
  1287. function isBuffer(val) {
  1288. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  1289. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  1290. }
  1291. /**
  1292. * Determine if a value is an ArrayBuffer
  1293. *
  1294. * @param {Object} val The value to test
  1295. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  1296. */
  1297. function isArrayBuffer(val) {
  1298. return toString.call(val) === '[object ArrayBuffer]';
  1299. }
  1300. /**
  1301. * Determine if a value is a FormData
  1302. *
  1303. * @param {Object} val The value to test
  1304. * @returns {boolean} True if value is an FormData, otherwise false
  1305. */
  1306. function isFormData(val) {
  1307. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  1308. }
  1309. /**
  1310. * Determine if a value is a view on an ArrayBuffer
  1311. *
  1312. * @param {Object} val The value to test
  1313. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  1314. */
  1315. function isArrayBufferView(val) {
  1316. var result;
  1317. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  1318. result = ArrayBuffer.isView(val);
  1319. } else {
  1320. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  1321. }
  1322. return result;
  1323. }
  1324. /**
  1325. * Determine if a value is a String
  1326. *
  1327. * @param {Object} val The value to test
  1328. * @returns {boolean} True if value is a String, otherwise false
  1329. */
  1330. function isString(val) {
  1331. return typeof val === 'string';
  1332. }
  1333. /**
  1334. * Determine if a value is a Number
  1335. *
  1336. * @param {Object} val The value to test
  1337. * @returns {boolean} True if value is a Number, otherwise false
  1338. */
  1339. function isNumber(val) {
  1340. return typeof val === 'number';
  1341. }
  1342. /**
  1343. * Determine if a value is an Object
  1344. *
  1345. * @param {Object} val The value to test
  1346. * @returns {boolean} True if value is an Object, otherwise false
  1347. */
  1348. function isObject(val) {
  1349. return val !== null && typeof val === 'object';
  1350. }
  1351. /**
  1352. * Determine if a value is a Date
  1353. *
  1354. * @param {Object} val The value to test
  1355. * @returns {boolean} True if value is a Date, otherwise false
  1356. */
  1357. function isDate(val) {
  1358. return toString.call(val) === '[object Date]';
  1359. }
  1360. /**
  1361. * Determine if a value is a File
  1362. *
  1363. * @param {Object} val The value to test
  1364. * @returns {boolean} True if value is a File, otherwise false
  1365. */
  1366. function isFile(val) {
  1367. return toString.call(val) === '[object File]';
  1368. }
  1369. /**
  1370. * Determine if a value is a Blob
  1371. *
  1372. * @param {Object} val The value to test
  1373. * @returns {boolean} True if value is a Blob, otherwise false
  1374. */
  1375. function isBlob(val) {
  1376. return toString.call(val) === '[object Blob]';
  1377. }
  1378. /**
  1379. * Determine if a value is a Function
  1380. *
  1381. * @param {Object} val The value to test
  1382. * @returns {boolean} True if value is a Function, otherwise false
  1383. */
  1384. function isFunction(val) {
  1385. return toString.call(val) === '[object Function]';
  1386. }
  1387. /**
  1388. * Determine if a value is a Stream
  1389. *
  1390. * @param {Object} val The value to test
  1391. * @returns {boolean} True if value is a Stream, otherwise false
  1392. */
  1393. function isStream(val) {
  1394. return isObject(val) && isFunction(val.pipe);
  1395. }
  1396. /**
  1397. * Determine if a value is a URLSearchParams object
  1398. *
  1399. * @param {Object} val The value to test
  1400. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  1401. */
  1402. function isURLSearchParams(val) {
  1403. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  1404. }
  1405. /**
  1406. * Trim excess whitespace off the beginning and end of a string
  1407. *
  1408. * @param {String} str The String to trim
  1409. * @returns {String} The String freed of excess whitespace
  1410. */
  1411. function trim(str) {
  1412. return str.replace(/^\s*/, '').replace(/\s*$/, '');
  1413. }
  1414. /**
  1415. * Determine if we're running in a standard browser environment
  1416. *
  1417. * This allows axios to run in a web worker, and react-native.
  1418. * Both environments support XMLHttpRequest, but not fully standard globals.
  1419. *
  1420. * web workers:
  1421. * typeof window -> undefined
  1422. * typeof document -> undefined
  1423. *
  1424. * react-native:
  1425. * navigator.product -> 'ReactNative'
  1426. * nativescript
  1427. * navigator.product -> 'NativeScript' or 'NS'
  1428. */
  1429. function isStandardBrowserEnv() {
  1430. if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
  1431. navigator.product === 'NativeScript' ||
  1432. navigator.product === 'NS')) {
  1433. return false;
  1434. }
  1435. return (
  1436. typeof window !== 'undefined' &&
  1437. typeof document !== 'undefined'
  1438. );
  1439. }
  1440. /**
  1441. * Iterate over an Array or an Object invoking a function for each item.
  1442. *
  1443. * If `obj` is an Array callback will be called passing
  1444. * the value, index, and complete array for each item.
  1445. *
  1446. * If 'obj' is an Object callback will be called passing
  1447. * the value, key, and complete object for each property.
  1448. *
  1449. * @param {Object|Array} obj The object to iterate
  1450. * @param {Function} fn The callback to invoke for each item
  1451. */
  1452. function forEach(obj, fn) {
  1453. // Don't bother if no value provided
  1454. if (obj === null || typeof obj === 'undefined') {
  1455. return;
  1456. }
  1457. // Force an array if not already something iterable
  1458. if (typeof obj !== 'object') {
  1459. /*eslint no-param-reassign:0*/
  1460. obj = [obj];
  1461. }
  1462. if (isArray(obj)) {
  1463. // Iterate over array values
  1464. for (var i = 0, l = obj.length; i < l; i++) {
  1465. fn.call(null, obj[i], i, obj);
  1466. }
  1467. } else {
  1468. // Iterate over object keys
  1469. for (var key in obj) {
  1470. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  1471. fn.call(null, obj[key], key, obj);
  1472. }
  1473. }
  1474. }
  1475. }
  1476. /**
  1477. * Accepts varargs expecting each argument to be an object, then
  1478. * immutably merges the properties of each object and returns result.
  1479. *
  1480. * When multiple objects contain the same key the later object in
  1481. * the arguments list will take precedence.
  1482. *
  1483. * Example:
  1484. *
  1485. * ```js
  1486. * var result = merge({foo: 123}, {foo: 456});
  1487. * console.log(result.foo); // outputs 456
  1488. * ```
  1489. *
  1490. * @param {Object} obj1 Object to merge
  1491. * @returns {Object} Result of all merge properties
  1492. */
  1493. function merge(/* obj1, obj2, obj3, ... */) {
  1494. var result = {};
  1495. function assignValue(val, key) {
  1496. if (typeof result[key] === 'object' && typeof val === 'object') {
  1497. result[key] = merge(result[key], val);
  1498. } else {
  1499. result[key] = val;
  1500. }
  1501. }
  1502. for (var i = 0, l = arguments.length; i < l; i++) {
  1503. forEach(arguments[i], assignValue);
  1504. }
  1505. return result;
  1506. }
  1507. /**
  1508. * Function equal to merge with the difference being that no reference
  1509. * to original objects is kept.
  1510. *
  1511. * @see merge
  1512. * @param {Object} obj1 Object to merge
  1513. * @returns {Object} Result of all merge properties
  1514. */
  1515. function deepMerge(/* obj1, obj2, obj3, ... */) {
  1516. var result = {};
  1517. function assignValue(val, key) {
  1518. if (typeof result[key] === 'object' && typeof val === 'object') {
  1519. result[key] = deepMerge(result[key], val);
  1520. } else if (typeof val === 'object') {
  1521. result[key] = deepMerge({}, val);
  1522. } else {
  1523. result[key] = val;
  1524. }
  1525. }
  1526. for (var i = 0, l = arguments.length; i < l; i++) {
  1527. forEach(arguments[i], assignValue);
  1528. }
  1529. return result;
  1530. }
  1531. /**
  1532. * Extends object a by mutably adding to it the properties of object b.
  1533. *
  1534. * @param {Object} a The object to be extended
  1535. * @param {Object} b The object to copy properties from
  1536. * @param {Object} thisArg The object to bind function to
  1537. * @return {Object} The resulting value of object a
  1538. */
  1539. function extend(a, b, thisArg) {
  1540. forEach(b, function assignValue(val, key) {
  1541. if (thisArg && typeof val === 'function') {
  1542. a[key] = bind(val, thisArg);
  1543. } else {
  1544. a[key] = val;
  1545. }
  1546. });
  1547. return a;
  1548. }
  1549. module.exports = {
  1550. isArray: isArray,
  1551. isArrayBuffer: isArrayBuffer,
  1552. isBuffer: isBuffer,
  1553. isFormData: isFormData,
  1554. isArrayBufferView: isArrayBufferView,
  1555. isString: isString,
  1556. isNumber: isNumber,
  1557. isObject: isObject,
  1558. isUndefined: isUndefined,
  1559. isDate: isDate,
  1560. isFile: isFile,
  1561. isBlob: isBlob,
  1562. isFunction: isFunction,
  1563. isStream: isStream,
  1564. isURLSearchParams: isURLSearchParams,
  1565. isStandardBrowserEnv: isStandardBrowserEnv,
  1566. forEach: forEach,
  1567. merge: merge,
  1568. deepMerge: deepMerge,
  1569. extend: extend,
  1570. trim: trim
  1571. };
  1572. /***/ }),
  1573. /***/ "./node_modules/lodash/lodash.js":
  1574. /*!***************************************!*\
  1575. !*** ./node_modules/lodash/lodash.js ***!
  1576. \***************************************/
  1577. /*! no static exports found */
  1578. /***/ (function(module, exports, __webpack_require__) {
  1579. /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
  1580. * @license
  1581. * Lodash <https://lodash.com/>
  1582. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  1583. * Released under MIT license <https://lodash.com/license>
  1584. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1585. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1586. */
  1587. ;(function() {
  1588. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  1589. var undefined;
  1590. /** Used as the semantic version number. */
  1591. var VERSION = '4.17.21';
  1592. /** Used as the size to enable large array optimizations. */
  1593. var LARGE_ARRAY_SIZE = 200;
  1594. /** Error message constants. */
  1595. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  1596. FUNC_ERROR_TEXT = 'Expected a function',
  1597. INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
  1598. /** Used to stand-in for `undefined` hash values. */
  1599. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  1600. /** Used as the maximum memoize cache size. */
  1601. var MAX_MEMOIZE_SIZE = 500;
  1602. /** Used as the internal argument placeholder. */
  1603. var PLACEHOLDER = '__lodash_placeholder__';
  1604. /** Used to compose bitmasks for cloning. */
  1605. var CLONE_DEEP_FLAG = 1,
  1606. CLONE_FLAT_FLAG = 2,
  1607. CLONE_SYMBOLS_FLAG = 4;
  1608. /** Used to compose bitmasks for value comparisons. */
  1609. var COMPARE_PARTIAL_FLAG = 1,
  1610. COMPARE_UNORDERED_FLAG = 2;
  1611. /** Used to compose bitmasks for function metadata. */
  1612. var WRAP_BIND_FLAG = 1,
  1613. WRAP_BIND_KEY_FLAG = 2,
  1614. WRAP_CURRY_BOUND_FLAG = 4,
  1615. WRAP_CURRY_FLAG = 8,
  1616. WRAP_CURRY_RIGHT_FLAG = 16,
  1617. WRAP_PARTIAL_FLAG = 32,
  1618. WRAP_PARTIAL_RIGHT_FLAG = 64,
  1619. WRAP_ARY_FLAG = 128,
  1620. WRAP_REARG_FLAG = 256,
  1621. WRAP_FLIP_FLAG = 512;
  1622. /** Used as default options for `_.truncate`. */
  1623. var DEFAULT_TRUNC_LENGTH = 30,
  1624. DEFAULT_TRUNC_OMISSION = '...';
  1625. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  1626. var HOT_COUNT = 800,
  1627. HOT_SPAN = 16;
  1628. /** Used to indicate the type of lazy iteratees. */
  1629. var LAZY_FILTER_FLAG = 1,
  1630. LAZY_MAP_FLAG = 2,
  1631. LAZY_WHILE_FLAG = 3;
  1632. /** Used as references for various `Number` constants. */
  1633. var INFINITY = 1 / 0,
  1634. MAX_SAFE_INTEGER = 9007199254740991,
  1635. MAX_INTEGER = 1.7976931348623157e+308,
  1636. NAN = 0 / 0;
  1637. /** Used as references for the maximum length and index of an array. */
  1638. var MAX_ARRAY_LENGTH = 4294967295,
  1639. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  1640. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  1641. /** Used to associate wrap methods with their bit flags. */
  1642. var wrapFlags = [
  1643. ['ary', WRAP_ARY_FLAG],
  1644. ['bind', WRAP_BIND_FLAG],
  1645. ['bindKey', WRAP_BIND_KEY_FLAG],
  1646. ['curry', WRAP_CURRY_FLAG],
  1647. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  1648. ['flip', WRAP_FLIP_FLAG],
  1649. ['partial', WRAP_PARTIAL_FLAG],
  1650. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  1651. ['rearg', WRAP_REARG_FLAG]
  1652. ];
  1653. /** `Object#toString` result references. */
  1654. var argsTag = '[object Arguments]',
  1655. arrayTag = '[object Array]',
  1656. asyncTag = '[object AsyncFunction]',
  1657. boolTag = '[object Boolean]',
  1658. dateTag = '[object Date]',
  1659. domExcTag = '[object DOMException]',
  1660. errorTag = '[object Error]',
  1661. funcTag = '[object Function]',
  1662. genTag = '[object GeneratorFunction]',
  1663. mapTag = '[object Map]',
  1664. numberTag = '[object Number]',
  1665. nullTag = '[object Null]',
  1666. objectTag = '[object Object]',
  1667. promiseTag = '[object Promise]',
  1668. proxyTag = '[object Proxy]',
  1669. regexpTag = '[object RegExp]',
  1670. setTag = '[object Set]',
  1671. stringTag = '[object String]',
  1672. symbolTag = '[object Symbol]',
  1673. undefinedTag = '[object Undefined]',
  1674. weakMapTag = '[object WeakMap]',
  1675. weakSetTag = '[object WeakSet]';
  1676. var arrayBufferTag = '[object ArrayBuffer]',
  1677. dataViewTag = '[object DataView]',
  1678. float32Tag = '[object Float32Array]',
  1679. float64Tag = '[object Float64Array]',
  1680. int8Tag = '[object Int8Array]',
  1681. int16Tag = '[object Int16Array]',
  1682. int32Tag = '[object Int32Array]',
  1683. uint8Tag = '[object Uint8Array]',
  1684. uint8ClampedTag = '[object Uint8ClampedArray]',
  1685. uint16Tag = '[object Uint16Array]',
  1686. uint32Tag = '[object Uint32Array]';
  1687. /** Used to match empty string literals in compiled template source. */
  1688. var reEmptyStringLeading = /\b__p \+= '';/g,
  1689. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  1690. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  1691. /** Used to match HTML entities and HTML characters. */
  1692. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  1693. reUnescapedHtml = /[&<>"']/g,
  1694. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  1695. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  1696. /** Used to match template delimiters. */
  1697. var reEscape = /<%-([\s\S]+?)%>/g,
  1698. reEvaluate = /<%([\s\S]+?)%>/g,
  1699. reInterpolate = /<%=([\s\S]+?)%>/g;
  1700. /** Used to match property names within property paths. */
  1701. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  1702. reIsPlainProp = /^\w*$/,
  1703. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  1704. /**
  1705. * Used to match `RegExp`
  1706. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  1707. */
  1708. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  1709. reHasRegExpChar = RegExp(reRegExpChar.source);
  1710. /** Used to match leading whitespace. */
  1711. var reTrimStart = /^\s+/;
  1712. /** Used to match a single whitespace character. */
  1713. var reWhitespace = /\s/;
  1714. /** Used to match wrap detail comments. */
  1715. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  1716. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  1717. reSplitDetails = /,? & /;
  1718. /** Used to match words composed of alphanumeric characters. */
  1719. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  1720. /**
  1721. * Used to validate the `validate` option in `_.template` variable.
  1722. *
  1723. * Forbids characters which could potentially change the meaning of the function argument definition:
  1724. * - "()," (modification of function parameters)
  1725. * - "=" (default value)
  1726. * - "[]{}" (destructuring of function parameters)
  1727. * - "/" (beginning of a comment)
  1728. * - whitespace
  1729. */
  1730. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  1731. /** Used to match backslashes in property paths. */
  1732. var reEscapeChar = /\\(\\)?/g;
  1733. /**
  1734. * Used to match
  1735. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  1736. */
  1737. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  1738. /** Used to match `RegExp` flags from their coerced string values. */
  1739. var reFlags = /\w*$/;
  1740. /** Used to detect bad signed hexadecimal string values. */
  1741. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  1742. /** Used to detect binary string values. */
  1743. var reIsBinary = /^0b[01]+$/i;
  1744. /** Used to detect host constructors (Safari). */
  1745. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  1746. /** Used to detect octal string values. */
  1747. var reIsOctal = /^0o[0-7]+$/i;
  1748. /** Used to detect unsigned integer values. */
  1749. var reIsUint = /^(?:0|[1-9]\d*)$/;
  1750. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  1751. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  1752. /** Used to ensure capturing order of template delimiters. */
  1753. var reNoMatch = /($^)/;
  1754. /** Used to match unescaped characters in compiled string literals. */
  1755. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  1756. /** Used to compose unicode character classes. */
  1757. var rsAstralRange = '\\ud800-\\udfff',
  1758. rsComboMarksRange = '\\u0300-\\u036f',
  1759. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  1760. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  1761. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  1762. rsDingbatRange = '\\u2700-\\u27bf',
  1763. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  1764. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  1765. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  1766. rsPunctuationRange = '\\u2000-\\u206f',
  1767. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  1768. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  1769. rsVarRange = '\\ufe0e\\ufe0f',
  1770. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  1771. /** Used to compose unicode capture groups. */
  1772. var rsApos = "['\u2019]",
  1773. rsAstral = '[' + rsAstralRange + ']',
  1774. rsBreak = '[' + rsBreakRange + ']',
  1775. rsCombo = '[' + rsComboRange + ']',
  1776. rsDigits = '\\d+',
  1777. rsDingbat = '[' + rsDingbatRange + ']',
  1778. rsLower = '[' + rsLowerRange + ']',
  1779. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  1780. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  1781. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  1782. rsNonAstral = '[^' + rsAstralRange + ']',
  1783. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  1784. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  1785. rsUpper = '[' + rsUpperRange + ']',
  1786. rsZWJ = '\\u200d';
  1787. /** Used to compose unicode regexes. */
  1788. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  1789. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  1790. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  1791. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  1792. reOptMod = rsModifier + '?',
  1793. rsOptVar = '[' + rsVarRange + ']?',
  1794. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  1795. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  1796. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  1797. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  1798. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  1799. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  1800. /** Used to match apostrophes. */
  1801. var reApos = RegExp(rsApos, 'g');
  1802. /**
  1803. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  1804. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  1805. */
  1806. var reComboMark = RegExp(rsCombo, 'g');
  1807. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  1808. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  1809. /** Used to match complex or compound words. */
  1810. var reUnicodeWord = RegExp([
  1811. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  1812. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  1813. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  1814. rsUpper + '+' + rsOptContrUpper,
  1815. rsOrdUpper,
  1816. rsOrdLower,
  1817. rsDigits,
  1818. rsEmoji
  1819. ].join('|'), 'g');
  1820. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  1821. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  1822. /** Used to detect strings that need a more robust regexp to match words. */
  1823. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  1824. /** Used to assign default `context` object properties. */
  1825. var contextProps = [
  1826. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  1827. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  1828. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  1829. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  1830. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  1831. ];
  1832. /** Used to make template sourceURLs easier to identify. */
  1833. var templateCounter = -1;
  1834. /** Used to identify `toStringTag` values of typed arrays. */
  1835. var typedArrayTags = {};
  1836. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  1837. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  1838. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  1839. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  1840. typedArrayTags[uint32Tag] = true;
  1841. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  1842. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  1843. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  1844. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  1845. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  1846. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  1847. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  1848. typedArrayTags[weakMapTag] = false;
  1849. /** Used to identify `toStringTag` values supported by `_.clone`. */
  1850. var cloneableTags = {};
  1851. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  1852. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  1853. cloneableTags[boolTag] = cloneableTags[dateTag] =
  1854. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  1855. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  1856. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  1857. cloneableTags[numberTag] = cloneableTags[objectTag] =
  1858. cloneableTags[regexpTag] = cloneableTags[setTag] =
  1859. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  1860. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  1861. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  1862. cloneableTags[errorTag] = cloneableTags[funcTag] =
  1863. cloneableTags[weakMapTag] = false;
  1864. /** Used to map Latin Unicode letters to basic Latin letters. */
  1865. var deburredLetters = {
  1866. // Latin-1 Supplement block.
  1867. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  1868. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  1869. '\xc7': 'C', '\xe7': 'c',
  1870. '\xd0': 'D', '\xf0': 'd',
  1871. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  1872. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  1873. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  1874. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  1875. '\xd1': 'N', '\xf1': 'n',
  1876. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  1877. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  1878. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  1879. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  1880. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  1881. '\xc6': 'Ae', '\xe6': 'ae',
  1882. '\xde': 'Th', '\xfe': 'th',
  1883. '\xdf': 'ss',
  1884. // Latin Extended-A block.
  1885. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  1886. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  1887. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  1888. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  1889. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  1890. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  1891. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  1892. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  1893. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  1894. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  1895. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  1896. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  1897. '\u0134': 'J', '\u0135': 'j',
  1898. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  1899. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  1900. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  1901. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  1902. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  1903. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  1904. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  1905. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  1906. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  1907. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  1908. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  1909. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  1910. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  1911. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  1912. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  1913. '\u0174': 'W', '\u0175': 'w',
  1914. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  1915. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  1916. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  1917. '\u0132': 'IJ', '\u0133': 'ij',
  1918. '\u0152': 'Oe', '\u0153': 'oe',
  1919. '\u0149': "'n", '\u017f': 's'
  1920. };
  1921. /** Used to map characters to HTML entities. */
  1922. var htmlEscapes = {
  1923. '&': '&amp;',
  1924. '<': '&lt;',
  1925. '>': '&gt;',
  1926. '"': '&quot;',
  1927. "'": '&#39;'
  1928. };
  1929. /** Used to map HTML entities to characters. */
  1930. var htmlUnescapes = {
  1931. '&amp;': '&',
  1932. '&lt;': '<',
  1933. '&gt;': '>',
  1934. '&quot;': '"',
  1935. '&#39;': "'"
  1936. };
  1937. /** Used to escape characters for inclusion in compiled string literals. */
  1938. var stringEscapes = {
  1939. '\\': '\\',
  1940. "'": "'",
  1941. '\n': 'n',
  1942. '\r': 'r',
  1943. '\u2028': 'u2028',
  1944. '\u2029': 'u2029'
  1945. };
  1946. /** Built-in method references without a dependency on `root`. */
  1947. var freeParseFloat = parseFloat,
  1948. freeParseInt = parseInt;
  1949. /** Detect free variable `global` from Node.js. */
  1950. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  1951. /** Detect free variable `self`. */
  1952. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  1953. /** Used as a reference to the global object. */
  1954. var root = freeGlobal || freeSelf || Function('return this')();
  1955. /** Detect free variable `exports`. */
  1956. var freeExports = true && exports && !exports.nodeType && exports;
  1957. /** Detect free variable `module`. */
  1958. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  1959. /** Detect the popular CommonJS extension `module.exports`. */
  1960. var moduleExports = freeModule && freeModule.exports === freeExports;
  1961. /** Detect free variable `process` from Node.js. */
  1962. var freeProcess = moduleExports && freeGlobal.process;
  1963. /** Used to access faster Node.js helpers. */
  1964. var nodeUtil = (function() {
  1965. try {
  1966. // Use `util.types` for Node.js 10+.
  1967. var types = freeModule && freeModule.require && freeModule.require('util').types;
  1968. if (types) {
  1969. return types;
  1970. }
  1971. // Legacy `process.binding('util')` for Node.js < 10.
  1972. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  1973. } catch (e) {}
  1974. }());
  1975. /* Node.js helper references. */
  1976. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  1977. nodeIsDate = nodeUtil && nodeUtil.isDate,
  1978. nodeIsMap = nodeUtil && nodeUtil.isMap,
  1979. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  1980. nodeIsSet = nodeUtil && nodeUtil.isSet,
  1981. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  1982. /*--------------------------------------------------------------------------*/
  1983. /**
  1984. * A faster alternative to `Function#apply`, this function invokes `func`
  1985. * with the `this` binding of `thisArg` and the arguments of `args`.
  1986. *
  1987. * @private
  1988. * @param {Function} func The function to invoke.
  1989. * @param {*} thisArg The `this` binding of `func`.
  1990. * @param {Array} args The arguments to invoke `func` with.
  1991. * @returns {*} Returns the result of `func`.
  1992. */
  1993. function apply(func, thisArg, args) {
  1994. switch (args.length) {
  1995. case 0: return func.call(thisArg);
  1996. case 1: return func.call(thisArg, args[0]);
  1997. case 2: return func.call(thisArg, args[0], args[1]);
  1998. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  1999. }
  2000. return func.apply(thisArg, args);
  2001. }
  2002. /**
  2003. * A specialized version of `baseAggregator` for arrays.
  2004. *
  2005. * @private
  2006. * @param {Array} [array] The array to iterate over.
  2007. * @param {Function} setter The function to set `accumulator` values.
  2008. * @param {Function} iteratee The iteratee to transform keys.
  2009. * @param {Object} accumulator The initial aggregated object.
  2010. * @returns {Function} Returns `accumulator`.
  2011. */
  2012. function arrayAggregator(array, setter, iteratee, accumulator) {
  2013. var index = -1,
  2014. length = array == null ? 0 : array.length;
  2015. while (++index < length) {
  2016. var value = array[index];
  2017. setter(accumulator, value, iteratee(value), array);
  2018. }
  2019. return accumulator;
  2020. }
  2021. /**
  2022. * A specialized version of `_.forEach` for arrays without support for
  2023. * iteratee shorthands.
  2024. *
  2025. * @private
  2026. * @param {Array} [array] The array to iterate over.
  2027. * @param {Function} iteratee The function invoked per iteration.
  2028. * @returns {Array} Returns `array`.
  2029. */
  2030. function arrayEach(array, iteratee) {
  2031. var index = -1,
  2032. length = array == null ? 0 : array.length;
  2033. while (++index < length) {
  2034. if (iteratee(array[index], index, array) === false) {
  2035. break;
  2036. }
  2037. }
  2038. return array;
  2039. }
  2040. /**
  2041. * A specialized version of `_.forEachRight` for arrays without support for
  2042. * iteratee shorthands.
  2043. *
  2044. * @private
  2045. * @param {Array} [array] The array to iterate over.
  2046. * @param {Function} iteratee The function invoked per iteration.
  2047. * @returns {Array} Returns `array`.
  2048. */
  2049. function arrayEachRight(array, iteratee) {
  2050. var length = array == null ? 0 : array.length;
  2051. while (length--) {
  2052. if (iteratee(array[length], length, array) === false) {
  2053. break;
  2054. }
  2055. }
  2056. return array;
  2057. }
  2058. /**
  2059. * A specialized version of `_.every` for arrays without support for
  2060. * iteratee shorthands.
  2061. *
  2062. * @private
  2063. * @param {Array} [array] The array to iterate over.
  2064. * @param {Function} predicate The function invoked per iteration.
  2065. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2066. * else `false`.
  2067. */
  2068. function arrayEvery(array, predicate) {
  2069. var index = -1,
  2070. length = array == null ? 0 : array.length;
  2071. while (++index < length) {
  2072. if (!predicate(array[index], index, array)) {
  2073. return false;
  2074. }
  2075. }
  2076. return true;
  2077. }
  2078. /**
  2079. * A specialized version of `_.filter` for arrays without support for
  2080. * iteratee shorthands.
  2081. *
  2082. * @private
  2083. * @param {Array} [array] The array to iterate over.
  2084. * @param {Function} predicate The function invoked per iteration.
  2085. * @returns {Array} Returns the new filtered array.
  2086. */
  2087. function arrayFilter(array, predicate) {
  2088. var index = -1,
  2089. length = array == null ? 0 : array.length,
  2090. resIndex = 0,
  2091. result = [];
  2092. while (++index < length) {
  2093. var value = array[index];
  2094. if (predicate(value, index, array)) {
  2095. result[resIndex++] = value;
  2096. }
  2097. }
  2098. return result;
  2099. }
  2100. /**
  2101. * A specialized version of `_.includes` for arrays without support for
  2102. * specifying an index to search from.
  2103. *
  2104. * @private
  2105. * @param {Array} [array] The array to inspect.
  2106. * @param {*} target The value to search for.
  2107. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  2108. */
  2109. function arrayIncludes(array, value) {
  2110. var length = array == null ? 0 : array.length;
  2111. return !!length && baseIndexOf(array, value, 0) > -1;
  2112. }
  2113. /**
  2114. * This function is like `arrayIncludes` except that it accepts a comparator.
  2115. *
  2116. * @private
  2117. * @param {Array} [array] The array to inspect.
  2118. * @param {*} target The value to search for.
  2119. * @param {Function} comparator The comparator invoked per element.
  2120. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  2121. */
  2122. function arrayIncludesWith(array, value, comparator) {
  2123. var index = -1,
  2124. length = array == null ? 0 : array.length;
  2125. while (++index < length) {
  2126. if (comparator(value, array[index])) {
  2127. return true;
  2128. }
  2129. }
  2130. return false;
  2131. }
  2132. /**
  2133. * A specialized version of `_.map` for arrays without support for iteratee
  2134. * shorthands.
  2135. *
  2136. * @private
  2137. * @param {Array} [array] The array to iterate over.
  2138. * @param {Function} iteratee The function invoked per iteration.
  2139. * @returns {Array} Returns the new mapped array.
  2140. */
  2141. function arrayMap(array, iteratee) {
  2142. var index = -1,
  2143. length = array == null ? 0 : array.length,
  2144. result = Array(length);
  2145. while (++index < length) {
  2146. result[index] = iteratee(array[index], index, array);
  2147. }
  2148. return result;
  2149. }
  2150. /**
  2151. * Appends the elements of `values` to `array`.
  2152. *
  2153. * @private
  2154. * @param {Array} array The array to modify.
  2155. * @param {Array} values The values to append.
  2156. * @returns {Array} Returns `array`.
  2157. */
  2158. function arrayPush(array, values) {
  2159. var index = -1,
  2160. length = values.length,
  2161. offset = array.length;
  2162. while (++index < length) {
  2163. array[offset + index] = values[index];
  2164. }
  2165. return array;
  2166. }
  2167. /**
  2168. * A specialized version of `_.reduce` for arrays without support for
  2169. * iteratee shorthands.
  2170. *
  2171. * @private
  2172. * @param {Array} [array] The array to iterate over.
  2173. * @param {Function} iteratee The function invoked per iteration.
  2174. * @param {*} [accumulator] The initial value.
  2175. * @param {boolean} [initAccum] Specify using the first element of `array` as
  2176. * the initial value.
  2177. * @returns {*} Returns the accumulated value.
  2178. */
  2179. function arrayReduce(array, iteratee, accumulator, initAccum) {
  2180. var index = -1,
  2181. length = array == null ? 0 : array.length;
  2182. if (initAccum && length) {
  2183. accumulator = array[++index];
  2184. }
  2185. while (++index < length) {
  2186. accumulator = iteratee(accumulator, array[index], index, array);
  2187. }
  2188. return accumulator;
  2189. }
  2190. /**
  2191. * A specialized version of `_.reduceRight` for arrays without support for
  2192. * iteratee shorthands.
  2193. *
  2194. * @private
  2195. * @param {Array} [array] The array to iterate over.
  2196. * @param {Function} iteratee The function invoked per iteration.
  2197. * @param {*} [accumulator] The initial value.
  2198. * @param {boolean} [initAccum] Specify using the last element of `array` as
  2199. * the initial value.
  2200. * @returns {*} Returns the accumulated value.
  2201. */
  2202. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  2203. var length = array == null ? 0 : array.length;
  2204. if (initAccum && length) {
  2205. accumulator = array[--length];
  2206. }
  2207. while (length--) {
  2208. accumulator = iteratee(accumulator, array[length], length, array);
  2209. }
  2210. return accumulator;
  2211. }
  2212. /**
  2213. * A specialized version of `_.some` for arrays without support for iteratee
  2214. * shorthands.
  2215. *
  2216. * @private
  2217. * @param {Array} [array] The array to iterate over.
  2218. * @param {Function} predicate The function invoked per iteration.
  2219. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2220. * else `false`.
  2221. */
  2222. function arraySome(array, predicate) {
  2223. var index = -1,
  2224. length = array == null ? 0 : array.length;
  2225. while (++index < length) {
  2226. if (predicate(array[index], index, array)) {
  2227. return true;
  2228. }
  2229. }
  2230. return false;
  2231. }
  2232. /**
  2233. * Gets the size of an ASCII `string`.
  2234. *
  2235. * @private
  2236. * @param {string} string The string inspect.
  2237. * @returns {number} Returns the string size.
  2238. */
  2239. var asciiSize = baseProperty('length');
  2240. /**
  2241. * Converts an ASCII `string` to an array.
  2242. *
  2243. * @private
  2244. * @param {string} string The string to convert.
  2245. * @returns {Array} Returns the converted array.
  2246. */
  2247. function asciiToArray(string) {
  2248. return string.split('');
  2249. }
  2250. /**
  2251. * Splits an ASCII `string` into an array of its words.
  2252. *
  2253. * @private
  2254. * @param {string} The string to inspect.
  2255. * @returns {Array} Returns the words of `string`.
  2256. */
  2257. function asciiWords(string) {
  2258. return string.match(reAsciiWord) || [];
  2259. }
  2260. /**
  2261. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  2262. * without support for iteratee shorthands, which iterates over `collection`
  2263. * using `eachFunc`.
  2264. *
  2265. * @private
  2266. * @param {Array|Object} collection The collection to inspect.
  2267. * @param {Function} predicate The function invoked per iteration.
  2268. * @param {Function} eachFunc The function to iterate over `collection`.
  2269. * @returns {*} Returns the found element or its key, else `undefined`.
  2270. */
  2271. function baseFindKey(collection, predicate, eachFunc) {
  2272. var result;
  2273. eachFunc(collection, function(value, key, collection) {
  2274. if (predicate(value, key, collection)) {
  2275. result = key;
  2276. return false;
  2277. }
  2278. });
  2279. return result;
  2280. }
  2281. /**
  2282. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  2283. * support for iteratee shorthands.
  2284. *
  2285. * @private
  2286. * @param {Array} array The array to inspect.
  2287. * @param {Function} predicate The function invoked per iteration.
  2288. * @param {number} fromIndex The index to search from.
  2289. * @param {boolean} [fromRight] Specify iterating from right to left.
  2290. * @returns {number} Returns the index of the matched value, else `-1`.
  2291. */
  2292. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  2293. var length = array.length,
  2294. index = fromIndex + (fromRight ? 1 : -1);
  2295. while ((fromRight ? index-- : ++index < length)) {
  2296. if (predicate(array[index], index, array)) {
  2297. return index;
  2298. }
  2299. }
  2300. return -1;
  2301. }
  2302. /**
  2303. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  2304. *
  2305. * @private
  2306. * @param {Array} array The array to inspect.
  2307. * @param {*} value The value to search for.
  2308. * @param {number} fromIndex The index to search from.
  2309. * @returns {number} Returns the index of the matched value, else `-1`.
  2310. */
  2311. function baseIndexOf(array, value, fromIndex) {
  2312. return value === value
  2313. ? strictIndexOf(array, value, fromIndex)
  2314. : baseFindIndex(array, baseIsNaN, fromIndex);
  2315. }
  2316. /**
  2317. * This function is like `baseIndexOf` except that it accepts a comparator.
  2318. *
  2319. * @private
  2320. * @param {Array} array The array to inspect.
  2321. * @param {*} value The value to search for.
  2322. * @param {number} fromIndex The index to search from.
  2323. * @param {Function} comparator The comparator invoked per element.
  2324. * @returns {number} Returns the index of the matched value, else `-1`.
  2325. */
  2326. function baseIndexOfWith(array, value, fromIndex, comparator) {
  2327. var index = fromIndex - 1,
  2328. length = array.length;
  2329. while (++index < length) {
  2330. if (comparator(array[index], value)) {
  2331. return index;
  2332. }
  2333. }
  2334. return -1;
  2335. }
  2336. /**
  2337. * The base implementation of `_.isNaN` without support for number objects.
  2338. *
  2339. * @private
  2340. * @param {*} value The value to check.
  2341. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  2342. */
  2343. function baseIsNaN(value) {
  2344. return value !== value;
  2345. }
  2346. /**
  2347. * The base implementation of `_.mean` and `_.meanBy` without support for
  2348. * iteratee shorthands.
  2349. *
  2350. * @private
  2351. * @param {Array} array The array to iterate over.
  2352. * @param {Function} iteratee The function invoked per iteration.
  2353. * @returns {number} Returns the mean.
  2354. */
  2355. function baseMean(array, iteratee) {
  2356. var length = array == null ? 0 : array.length;
  2357. return length ? (baseSum(array, iteratee) / length) : NAN;
  2358. }
  2359. /**
  2360. * The base implementation of `_.property` without support for deep paths.
  2361. *
  2362. * @private
  2363. * @param {string} key The key of the property to get.
  2364. * @returns {Function} Returns the new accessor function.
  2365. */
  2366. function baseProperty(key) {
  2367. return function(object) {
  2368. return object == null ? undefined : object[key];
  2369. };
  2370. }
  2371. /**
  2372. * The base implementation of `_.propertyOf` without support for deep paths.
  2373. *
  2374. * @private
  2375. * @param {Object} object The object to query.
  2376. * @returns {Function} Returns the new accessor function.
  2377. */
  2378. function basePropertyOf(object) {
  2379. return function(key) {
  2380. return object == null ? undefined : object[key];
  2381. };
  2382. }
  2383. /**
  2384. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  2385. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  2386. *
  2387. * @private
  2388. * @param {Array|Object} collection The collection to iterate over.
  2389. * @param {Function} iteratee The function invoked per iteration.
  2390. * @param {*} accumulator The initial value.
  2391. * @param {boolean} initAccum Specify using the first or last element of
  2392. * `collection` as the initial value.
  2393. * @param {Function} eachFunc The function to iterate over `collection`.
  2394. * @returns {*} Returns the accumulated value.
  2395. */
  2396. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  2397. eachFunc(collection, function(value, index, collection) {
  2398. accumulator = initAccum
  2399. ? (initAccum = false, value)
  2400. : iteratee(accumulator, value, index, collection);
  2401. });
  2402. return accumulator;
  2403. }
  2404. /**
  2405. * The base implementation of `_.sortBy` which uses `comparer` to define the
  2406. * sort order of `array` and replaces criteria objects with their corresponding
  2407. * values.
  2408. *
  2409. * @private
  2410. * @param {Array} array The array to sort.
  2411. * @param {Function} comparer The function to define sort order.
  2412. * @returns {Array} Returns `array`.
  2413. */
  2414. function baseSortBy(array, comparer) {
  2415. var length = array.length;
  2416. array.sort(comparer);
  2417. while (length--) {
  2418. array[length] = array[length].value;
  2419. }
  2420. return array;
  2421. }
  2422. /**
  2423. * The base implementation of `_.sum` and `_.sumBy` without support for
  2424. * iteratee shorthands.
  2425. *
  2426. * @private
  2427. * @param {Array} array The array to iterate over.
  2428. * @param {Function} iteratee The function invoked per iteration.
  2429. * @returns {number} Returns the sum.
  2430. */
  2431. function baseSum(array, iteratee) {
  2432. var result,
  2433. index = -1,
  2434. length = array.length;
  2435. while (++index < length) {
  2436. var current = iteratee(array[index]);
  2437. if (current !== undefined) {
  2438. result = result === undefined ? current : (result + current);
  2439. }
  2440. }
  2441. return result;
  2442. }
  2443. /**
  2444. * The base implementation of `_.times` without support for iteratee shorthands
  2445. * or max array length checks.
  2446. *
  2447. * @private
  2448. * @param {number} n The number of times to invoke `iteratee`.
  2449. * @param {Function} iteratee The function invoked per iteration.
  2450. * @returns {Array} Returns the array of results.
  2451. */
  2452. function baseTimes(n, iteratee) {
  2453. var index = -1,
  2454. result = Array(n);
  2455. while (++index < n) {
  2456. result[index] = iteratee(index);
  2457. }
  2458. return result;
  2459. }
  2460. /**
  2461. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  2462. * of key-value pairs for `object` corresponding to the property names of `props`.
  2463. *
  2464. * @private
  2465. * @param {Object} object The object to query.
  2466. * @param {Array} props The property names to get values for.
  2467. * @returns {Object} Returns the key-value pairs.
  2468. */
  2469. function baseToPairs(object, props) {
  2470. return arrayMap(props, function(key) {
  2471. return [key, object[key]];
  2472. });
  2473. }
  2474. /**
  2475. * The base implementation of `_.trim`.
  2476. *
  2477. * @private
  2478. * @param {string} string The string to trim.
  2479. * @returns {string} Returns the trimmed string.
  2480. */
  2481. function baseTrim(string) {
  2482. return string
  2483. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  2484. : string;
  2485. }
  2486. /**
  2487. * The base implementation of `_.unary` without support for storing metadata.
  2488. *
  2489. * @private
  2490. * @param {Function} func The function to cap arguments for.
  2491. * @returns {Function} Returns the new capped function.
  2492. */
  2493. function baseUnary(func) {
  2494. return function(value) {
  2495. return func(value);
  2496. };
  2497. }
  2498. /**
  2499. * The base implementation of `_.values` and `_.valuesIn` which creates an
  2500. * array of `object` property values corresponding to the property names
  2501. * of `props`.
  2502. *
  2503. * @private
  2504. * @param {Object} object The object to query.
  2505. * @param {Array} props The property names to get values for.
  2506. * @returns {Object} Returns the array of property values.
  2507. */
  2508. function baseValues(object, props) {
  2509. return arrayMap(props, function(key) {
  2510. return object[key];
  2511. });
  2512. }
  2513. /**
  2514. * Checks if a `cache` value for `key` exists.
  2515. *
  2516. * @private
  2517. * @param {Object} cache The cache to query.
  2518. * @param {string} key The key of the entry to check.
  2519. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2520. */
  2521. function cacheHas(cache, key) {
  2522. return cache.has(key);
  2523. }
  2524. /**
  2525. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  2526. * that is not found in the character symbols.
  2527. *
  2528. * @private
  2529. * @param {Array} strSymbols The string symbols to inspect.
  2530. * @param {Array} chrSymbols The character symbols to find.
  2531. * @returns {number} Returns the index of the first unmatched string symbol.
  2532. */
  2533. function charsStartIndex(strSymbols, chrSymbols) {
  2534. var index = -1,
  2535. length = strSymbols.length;
  2536. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  2537. return index;
  2538. }
  2539. /**
  2540. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  2541. * that is not found in the character symbols.
  2542. *
  2543. * @private
  2544. * @param {Array} strSymbols The string symbols to inspect.
  2545. * @param {Array} chrSymbols The character symbols to find.
  2546. * @returns {number} Returns the index of the last unmatched string symbol.
  2547. */
  2548. function charsEndIndex(strSymbols, chrSymbols) {
  2549. var index = strSymbols.length;
  2550. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  2551. return index;
  2552. }
  2553. /**
  2554. * Gets the number of `placeholder` occurrences in `array`.
  2555. *
  2556. * @private
  2557. * @param {Array} array The array to inspect.
  2558. * @param {*} placeholder The placeholder to search for.
  2559. * @returns {number} Returns the placeholder count.
  2560. */
  2561. function countHolders(array, placeholder) {
  2562. var length = array.length,
  2563. result = 0;
  2564. while (length--) {
  2565. if (array[length] === placeholder) {
  2566. ++result;
  2567. }
  2568. }
  2569. return result;
  2570. }
  2571. /**
  2572. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  2573. * letters to basic Latin letters.
  2574. *
  2575. * @private
  2576. * @param {string} letter The matched letter to deburr.
  2577. * @returns {string} Returns the deburred letter.
  2578. */
  2579. var deburrLetter = basePropertyOf(deburredLetters);
  2580. /**
  2581. * Used by `_.escape` to convert characters to HTML entities.
  2582. *
  2583. * @private
  2584. * @param {string} chr The matched character to escape.
  2585. * @returns {string} Returns the escaped character.
  2586. */
  2587. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  2588. /**
  2589. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  2590. *
  2591. * @private
  2592. * @param {string} chr The matched character to escape.
  2593. * @returns {string} Returns the escaped character.
  2594. */
  2595. function escapeStringChar(chr) {
  2596. return '\\' + stringEscapes[chr];
  2597. }
  2598. /**
  2599. * Gets the value at `key` of `object`.
  2600. *
  2601. * @private
  2602. * @param {Object} [object] The object to query.
  2603. * @param {string} key The key of the property to get.
  2604. * @returns {*} Returns the property value.
  2605. */
  2606. function getValue(object, key) {
  2607. return object == null ? undefined : object[key];
  2608. }
  2609. /**
  2610. * Checks if `string` contains Unicode symbols.
  2611. *
  2612. * @private
  2613. * @param {string} string The string to inspect.
  2614. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  2615. */
  2616. function hasUnicode(string) {
  2617. return reHasUnicode.test(string);
  2618. }
  2619. /**
  2620. * Checks if `string` contains a word composed of Unicode symbols.
  2621. *
  2622. * @private
  2623. * @param {string} string The string to inspect.
  2624. * @returns {boolean} Returns `true` if a word is found, else `false`.
  2625. */
  2626. function hasUnicodeWord(string) {
  2627. return reHasUnicodeWord.test(string);
  2628. }
  2629. /**
  2630. * Converts `iterator` to an array.
  2631. *
  2632. * @private
  2633. * @param {Object} iterator The iterator to convert.
  2634. * @returns {Array} Returns the converted array.
  2635. */
  2636. function iteratorToArray(iterator) {
  2637. var data,
  2638. result = [];
  2639. while (!(data = iterator.next()).done) {
  2640. result.push(data.value);
  2641. }
  2642. return result;
  2643. }
  2644. /**
  2645. * Converts `map` to its key-value pairs.
  2646. *
  2647. * @private
  2648. * @param {Object} map The map to convert.
  2649. * @returns {Array} Returns the key-value pairs.
  2650. */
  2651. function mapToArray(map) {
  2652. var index = -1,
  2653. result = Array(map.size);
  2654. map.forEach(function(value, key) {
  2655. result[++index] = [key, value];
  2656. });
  2657. return result;
  2658. }
  2659. /**
  2660. * Creates a unary function that invokes `func` with its argument transformed.
  2661. *
  2662. * @private
  2663. * @param {Function} func The function to wrap.
  2664. * @param {Function} transform The argument transform.
  2665. * @returns {Function} Returns the new function.
  2666. */
  2667. function overArg(func, transform) {
  2668. return function(arg) {
  2669. return func(transform(arg));
  2670. };
  2671. }
  2672. /**
  2673. * Replaces all `placeholder` elements in `array` with an internal placeholder
  2674. * and returns an array of their indexes.
  2675. *
  2676. * @private
  2677. * @param {Array} array The array to modify.
  2678. * @param {*} placeholder The placeholder to replace.
  2679. * @returns {Array} Returns the new array of placeholder indexes.
  2680. */
  2681. function replaceHolders(array, placeholder) {
  2682. var index = -1,
  2683. length = array.length,
  2684. resIndex = 0,
  2685. result = [];
  2686. while (++index < length) {
  2687. var value = array[index];
  2688. if (value === placeholder || value === PLACEHOLDER) {
  2689. array[index] = PLACEHOLDER;
  2690. result[resIndex++] = index;
  2691. }
  2692. }
  2693. return result;
  2694. }
  2695. /**
  2696. * Converts `set` to an array of its values.
  2697. *
  2698. * @private
  2699. * @param {Object} set The set to convert.
  2700. * @returns {Array} Returns the values.
  2701. */
  2702. function setToArray(set) {
  2703. var index = -1,
  2704. result = Array(set.size);
  2705. set.forEach(function(value) {
  2706. result[++index] = value;
  2707. });
  2708. return result;
  2709. }
  2710. /**
  2711. * Converts `set` to its value-value pairs.
  2712. *
  2713. * @private
  2714. * @param {Object} set The set to convert.
  2715. * @returns {Array} Returns the value-value pairs.
  2716. */
  2717. function setToPairs(set) {
  2718. var index = -1,
  2719. result = Array(set.size);
  2720. set.forEach(function(value) {
  2721. result[++index] = [value, value];
  2722. });
  2723. return result;
  2724. }
  2725. /**
  2726. * A specialized version of `_.indexOf` which performs strict equality
  2727. * comparisons of values, i.e. `===`.
  2728. *
  2729. * @private
  2730. * @param {Array} array The array to inspect.
  2731. * @param {*} value The value to search for.
  2732. * @param {number} fromIndex The index to search from.
  2733. * @returns {number} Returns the index of the matched value, else `-1`.
  2734. */
  2735. function strictIndexOf(array, value, fromIndex) {
  2736. var index = fromIndex - 1,
  2737. length = array.length;
  2738. while (++index < length) {
  2739. if (array[index] === value) {
  2740. return index;
  2741. }
  2742. }
  2743. return -1;
  2744. }
  2745. /**
  2746. * A specialized version of `_.lastIndexOf` which performs strict equality
  2747. * comparisons of values, i.e. `===`.
  2748. *
  2749. * @private
  2750. * @param {Array} array The array to inspect.
  2751. * @param {*} value The value to search for.
  2752. * @param {number} fromIndex The index to search from.
  2753. * @returns {number} Returns the index of the matched value, else `-1`.
  2754. */
  2755. function strictLastIndexOf(array, value, fromIndex) {
  2756. var index = fromIndex + 1;
  2757. while (index--) {
  2758. if (array[index] === value) {
  2759. return index;
  2760. }
  2761. }
  2762. return index;
  2763. }
  2764. /**
  2765. * Gets the number of symbols in `string`.
  2766. *
  2767. * @private
  2768. * @param {string} string The string to inspect.
  2769. * @returns {number} Returns the string size.
  2770. */
  2771. function stringSize(string) {
  2772. return hasUnicode(string)
  2773. ? unicodeSize(string)
  2774. : asciiSize(string);
  2775. }
  2776. /**
  2777. * Converts `string` to an array.
  2778. *
  2779. * @private
  2780. * @param {string} string The string to convert.
  2781. * @returns {Array} Returns the converted array.
  2782. */
  2783. function stringToArray(string) {
  2784. return hasUnicode(string)
  2785. ? unicodeToArray(string)
  2786. : asciiToArray(string);
  2787. }
  2788. /**
  2789. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  2790. * character of `string`.
  2791. *
  2792. * @private
  2793. * @param {string} string The string to inspect.
  2794. * @returns {number} Returns the index of the last non-whitespace character.
  2795. */
  2796. function trimmedEndIndex(string) {
  2797. var index = string.length;
  2798. while (index-- && reWhitespace.test(string.charAt(index))) {}
  2799. return index;
  2800. }
  2801. /**
  2802. * Used by `_.unescape` to convert HTML entities to characters.
  2803. *
  2804. * @private
  2805. * @param {string} chr The matched character to unescape.
  2806. * @returns {string} Returns the unescaped character.
  2807. */
  2808. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  2809. /**
  2810. * Gets the size of a Unicode `string`.
  2811. *
  2812. * @private
  2813. * @param {string} string The string inspect.
  2814. * @returns {number} Returns the string size.
  2815. */
  2816. function unicodeSize(string) {
  2817. var result = reUnicode.lastIndex = 0;
  2818. while (reUnicode.test(string)) {
  2819. ++result;
  2820. }
  2821. return result;
  2822. }
  2823. /**
  2824. * Converts a Unicode `string` to an array.
  2825. *
  2826. * @private
  2827. * @param {string} string The string to convert.
  2828. * @returns {Array} Returns the converted array.
  2829. */
  2830. function unicodeToArray(string) {
  2831. return string.match(reUnicode) || [];
  2832. }
  2833. /**
  2834. * Splits a Unicode `string` into an array of its words.
  2835. *
  2836. * @private
  2837. * @param {string} The string to inspect.
  2838. * @returns {Array} Returns the words of `string`.
  2839. */
  2840. function unicodeWords(string) {
  2841. return string.match(reUnicodeWord) || [];
  2842. }
  2843. /*--------------------------------------------------------------------------*/
  2844. /**
  2845. * Create a new pristine `lodash` function using the `context` object.
  2846. *
  2847. * @static
  2848. * @memberOf _
  2849. * @since 1.1.0
  2850. * @category Util
  2851. * @param {Object} [context=root] The context object.
  2852. * @returns {Function} Returns a new `lodash` function.
  2853. * @example
  2854. *
  2855. * _.mixin({ 'foo': _.constant('foo') });
  2856. *
  2857. * var lodash = _.runInContext();
  2858. * lodash.mixin({ 'bar': lodash.constant('bar') });
  2859. *
  2860. * _.isFunction(_.foo);
  2861. * // => true
  2862. * _.isFunction(_.bar);
  2863. * // => false
  2864. *
  2865. * lodash.isFunction(lodash.foo);
  2866. * // => false
  2867. * lodash.isFunction(lodash.bar);
  2868. * // => true
  2869. *
  2870. * // Create a suped-up `defer` in Node.js.
  2871. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  2872. */
  2873. var runInContext = (function runInContext(context) {
  2874. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  2875. /** Built-in constructor references. */
  2876. var Array = context.Array,
  2877. Date = context.Date,
  2878. Error = context.Error,
  2879. Function = context.Function,
  2880. Math = context.Math,
  2881. Object = context.Object,
  2882. RegExp = context.RegExp,
  2883. String = context.String,
  2884. TypeError = context.TypeError;
  2885. /** Used for built-in method references. */
  2886. var arrayProto = Array.prototype,
  2887. funcProto = Function.prototype,
  2888. objectProto = Object.prototype;
  2889. /** Used to detect overreaching core-js shims. */
  2890. var coreJsData = context['__core-js_shared__'];
  2891. /** Used to resolve the decompiled source of functions. */
  2892. var funcToString = funcProto.toString;
  2893. /** Used to check objects for own properties. */
  2894. var hasOwnProperty = objectProto.hasOwnProperty;
  2895. /** Used to generate unique IDs. */
  2896. var idCounter = 0;
  2897. /** Used to detect methods masquerading as native. */
  2898. var maskSrcKey = (function() {
  2899. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  2900. return uid ? ('Symbol(src)_1.' + uid) : '';
  2901. }());
  2902. /**
  2903. * Used to resolve the
  2904. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  2905. * of values.
  2906. */
  2907. var nativeObjectToString = objectProto.toString;
  2908. /** Used to infer the `Object` constructor. */
  2909. var objectCtorString = funcToString.call(Object);
  2910. /** Used to restore the original `_` reference in `_.noConflict`. */
  2911. var oldDash = root._;
  2912. /** Used to detect if a method is native. */
  2913. var reIsNative = RegExp('^' +
  2914. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  2915. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  2916. );
  2917. /** Built-in value references. */
  2918. var Buffer = moduleExports ? context.Buffer : undefined,
  2919. Symbol = context.Symbol,
  2920. Uint8Array = context.Uint8Array,
  2921. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  2922. getPrototype = overArg(Object.getPrototypeOf, Object),
  2923. objectCreate = Object.create,
  2924. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  2925. splice = arrayProto.splice,
  2926. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  2927. symIterator = Symbol ? Symbol.iterator : undefined,
  2928. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  2929. var defineProperty = (function() {
  2930. try {
  2931. var func = getNative(Object, 'defineProperty');
  2932. func({}, '', {});
  2933. return func;
  2934. } catch (e) {}
  2935. }());
  2936. /** Mocked built-ins. */
  2937. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  2938. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  2939. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  2940. /* Built-in method references for those with the same name as other `lodash` methods. */
  2941. var nativeCeil = Math.ceil,
  2942. nativeFloor = Math.floor,
  2943. nativeGetSymbols = Object.getOwnPropertySymbols,
  2944. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  2945. nativeIsFinite = context.isFinite,
  2946. nativeJoin = arrayProto.join,
  2947. nativeKeys = overArg(Object.keys, Object),
  2948. nativeMax = Math.max,
  2949. nativeMin = Math.min,
  2950. nativeNow = Date.now,
  2951. nativeParseInt = context.parseInt,
  2952. nativeRandom = Math.random,
  2953. nativeReverse = arrayProto.reverse;
  2954. /* Built-in method references that are verified to be native. */
  2955. var DataView = getNative(context, 'DataView'),
  2956. Map = getNative(context, 'Map'),
  2957. Promise = getNative(context, 'Promise'),
  2958. Set = getNative(context, 'Set'),
  2959. WeakMap = getNative(context, 'WeakMap'),
  2960. nativeCreate = getNative(Object, 'create');
  2961. /** Used to store function metadata. */
  2962. var metaMap = WeakMap && new WeakMap;
  2963. /** Used to lookup unminified function names. */
  2964. var realNames = {};
  2965. /** Used to detect maps, sets, and weakmaps. */
  2966. var dataViewCtorString = toSource(DataView),
  2967. mapCtorString = toSource(Map),
  2968. promiseCtorString = toSource(Promise),
  2969. setCtorString = toSource(Set),
  2970. weakMapCtorString = toSource(WeakMap);
  2971. /** Used to convert symbols to primitives and strings. */
  2972. var symbolProto = Symbol ? Symbol.prototype : undefined,
  2973. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  2974. symbolToString = symbolProto ? symbolProto.toString : undefined;
  2975. /*------------------------------------------------------------------------*/
  2976. /**
  2977. * Creates a `lodash` object which wraps `value` to enable implicit method
  2978. * chain sequences. Methods that operate on and return arrays, collections,
  2979. * and functions can be chained together. Methods that retrieve a single value
  2980. * or may return a primitive value will automatically end the chain sequence
  2981. * and return the unwrapped value. Otherwise, the value must be unwrapped
  2982. * with `_#value`.
  2983. *
  2984. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  2985. * enabled using `_.chain`.
  2986. *
  2987. * The execution of chained methods is lazy, that is, it's deferred until
  2988. * `_#value` is implicitly or explicitly called.
  2989. *
  2990. * Lazy evaluation allows several methods to support shortcut fusion.
  2991. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  2992. * the creation of intermediate arrays and can greatly reduce the number of
  2993. * iteratee executions. Sections of a chain sequence qualify for shortcut
  2994. * fusion if the section is applied to an array and iteratees accept only
  2995. * one argument. The heuristic for whether a section qualifies for shortcut
  2996. * fusion is subject to change.
  2997. *
  2998. * Chaining is supported in custom builds as long as the `_#value` method is
  2999. * directly or indirectly included in the build.
  3000. *
  3001. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  3002. *
  3003. * The wrapper `Array` methods are:
  3004. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  3005. *
  3006. * The wrapper `String` methods are:
  3007. * `replace` and `split`
  3008. *
  3009. * The wrapper methods that support shortcut fusion are:
  3010. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  3011. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  3012. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  3013. *
  3014. * The chainable wrapper methods are:
  3015. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  3016. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  3017. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  3018. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  3019. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  3020. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  3021. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  3022. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  3023. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  3024. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  3025. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  3026. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  3027. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  3028. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  3029. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  3030. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  3031. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  3032. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  3033. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  3034. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  3035. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  3036. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  3037. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  3038. * `zipObject`, `zipObjectDeep`, and `zipWith`
  3039. *
  3040. * The wrapper methods that are **not** chainable by default are:
  3041. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  3042. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  3043. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  3044. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  3045. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  3046. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  3047. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  3048. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  3049. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  3050. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  3051. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  3052. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  3053. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  3054. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  3055. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  3056. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  3057. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  3058. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  3059. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  3060. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  3061. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  3062. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  3063. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  3064. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  3065. * `upperFirst`, `value`, and `words`
  3066. *
  3067. * @name _
  3068. * @constructor
  3069. * @category Seq
  3070. * @param {*} value The value to wrap in a `lodash` instance.
  3071. * @returns {Object} Returns the new `lodash` wrapper instance.
  3072. * @example
  3073. *
  3074. * function square(n) {
  3075. * return n * n;
  3076. * }
  3077. *
  3078. * var wrapped = _([1, 2, 3]);
  3079. *
  3080. * // Returns an unwrapped value.
  3081. * wrapped.reduce(_.add);
  3082. * // => 6
  3083. *
  3084. * // Returns a wrapped value.
  3085. * var squares = wrapped.map(square);
  3086. *
  3087. * _.isArray(squares);
  3088. * // => false
  3089. *
  3090. * _.isArray(squares.value());
  3091. * // => true
  3092. */
  3093. function lodash(value) {
  3094. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  3095. if (value instanceof LodashWrapper) {
  3096. return value;
  3097. }
  3098. if (hasOwnProperty.call(value, '__wrapped__')) {
  3099. return wrapperClone(value);
  3100. }
  3101. }
  3102. return new LodashWrapper(value);
  3103. }
  3104. /**
  3105. * The base implementation of `_.create` without support for assigning
  3106. * properties to the created object.
  3107. *
  3108. * @private
  3109. * @param {Object} proto The object to inherit from.
  3110. * @returns {Object} Returns the new object.
  3111. */
  3112. var baseCreate = (function() {
  3113. function object() {}
  3114. return function(proto) {
  3115. if (!isObject(proto)) {
  3116. return {};
  3117. }
  3118. if (objectCreate) {
  3119. return objectCreate(proto);
  3120. }
  3121. object.prototype = proto;
  3122. var result = new object;
  3123. object.prototype = undefined;
  3124. return result;
  3125. };
  3126. }());
  3127. /**
  3128. * The function whose prototype chain sequence wrappers inherit from.
  3129. *
  3130. * @private
  3131. */
  3132. function baseLodash() {
  3133. // No operation performed.
  3134. }
  3135. /**
  3136. * The base constructor for creating `lodash` wrapper objects.
  3137. *
  3138. * @private
  3139. * @param {*} value The value to wrap.
  3140. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  3141. */
  3142. function LodashWrapper(value, chainAll) {
  3143. this.__wrapped__ = value;
  3144. this.__actions__ = [];
  3145. this.__chain__ = !!chainAll;
  3146. this.__index__ = 0;
  3147. this.__values__ = undefined;
  3148. }
  3149. /**
  3150. * By default, the template delimiters used by lodash are like those in
  3151. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  3152. * following template settings to use alternative delimiters.
  3153. *
  3154. * @static
  3155. * @memberOf _
  3156. * @type {Object}
  3157. */
  3158. lodash.templateSettings = {
  3159. /**
  3160. * Used to detect `data` property values to be HTML-escaped.
  3161. *
  3162. * @memberOf _.templateSettings
  3163. * @type {RegExp}
  3164. */
  3165. 'escape': reEscape,
  3166. /**
  3167. * Used to detect code to be evaluated.
  3168. *
  3169. * @memberOf _.templateSettings
  3170. * @type {RegExp}
  3171. */
  3172. 'evaluate': reEvaluate,
  3173. /**
  3174. * Used to detect `data` property values to inject.
  3175. *
  3176. * @memberOf _.templateSettings
  3177. * @type {RegExp}
  3178. */
  3179. 'interpolate': reInterpolate,
  3180. /**
  3181. * Used to reference the data object in the template text.
  3182. *
  3183. * @memberOf _.templateSettings
  3184. * @type {string}
  3185. */
  3186. 'variable': '',
  3187. /**
  3188. * Used to import variables into the compiled template.
  3189. *
  3190. * @memberOf _.templateSettings
  3191. * @type {Object}
  3192. */
  3193. 'imports': {
  3194. /**
  3195. * A reference to the `lodash` function.
  3196. *
  3197. * @memberOf _.templateSettings.imports
  3198. * @type {Function}
  3199. */
  3200. '_': lodash
  3201. }
  3202. };
  3203. // Ensure wrappers are instances of `baseLodash`.
  3204. lodash.prototype = baseLodash.prototype;
  3205. lodash.prototype.constructor = lodash;
  3206. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  3207. LodashWrapper.prototype.constructor = LodashWrapper;
  3208. /*------------------------------------------------------------------------*/
  3209. /**
  3210. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  3211. *
  3212. * @private
  3213. * @constructor
  3214. * @param {*} value The value to wrap.
  3215. */
  3216. function LazyWrapper(value) {
  3217. this.__wrapped__ = value;
  3218. this.__actions__ = [];
  3219. this.__dir__ = 1;
  3220. this.__filtered__ = false;
  3221. this.__iteratees__ = [];
  3222. this.__takeCount__ = MAX_ARRAY_LENGTH;
  3223. this.__views__ = [];
  3224. }
  3225. /**
  3226. * Creates a clone of the lazy wrapper object.
  3227. *
  3228. * @private
  3229. * @name clone
  3230. * @memberOf LazyWrapper
  3231. * @returns {Object} Returns the cloned `LazyWrapper` object.
  3232. */
  3233. function lazyClone() {
  3234. var result = new LazyWrapper(this.__wrapped__);
  3235. result.__actions__ = copyArray(this.__actions__);
  3236. result.__dir__ = this.__dir__;
  3237. result.__filtered__ = this.__filtered__;
  3238. result.__iteratees__ = copyArray(this.__iteratees__);
  3239. result.__takeCount__ = this.__takeCount__;
  3240. result.__views__ = copyArray(this.__views__);
  3241. return result;
  3242. }
  3243. /**
  3244. * Reverses the direction of lazy iteration.
  3245. *
  3246. * @private
  3247. * @name reverse
  3248. * @memberOf LazyWrapper
  3249. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  3250. */
  3251. function lazyReverse() {
  3252. if (this.__filtered__) {
  3253. var result = new LazyWrapper(this);
  3254. result.__dir__ = -1;
  3255. result.__filtered__ = true;
  3256. } else {
  3257. result = this.clone();
  3258. result.__dir__ *= -1;
  3259. }
  3260. return result;
  3261. }
  3262. /**
  3263. * Extracts the unwrapped value from its lazy wrapper.
  3264. *
  3265. * @private
  3266. * @name value
  3267. * @memberOf LazyWrapper
  3268. * @returns {*} Returns the unwrapped value.
  3269. */
  3270. function lazyValue() {
  3271. var array = this.__wrapped__.value(),
  3272. dir = this.__dir__,
  3273. isArr = isArray(array),
  3274. isRight = dir < 0,
  3275. arrLength = isArr ? array.length : 0,
  3276. view = getView(0, arrLength, this.__views__),
  3277. start = view.start,
  3278. end = view.end,
  3279. length = end - start,
  3280. index = isRight ? end : (start - 1),
  3281. iteratees = this.__iteratees__,
  3282. iterLength = iteratees.length,
  3283. resIndex = 0,
  3284. takeCount = nativeMin(length, this.__takeCount__);
  3285. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  3286. return baseWrapperValue(array, this.__actions__);
  3287. }
  3288. var result = [];
  3289. outer:
  3290. while (length-- && resIndex < takeCount) {
  3291. index += dir;
  3292. var iterIndex = -1,
  3293. value = array[index];
  3294. while (++iterIndex < iterLength) {
  3295. var data = iteratees[iterIndex],
  3296. iteratee = data.iteratee,
  3297. type = data.type,
  3298. computed = iteratee(value);
  3299. if (type == LAZY_MAP_FLAG) {
  3300. value = computed;
  3301. } else if (!computed) {
  3302. if (type == LAZY_FILTER_FLAG) {
  3303. continue outer;
  3304. } else {
  3305. break outer;
  3306. }
  3307. }
  3308. }
  3309. result[resIndex++] = value;
  3310. }
  3311. return result;
  3312. }
  3313. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  3314. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  3315. LazyWrapper.prototype.constructor = LazyWrapper;
  3316. /*------------------------------------------------------------------------*/
  3317. /**
  3318. * Creates a hash object.
  3319. *
  3320. * @private
  3321. * @constructor
  3322. * @param {Array} [entries] The key-value pairs to cache.
  3323. */
  3324. function Hash(entries) {
  3325. var index = -1,
  3326. length = entries == null ? 0 : entries.length;
  3327. this.clear();
  3328. while (++index < length) {
  3329. var entry = entries[index];
  3330. this.set(entry[0], entry[1]);
  3331. }
  3332. }
  3333. /**
  3334. * Removes all key-value entries from the hash.
  3335. *
  3336. * @private
  3337. * @name clear
  3338. * @memberOf Hash
  3339. */
  3340. function hashClear() {
  3341. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  3342. this.size = 0;
  3343. }
  3344. /**
  3345. * Removes `key` and its value from the hash.
  3346. *
  3347. * @private
  3348. * @name delete
  3349. * @memberOf Hash
  3350. * @param {Object} hash The hash to modify.
  3351. * @param {string} key The key of the value to remove.
  3352. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3353. */
  3354. function hashDelete(key) {
  3355. var result = this.has(key) && delete this.__data__[key];
  3356. this.size -= result ? 1 : 0;
  3357. return result;
  3358. }
  3359. /**
  3360. * Gets the hash value for `key`.
  3361. *
  3362. * @private
  3363. * @name get
  3364. * @memberOf Hash
  3365. * @param {string} key The key of the value to get.
  3366. * @returns {*} Returns the entry value.
  3367. */
  3368. function hashGet(key) {
  3369. var data = this.__data__;
  3370. if (nativeCreate) {
  3371. var result = data[key];
  3372. return result === HASH_UNDEFINED ? undefined : result;
  3373. }
  3374. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  3375. }
  3376. /**
  3377. * Checks if a hash value for `key` exists.
  3378. *
  3379. * @private
  3380. * @name has
  3381. * @memberOf Hash
  3382. * @param {string} key The key of the entry to check.
  3383. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3384. */
  3385. function hashHas(key) {
  3386. var data = this.__data__;
  3387. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  3388. }
  3389. /**
  3390. * Sets the hash `key` to `value`.
  3391. *
  3392. * @private
  3393. * @name set
  3394. * @memberOf Hash
  3395. * @param {string} key The key of the value to set.
  3396. * @param {*} value The value to set.
  3397. * @returns {Object} Returns the hash instance.
  3398. */
  3399. function hashSet(key, value) {
  3400. var data = this.__data__;
  3401. this.size += this.has(key) ? 0 : 1;
  3402. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  3403. return this;
  3404. }
  3405. // Add methods to `Hash`.
  3406. Hash.prototype.clear = hashClear;
  3407. Hash.prototype['delete'] = hashDelete;
  3408. Hash.prototype.get = hashGet;
  3409. Hash.prototype.has = hashHas;
  3410. Hash.prototype.set = hashSet;
  3411. /*------------------------------------------------------------------------*/
  3412. /**
  3413. * Creates an list cache object.
  3414. *
  3415. * @private
  3416. * @constructor
  3417. * @param {Array} [entries] The key-value pairs to cache.
  3418. */
  3419. function ListCache(entries) {
  3420. var index = -1,
  3421. length = entries == null ? 0 : entries.length;
  3422. this.clear();
  3423. while (++index < length) {
  3424. var entry = entries[index];
  3425. this.set(entry[0], entry[1]);
  3426. }
  3427. }
  3428. /**
  3429. * Removes all key-value entries from the list cache.
  3430. *
  3431. * @private
  3432. * @name clear
  3433. * @memberOf ListCache
  3434. */
  3435. function listCacheClear() {
  3436. this.__data__ = [];
  3437. this.size = 0;
  3438. }
  3439. /**
  3440. * Removes `key` and its value from the list cache.
  3441. *
  3442. * @private
  3443. * @name delete
  3444. * @memberOf ListCache
  3445. * @param {string} key The key of the value to remove.
  3446. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3447. */
  3448. function listCacheDelete(key) {
  3449. var data = this.__data__,
  3450. index = assocIndexOf(data, key);
  3451. if (index < 0) {
  3452. return false;
  3453. }
  3454. var lastIndex = data.length - 1;
  3455. if (index == lastIndex) {
  3456. data.pop();
  3457. } else {
  3458. splice.call(data, index, 1);
  3459. }
  3460. --this.size;
  3461. return true;
  3462. }
  3463. /**
  3464. * Gets the list cache value for `key`.
  3465. *
  3466. * @private
  3467. * @name get
  3468. * @memberOf ListCache
  3469. * @param {string} key The key of the value to get.
  3470. * @returns {*} Returns the entry value.
  3471. */
  3472. function listCacheGet(key) {
  3473. var data = this.__data__,
  3474. index = assocIndexOf(data, key);
  3475. return index < 0 ? undefined : data[index][1];
  3476. }
  3477. /**
  3478. * Checks if a list cache value for `key` exists.
  3479. *
  3480. * @private
  3481. * @name has
  3482. * @memberOf ListCache
  3483. * @param {string} key The key of the entry to check.
  3484. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3485. */
  3486. function listCacheHas(key) {
  3487. return assocIndexOf(this.__data__, key) > -1;
  3488. }
  3489. /**
  3490. * Sets the list cache `key` to `value`.
  3491. *
  3492. * @private
  3493. * @name set
  3494. * @memberOf ListCache
  3495. * @param {string} key The key of the value to set.
  3496. * @param {*} value The value to set.
  3497. * @returns {Object} Returns the list cache instance.
  3498. */
  3499. function listCacheSet(key, value) {
  3500. var data = this.__data__,
  3501. index = assocIndexOf(data, key);
  3502. if (index < 0) {
  3503. ++this.size;
  3504. data.push([key, value]);
  3505. } else {
  3506. data[index][1] = value;
  3507. }
  3508. return this;
  3509. }
  3510. // Add methods to `ListCache`.
  3511. ListCache.prototype.clear = listCacheClear;
  3512. ListCache.prototype['delete'] = listCacheDelete;
  3513. ListCache.prototype.get = listCacheGet;
  3514. ListCache.prototype.has = listCacheHas;
  3515. ListCache.prototype.set = listCacheSet;
  3516. /*------------------------------------------------------------------------*/
  3517. /**
  3518. * Creates a map cache object to store key-value pairs.
  3519. *
  3520. * @private
  3521. * @constructor
  3522. * @param {Array} [entries] The key-value pairs to cache.
  3523. */
  3524. function MapCache(entries) {
  3525. var index = -1,
  3526. length = entries == null ? 0 : entries.length;
  3527. this.clear();
  3528. while (++index < length) {
  3529. var entry = entries[index];
  3530. this.set(entry[0], entry[1]);
  3531. }
  3532. }
  3533. /**
  3534. * Removes all key-value entries from the map.
  3535. *
  3536. * @private
  3537. * @name clear
  3538. * @memberOf MapCache
  3539. */
  3540. function mapCacheClear() {
  3541. this.size = 0;
  3542. this.__data__ = {
  3543. 'hash': new Hash,
  3544. 'map': new (Map || ListCache),
  3545. 'string': new Hash
  3546. };
  3547. }
  3548. /**
  3549. * Removes `key` and its value from the map.
  3550. *
  3551. * @private
  3552. * @name delete
  3553. * @memberOf MapCache
  3554. * @param {string} key The key of the value to remove.
  3555. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3556. */
  3557. function mapCacheDelete(key) {
  3558. var result = getMapData(this, key)['delete'](key);
  3559. this.size -= result ? 1 : 0;
  3560. return result;
  3561. }
  3562. /**
  3563. * Gets the map value for `key`.
  3564. *
  3565. * @private
  3566. * @name get
  3567. * @memberOf MapCache
  3568. * @param {string} key The key of the value to get.
  3569. * @returns {*} Returns the entry value.
  3570. */
  3571. function mapCacheGet(key) {
  3572. return getMapData(this, key).get(key);
  3573. }
  3574. /**
  3575. * Checks if a map value for `key` exists.
  3576. *
  3577. * @private
  3578. * @name has
  3579. * @memberOf MapCache
  3580. * @param {string} key The key of the entry to check.
  3581. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3582. */
  3583. function mapCacheHas(key) {
  3584. return getMapData(this, key).has(key);
  3585. }
  3586. /**
  3587. * Sets the map `key` to `value`.
  3588. *
  3589. * @private
  3590. * @name set
  3591. * @memberOf MapCache
  3592. * @param {string} key The key of the value to set.
  3593. * @param {*} value The value to set.
  3594. * @returns {Object} Returns the map cache instance.
  3595. */
  3596. function mapCacheSet(key, value) {
  3597. var data = getMapData(this, key),
  3598. size = data.size;
  3599. data.set(key, value);
  3600. this.size += data.size == size ? 0 : 1;
  3601. return this;
  3602. }
  3603. // Add methods to `MapCache`.
  3604. MapCache.prototype.clear = mapCacheClear;
  3605. MapCache.prototype['delete'] = mapCacheDelete;
  3606. MapCache.prototype.get = mapCacheGet;
  3607. MapCache.prototype.has = mapCacheHas;
  3608. MapCache.prototype.set = mapCacheSet;
  3609. /*------------------------------------------------------------------------*/
  3610. /**
  3611. *
  3612. * Creates an array cache object to store unique values.
  3613. *
  3614. * @private
  3615. * @constructor
  3616. * @param {Array} [values] The values to cache.
  3617. */
  3618. function SetCache(values) {
  3619. var index = -1,
  3620. length = values == null ? 0 : values.length;
  3621. this.__data__ = new MapCache;
  3622. while (++index < length) {
  3623. this.add(values[index]);
  3624. }
  3625. }
  3626. /**
  3627. * Adds `value` to the array cache.
  3628. *
  3629. * @private
  3630. * @name add
  3631. * @memberOf SetCache
  3632. * @alias push
  3633. * @param {*} value The value to cache.
  3634. * @returns {Object} Returns the cache instance.
  3635. */
  3636. function setCacheAdd(value) {
  3637. this.__data__.set(value, HASH_UNDEFINED);
  3638. return this;
  3639. }
  3640. /**
  3641. * Checks if `value` is in the array cache.
  3642. *
  3643. * @private
  3644. * @name has
  3645. * @memberOf SetCache
  3646. * @param {*} value The value to search for.
  3647. * @returns {number} Returns `true` if `value` is found, else `false`.
  3648. */
  3649. function setCacheHas(value) {
  3650. return this.__data__.has(value);
  3651. }
  3652. // Add methods to `SetCache`.
  3653. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  3654. SetCache.prototype.has = setCacheHas;
  3655. /*------------------------------------------------------------------------*/
  3656. /**
  3657. * Creates a stack cache object to store key-value pairs.
  3658. *
  3659. * @private
  3660. * @constructor
  3661. * @param {Array} [entries] The key-value pairs to cache.
  3662. */
  3663. function Stack(entries) {
  3664. var data = this.__data__ = new ListCache(entries);
  3665. this.size = data.size;
  3666. }
  3667. /**
  3668. * Removes all key-value entries from the stack.
  3669. *
  3670. * @private
  3671. * @name clear
  3672. * @memberOf Stack
  3673. */
  3674. function stackClear() {
  3675. this.__data__ = new ListCache;
  3676. this.size = 0;
  3677. }
  3678. /**
  3679. * Removes `key` and its value from the stack.
  3680. *
  3681. * @private
  3682. * @name delete
  3683. * @memberOf Stack
  3684. * @param {string} key The key of the value to remove.
  3685. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  3686. */
  3687. function stackDelete(key) {
  3688. var data = this.__data__,
  3689. result = data['delete'](key);
  3690. this.size = data.size;
  3691. return result;
  3692. }
  3693. /**
  3694. * Gets the stack value for `key`.
  3695. *
  3696. * @private
  3697. * @name get
  3698. * @memberOf Stack
  3699. * @param {string} key The key of the value to get.
  3700. * @returns {*} Returns the entry value.
  3701. */
  3702. function stackGet(key) {
  3703. return this.__data__.get(key);
  3704. }
  3705. /**
  3706. * Checks if a stack value for `key` exists.
  3707. *
  3708. * @private
  3709. * @name has
  3710. * @memberOf Stack
  3711. * @param {string} key The key of the entry to check.
  3712. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  3713. */
  3714. function stackHas(key) {
  3715. return this.__data__.has(key);
  3716. }
  3717. /**
  3718. * Sets the stack `key` to `value`.
  3719. *
  3720. * @private
  3721. * @name set
  3722. * @memberOf Stack
  3723. * @param {string} key The key of the value to set.
  3724. * @param {*} value The value to set.
  3725. * @returns {Object} Returns the stack cache instance.
  3726. */
  3727. function stackSet(key, value) {
  3728. var data = this.__data__;
  3729. if (data instanceof ListCache) {
  3730. var pairs = data.__data__;
  3731. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  3732. pairs.push([key, value]);
  3733. this.size = ++data.size;
  3734. return this;
  3735. }
  3736. data = this.__data__ = new MapCache(pairs);
  3737. }
  3738. data.set(key, value);
  3739. this.size = data.size;
  3740. return this;
  3741. }
  3742. // Add methods to `Stack`.
  3743. Stack.prototype.clear = stackClear;
  3744. Stack.prototype['delete'] = stackDelete;
  3745. Stack.prototype.get = stackGet;
  3746. Stack.prototype.has = stackHas;
  3747. Stack.prototype.set = stackSet;
  3748. /*------------------------------------------------------------------------*/
  3749. /**
  3750. * Creates an array of the enumerable property names of the array-like `value`.
  3751. *
  3752. * @private
  3753. * @param {*} value The value to query.
  3754. * @param {boolean} inherited Specify returning inherited property names.
  3755. * @returns {Array} Returns the array of property names.
  3756. */
  3757. function arrayLikeKeys(value, inherited) {
  3758. var isArr = isArray(value),
  3759. isArg = !isArr && isArguments(value),
  3760. isBuff = !isArr && !isArg && isBuffer(value),
  3761. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  3762. skipIndexes = isArr || isArg || isBuff || isType,
  3763. result = skipIndexes ? baseTimes(value.length, String) : [],
  3764. length = result.length;
  3765. for (var key in value) {
  3766. if ((inherited || hasOwnProperty.call(value, key)) &&
  3767. !(skipIndexes && (
  3768. // Safari 9 has enumerable `arguments.length` in strict mode.
  3769. key == 'length' ||
  3770. // Node.js 0.10 has enumerable non-index properties on buffers.
  3771. (isBuff && (key == 'offset' || key == 'parent')) ||
  3772. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  3773. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  3774. // Skip index properties.
  3775. isIndex(key, length)
  3776. ))) {
  3777. result.push(key);
  3778. }
  3779. }
  3780. return result;
  3781. }
  3782. /**
  3783. * A specialized version of `_.sample` for arrays.
  3784. *
  3785. * @private
  3786. * @param {Array} array The array to sample.
  3787. * @returns {*} Returns the random element.
  3788. */
  3789. function arraySample(array) {
  3790. var length = array.length;
  3791. return length ? array[baseRandom(0, length - 1)] : undefined;
  3792. }
  3793. /**
  3794. * A specialized version of `_.sampleSize` for arrays.
  3795. *
  3796. * @private
  3797. * @param {Array} array The array to sample.
  3798. * @param {number} n The number of elements to sample.
  3799. * @returns {Array} Returns the random elements.
  3800. */
  3801. function arraySampleSize(array, n) {
  3802. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  3803. }
  3804. /**
  3805. * A specialized version of `_.shuffle` for arrays.
  3806. *
  3807. * @private
  3808. * @param {Array} array The array to shuffle.
  3809. * @returns {Array} Returns the new shuffled array.
  3810. */
  3811. function arrayShuffle(array) {
  3812. return shuffleSelf(copyArray(array));
  3813. }
  3814. /**
  3815. * This function is like `assignValue` except that it doesn't assign
  3816. * `undefined` values.
  3817. *
  3818. * @private
  3819. * @param {Object} object The object to modify.
  3820. * @param {string} key The key of the property to assign.
  3821. * @param {*} value The value to assign.
  3822. */
  3823. function assignMergeValue(object, key, value) {
  3824. if ((value !== undefined && !eq(object[key], value)) ||
  3825. (value === undefined && !(key in object))) {
  3826. baseAssignValue(object, key, value);
  3827. }
  3828. }
  3829. /**
  3830. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  3831. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  3832. * for equality comparisons.
  3833. *
  3834. * @private
  3835. * @param {Object} object The object to modify.
  3836. * @param {string} key The key of the property to assign.
  3837. * @param {*} value The value to assign.
  3838. */
  3839. function assignValue(object, key, value) {
  3840. var objValue = object[key];
  3841. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  3842. (value === undefined && !(key in object))) {
  3843. baseAssignValue(object, key, value);
  3844. }
  3845. }
  3846. /**
  3847. * Gets the index at which the `key` is found in `array` of key-value pairs.
  3848. *
  3849. * @private
  3850. * @param {Array} array The array to inspect.
  3851. * @param {*} key The key to search for.
  3852. * @returns {number} Returns the index of the matched value, else `-1`.
  3853. */
  3854. function assocIndexOf(array, key) {
  3855. var length = array.length;
  3856. while (length--) {
  3857. if (eq(array[length][0], key)) {
  3858. return length;
  3859. }
  3860. }
  3861. return -1;
  3862. }
  3863. /**
  3864. * Aggregates elements of `collection` on `accumulator` with keys transformed
  3865. * by `iteratee` and values set by `setter`.
  3866. *
  3867. * @private
  3868. * @param {Array|Object} collection The collection to iterate over.
  3869. * @param {Function} setter The function to set `accumulator` values.
  3870. * @param {Function} iteratee The iteratee to transform keys.
  3871. * @param {Object} accumulator The initial aggregated object.
  3872. * @returns {Function} Returns `accumulator`.
  3873. */
  3874. function baseAggregator(collection, setter, iteratee, accumulator) {
  3875. baseEach(collection, function(value, key, collection) {
  3876. setter(accumulator, value, iteratee(value), collection);
  3877. });
  3878. return accumulator;
  3879. }
  3880. /**
  3881. * The base implementation of `_.assign` without support for multiple sources
  3882. * or `customizer` functions.
  3883. *
  3884. * @private
  3885. * @param {Object} object The destination object.
  3886. * @param {Object} source The source object.
  3887. * @returns {Object} Returns `object`.
  3888. */
  3889. function baseAssign(object, source) {
  3890. return object && copyObject(source, keys(source), object);
  3891. }
  3892. /**
  3893. * The base implementation of `_.assignIn` without support for multiple sources
  3894. * or `customizer` functions.
  3895. *
  3896. * @private
  3897. * @param {Object} object The destination object.
  3898. * @param {Object} source The source object.
  3899. * @returns {Object} Returns `object`.
  3900. */
  3901. function baseAssignIn(object, source) {
  3902. return object && copyObject(source, keysIn(source), object);
  3903. }
  3904. /**
  3905. * The base implementation of `assignValue` and `assignMergeValue` without
  3906. * value checks.
  3907. *
  3908. * @private
  3909. * @param {Object} object The object to modify.
  3910. * @param {string} key The key of the property to assign.
  3911. * @param {*} value The value to assign.
  3912. */
  3913. function baseAssignValue(object, key, value) {
  3914. if (key == '__proto__' && defineProperty) {
  3915. defineProperty(object, key, {
  3916. 'configurable': true,
  3917. 'enumerable': true,
  3918. 'value': value,
  3919. 'writable': true
  3920. });
  3921. } else {
  3922. object[key] = value;
  3923. }
  3924. }
  3925. /**
  3926. * The base implementation of `_.at` without support for individual paths.
  3927. *
  3928. * @private
  3929. * @param {Object} object The object to iterate over.
  3930. * @param {string[]} paths The property paths to pick.
  3931. * @returns {Array} Returns the picked elements.
  3932. */
  3933. function baseAt(object, paths) {
  3934. var index = -1,
  3935. length = paths.length,
  3936. result = Array(length),
  3937. skip = object == null;
  3938. while (++index < length) {
  3939. result[index] = skip ? undefined : get(object, paths[index]);
  3940. }
  3941. return result;
  3942. }
  3943. /**
  3944. * The base implementation of `_.clamp` which doesn't coerce arguments.
  3945. *
  3946. * @private
  3947. * @param {number} number The number to clamp.
  3948. * @param {number} [lower] The lower bound.
  3949. * @param {number} upper The upper bound.
  3950. * @returns {number} Returns the clamped number.
  3951. */
  3952. function baseClamp(number, lower, upper) {
  3953. if (number === number) {
  3954. if (upper !== undefined) {
  3955. number = number <= upper ? number : upper;
  3956. }
  3957. if (lower !== undefined) {
  3958. number = number >= lower ? number : lower;
  3959. }
  3960. }
  3961. return number;
  3962. }
  3963. /**
  3964. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  3965. * traversed objects.
  3966. *
  3967. * @private
  3968. * @param {*} value The value to clone.
  3969. * @param {boolean} bitmask The bitmask flags.
  3970. * 1 - Deep clone
  3971. * 2 - Flatten inherited properties
  3972. * 4 - Clone symbols
  3973. * @param {Function} [customizer] The function to customize cloning.
  3974. * @param {string} [key] The key of `value`.
  3975. * @param {Object} [object] The parent object of `value`.
  3976. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  3977. * @returns {*} Returns the cloned value.
  3978. */
  3979. function baseClone(value, bitmask, customizer, key, object, stack) {
  3980. var result,
  3981. isDeep = bitmask & CLONE_DEEP_FLAG,
  3982. isFlat = bitmask & CLONE_FLAT_FLAG,
  3983. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  3984. if (customizer) {
  3985. result = object ? customizer(value, key, object, stack) : customizer(value);
  3986. }
  3987. if (result !== undefined) {
  3988. return result;
  3989. }
  3990. if (!isObject(value)) {
  3991. return value;
  3992. }
  3993. var isArr = isArray(value);
  3994. if (isArr) {
  3995. result = initCloneArray(value);
  3996. if (!isDeep) {
  3997. return copyArray(value, result);
  3998. }
  3999. } else {
  4000. var tag = getTag(value),
  4001. isFunc = tag == funcTag || tag == genTag;
  4002. if (isBuffer(value)) {
  4003. return cloneBuffer(value, isDeep);
  4004. }
  4005. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  4006. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  4007. if (!isDeep) {
  4008. return isFlat
  4009. ? copySymbolsIn(value, baseAssignIn(result, value))
  4010. : copySymbols(value, baseAssign(result, value));
  4011. }
  4012. } else {
  4013. if (!cloneableTags[tag]) {
  4014. return object ? value : {};
  4015. }
  4016. result = initCloneByTag(value, tag, isDeep);
  4017. }
  4018. }
  4019. // Check for circular references and return its corresponding clone.
  4020. stack || (stack = new Stack);
  4021. var stacked = stack.get(value);
  4022. if (stacked) {
  4023. return stacked;
  4024. }
  4025. stack.set(value, result);
  4026. if (isSet(value)) {
  4027. value.forEach(function(subValue) {
  4028. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  4029. });
  4030. } else if (isMap(value)) {
  4031. value.forEach(function(subValue, key) {
  4032. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  4033. });
  4034. }
  4035. var keysFunc = isFull
  4036. ? (isFlat ? getAllKeysIn : getAllKeys)
  4037. : (isFlat ? keysIn : keys);
  4038. var props = isArr ? undefined : keysFunc(value);
  4039. arrayEach(props || value, function(subValue, key) {
  4040. if (props) {
  4041. key = subValue;
  4042. subValue = value[key];
  4043. }
  4044. // Recursively populate clone (susceptible to call stack limits).
  4045. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  4046. });
  4047. return result;
  4048. }
  4049. /**
  4050. * The base implementation of `_.conforms` which doesn't clone `source`.
  4051. *
  4052. * @private
  4053. * @param {Object} source The object of property predicates to conform to.
  4054. * @returns {Function} Returns the new spec function.
  4055. */
  4056. function baseConforms(source) {
  4057. var props = keys(source);
  4058. return function(object) {
  4059. return baseConformsTo(object, source, props);
  4060. };
  4061. }
  4062. /**
  4063. * The base implementation of `_.conformsTo` which accepts `props` to check.
  4064. *
  4065. * @private
  4066. * @param {Object} object The object to inspect.
  4067. * @param {Object} source The object of property predicates to conform to.
  4068. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  4069. */
  4070. function baseConformsTo(object, source, props) {
  4071. var length = props.length;
  4072. if (object == null) {
  4073. return !length;
  4074. }
  4075. object = Object(object);
  4076. while (length--) {
  4077. var key = props[length],
  4078. predicate = source[key],
  4079. value = object[key];
  4080. if ((value === undefined && !(key in object)) || !predicate(value)) {
  4081. return false;
  4082. }
  4083. }
  4084. return true;
  4085. }
  4086. /**
  4087. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  4088. * to provide to `func`.
  4089. *
  4090. * @private
  4091. * @param {Function} func The function to delay.
  4092. * @param {number} wait The number of milliseconds to delay invocation.
  4093. * @param {Array} args The arguments to provide to `func`.
  4094. * @returns {number|Object} Returns the timer id or timeout object.
  4095. */
  4096. function baseDelay(func, wait, args) {
  4097. if (typeof func != 'function') {
  4098. throw new TypeError(FUNC_ERROR_TEXT);
  4099. }
  4100. return setTimeout(function() { func.apply(undefined, args); }, wait);
  4101. }
  4102. /**
  4103. * The base implementation of methods like `_.difference` without support
  4104. * for excluding multiple arrays or iteratee shorthands.
  4105. *
  4106. * @private
  4107. * @param {Array} array The array to inspect.
  4108. * @param {Array} values The values to exclude.
  4109. * @param {Function} [iteratee] The iteratee invoked per element.
  4110. * @param {Function} [comparator] The comparator invoked per element.
  4111. * @returns {Array} Returns the new array of filtered values.
  4112. */
  4113. function baseDifference(array, values, iteratee, comparator) {
  4114. var index = -1,
  4115. includes = arrayIncludes,
  4116. isCommon = true,
  4117. length = array.length,
  4118. result = [],
  4119. valuesLength = values.length;
  4120. if (!length) {
  4121. return result;
  4122. }
  4123. if (iteratee) {
  4124. values = arrayMap(values, baseUnary(iteratee));
  4125. }
  4126. if (comparator) {
  4127. includes = arrayIncludesWith;
  4128. isCommon = false;
  4129. }
  4130. else if (values.length >= LARGE_ARRAY_SIZE) {
  4131. includes = cacheHas;
  4132. isCommon = false;
  4133. values = new SetCache(values);
  4134. }
  4135. outer:
  4136. while (++index < length) {
  4137. var value = array[index],
  4138. computed = iteratee == null ? value : iteratee(value);
  4139. value = (comparator || value !== 0) ? value : 0;
  4140. if (isCommon && computed === computed) {
  4141. var valuesIndex = valuesLength;
  4142. while (valuesIndex--) {
  4143. if (values[valuesIndex] === computed) {
  4144. continue outer;
  4145. }
  4146. }
  4147. result.push(value);
  4148. }
  4149. else if (!includes(values, computed, comparator)) {
  4150. result.push(value);
  4151. }
  4152. }
  4153. return result;
  4154. }
  4155. /**
  4156. * The base implementation of `_.forEach` without support for iteratee shorthands.
  4157. *
  4158. * @private
  4159. * @param {Array|Object} collection The collection to iterate over.
  4160. * @param {Function} iteratee The function invoked per iteration.
  4161. * @returns {Array|Object} Returns `collection`.
  4162. */
  4163. var baseEach = createBaseEach(baseForOwn);
  4164. /**
  4165. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  4166. *
  4167. * @private
  4168. * @param {Array|Object} collection The collection to iterate over.
  4169. * @param {Function} iteratee The function invoked per iteration.
  4170. * @returns {Array|Object} Returns `collection`.
  4171. */
  4172. var baseEachRight = createBaseEach(baseForOwnRight, true);
  4173. /**
  4174. * The base implementation of `_.every` without support for iteratee shorthands.
  4175. *
  4176. * @private
  4177. * @param {Array|Object} collection The collection to iterate over.
  4178. * @param {Function} predicate The function invoked per iteration.
  4179. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  4180. * else `false`
  4181. */
  4182. function baseEvery(collection, predicate) {
  4183. var result = true;
  4184. baseEach(collection, function(value, index, collection) {
  4185. result = !!predicate(value, index, collection);
  4186. return result;
  4187. });
  4188. return result;
  4189. }
  4190. /**
  4191. * The base implementation of methods like `_.max` and `_.min` which accepts a
  4192. * `comparator` to determine the extremum value.
  4193. *
  4194. * @private
  4195. * @param {Array} array The array to iterate over.
  4196. * @param {Function} iteratee The iteratee invoked per iteration.
  4197. * @param {Function} comparator The comparator used to compare values.
  4198. * @returns {*} Returns the extremum value.
  4199. */
  4200. function baseExtremum(array, iteratee, comparator) {
  4201. var index = -1,
  4202. length = array.length;
  4203. while (++index < length) {
  4204. var value = array[index],
  4205. current = iteratee(value);
  4206. if (current != null && (computed === undefined
  4207. ? (current === current && !isSymbol(current))
  4208. : comparator(current, computed)
  4209. )) {
  4210. var computed = current,
  4211. result = value;
  4212. }
  4213. }
  4214. return result;
  4215. }
  4216. /**
  4217. * The base implementation of `_.fill` without an iteratee call guard.
  4218. *
  4219. * @private
  4220. * @param {Array} array The array to fill.
  4221. * @param {*} value The value to fill `array` with.
  4222. * @param {number} [start=0] The start position.
  4223. * @param {number} [end=array.length] The end position.
  4224. * @returns {Array} Returns `array`.
  4225. */
  4226. function baseFill(array, value, start, end) {
  4227. var length = array.length;
  4228. start = toInteger(start);
  4229. if (start < 0) {
  4230. start = -start > length ? 0 : (length + start);
  4231. }
  4232. end = (end === undefined || end > length) ? length : toInteger(end);
  4233. if (end < 0) {
  4234. end += length;
  4235. }
  4236. end = start > end ? 0 : toLength(end);
  4237. while (start < end) {
  4238. array[start++] = value;
  4239. }
  4240. return array;
  4241. }
  4242. /**
  4243. * The base implementation of `_.filter` without support for iteratee shorthands.
  4244. *
  4245. * @private
  4246. * @param {Array|Object} collection The collection to iterate over.
  4247. * @param {Function} predicate The function invoked per iteration.
  4248. * @returns {Array} Returns the new filtered array.
  4249. */
  4250. function baseFilter(collection, predicate) {
  4251. var result = [];
  4252. baseEach(collection, function(value, index, collection) {
  4253. if (predicate(value, index, collection)) {
  4254. result.push(value);
  4255. }
  4256. });
  4257. return result;
  4258. }
  4259. /**
  4260. * The base implementation of `_.flatten` with support for restricting flattening.
  4261. *
  4262. * @private
  4263. * @param {Array} array The array to flatten.
  4264. * @param {number} depth The maximum recursion depth.
  4265. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  4266. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  4267. * @param {Array} [result=[]] The initial result value.
  4268. * @returns {Array} Returns the new flattened array.
  4269. */
  4270. function baseFlatten(array, depth, predicate, isStrict, result) {
  4271. var index = -1,
  4272. length = array.length;
  4273. predicate || (predicate = isFlattenable);
  4274. result || (result = []);
  4275. while (++index < length) {
  4276. var value = array[index];
  4277. if (depth > 0 && predicate(value)) {
  4278. if (depth > 1) {
  4279. // Recursively flatten arrays (susceptible to call stack limits).
  4280. baseFlatten(value, depth - 1, predicate, isStrict, result);
  4281. } else {
  4282. arrayPush(result, value);
  4283. }
  4284. } else if (!isStrict) {
  4285. result[result.length] = value;
  4286. }
  4287. }
  4288. return result;
  4289. }
  4290. /**
  4291. * The base implementation of `baseForOwn` which iterates over `object`
  4292. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  4293. * Iteratee functions may exit iteration early by explicitly returning `false`.
  4294. *
  4295. * @private
  4296. * @param {Object} object The object to iterate over.
  4297. * @param {Function} iteratee The function invoked per iteration.
  4298. * @param {Function} keysFunc The function to get the keys of `object`.
  4299. * @returns {Object} Returns `object`.
  4300. */
  4301. var baseFor = createBaseFor();
  4302. /**
  4303. * This function is like `baseFor` except that it iterates over properties
  4304. * in the opposite order.
  4305. *
  4306. * @private
  4307. * @param {Object} object The object to iterate over.
  4308. * @param {Function} iteratee The function invoked per iteration.
  4309. * @param {Function} keysFunc The function to get the keys of `object`.
  4310. * @returns {Object} Returns `object`.
  4311. */
  4312. var baseForRight = createBaseFor(true);
  4313. /**
  4314. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  4315. *
  4316. * @private
  4317. * @param {Object} object The object to iterate over.
  4318. * @param {Function} iteratee The function invoked per iteration.
  4319. * @returns {Object} Returns `object`.
  4320. */
  4321. function baseForOwn(object, iteratee) {
  4322. return object && baseFor(object, iteratee, keys);
  4323. }
  4324. /**
  4325. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  4326. *
  4327. * @private
  4328. * @param {Object} object The object to iterate over.
  4329. * @param {Function} iteratee The function invoked per iteration.
  4330. * @returns {Object} Returns `object`.
  4331. */
  4332. function baseForOwnRight(object, iteratee) {
  4333. return object && baseForRight(object, iteratee, keys);
  4334. }
  4335. /**
  4336. * The base implementation of `_.functions` which creates an array of
  4337. * `object` function property names filtered from `props`.
  4338. *
  4339. * @private
  4340. * @param {Object} object The object to inspect.
  4341. * @param {Array} props The property names to filter.
  4342. * @returns {Array} Returns the function names.
  4343. */
  4344. function baseFunctions(object, props) {
  4345. return arrayFilter(props, function(key) {
  4346. return isFunction(object[key]);
  4347. });
  4348. }
  4349. /**
  4350. * The base implementation of `_.get` without support for default values.
  4351. *
  4352. * @private
  4353. * @param {Object} object The object to query.
  4354. * @param {Array|string} path The path of the property to get.
  4355. * @returns {*} Returns the resolved value.
  4356. */
  4357. function baseGet(object, path) {
  4358. path = castPath(path, object);
  4359. var index = 0,
  4360. length = path.length;
  4361. while (object != null && index < length) {
  4362. object = object[toKey(path[index++])];
  4363. }
  4364. return (index && index == length) ? object : undefined;
  4365. }
  4366. /**
  4367. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  4368. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  4369. * symbols of `object`.
  4370. *
  4371. * @private
  4372. * @param {Object} object The object to query.
  4373. * @param {Function} keysFunc The function to get the keys of `object`.
  4374. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  4375. * @returns {Array} Returns the array of property names and symbols.
  4376. */
  4377. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  4378. var result = keysFunc(object);
  4379. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  4380. }
  4381. /**
  4382. * The base implementation of `getTag` without fallbacks for buggy environments.
  4383. *
  4384. * @private
  4385. * @param {*} value The value to query.
  4386. * @returns {string} Returns the `toStringTag`.
  4387. */
  4388. function baseGetTag(value) {
  4389. if (value == null) {
  4390. return value === undefined ? undefinedTag : nullTag;
  4391. }
  4392. return (symToStringTag && symToStringTag in Object(value))
  4393. ? getRawTag(value)
  4394. : objectToString(value);
  4395. }
  4396. /**
  4397. * The base implementation of `_.gt` which doesn't coerce arguments.
  4398. *
  4399. * @private
  4400. * @param {*} value The value to compare.
  4401. * @param {*} other The other value to compare.
  4402. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  4403. * else `false`.
  4404. */
  4405. function baseGt(value, other) {
  4406. return value > other;
  4407. }
  4408. /**
  4409. * The base implementation of `_.has` without support for deep paths.
  4410. *
  4411. * @private
  4412. * @param {Object} [object] The object to query.
  4413. * @param {Array|string} key The key to check.
  4414. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  4415. */
  4416. function baseHas(object, key) {
  4417. return object != null && hasOwnProperty.call(object, key);
  4418. }
  4419. /**
  4420. * The base implementation of `_.hasIn` without support for deep paths.
  4421. *
  4422. * @private
  4423. * @param {Object} [object] The object to query.
  4424. * @param {Array|string} key The key to check.
  4425. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  4426. */
  4427. function baseHasIn(object, key) {
  4428. return object != null && key in Object(object);
  4429. }
  4430. /**
  4431. * The base implementation of `_.inRange` which doesn't coerce arguments.
  4432. *
  4433. * @private
  4434. * @param {number} number The number to check.
  4435. * @param {number} start The start of the range.
  4436. * @param {number} end The end of the range.
  4437. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  4438. */
  4439. function baseInRange(number, start, end) {
  4440. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  4441. }
  4442. /**
  4443. * The base implementation of methods like `_.intersection`, without support
  4444. * for iteratee shorthands, that accepts an array of arrays to inspect.
  4445. *
  4446. * @private
  4447. * @param {Array} arrays The arrays to inspect.
  4448. * @param {Function} [iteratee] The iteratee invoked per element.
  4449. * @param {Function} [comparator] The comparator invoked per element.
  4450. * @returns {Array} Returns the new array of shared values.
  4451. */
  4452. function baseIntersection(arrays, iteratee, comparator) {
  4453. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  4454. length = arrays[0].length,
  4455. othLength = arrays.length,
  4456. othIndex = othLength,
  4457. caches = Array(othLength),
  4458. maxLength = Infinity,
  4459. result = [];
  4460. while (othIndex--) {
  4461. var array = arrays[othIndex];
  4462. if (othIndex && iteratee) {
  4463. array = arrayMap(array, baseUnary(iteratee));
  4464. }
  4465. maxLength = nativeMin(array.length, maxLength);
  4466. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  4467. ? new SetCache(othIndex && array)
  4468. : undefined;
  4469. }
  4470. array = arrays[0];
  4471. var index = -1,
  4472. seen = caches[0];
  4473. outer:
  4474. while (++index < length && result.length < maxLength) {
  4475. var value = array[index],
  4476. computed = iteratee ? iteratee(value) : value;
  4477. value = (comparator || value !== 0) ? value : 0;
  4478. if (!(seen
  4479. ? cacheHas(seen, computed)
  4480. : includes(result, computed, comparator)
  4481. )) {
  4482. othIndex = othLength;
  4483. while (--othIndex) {
  4484. var cache = caches[othIndex];
  4485. if (!(cache
  4486. ? cacheHas(cache, computed)
  4487. : includes(arrays[othIndex], computed, comparator))
  4488. ) {
  4489. continue outer;
  4490. }
  4491. }
  4492. if (seen) {
  4493. seen.push(computed);
  4494. }
  4495. result.push(value);
  4496. }
  4497. }
  4498. return result;
  4499. }
  4500. /**
  4501. * The base implementation of `_.invert` and `_.invertBy` which inverts
  4502. * `object` with values transformed by `iteratee` and set by `setter`.
  4503. *
  4504. * @private
  4505. * @param {Object} object The object to iterate over.
  4506. * @param {Function} setter The function to set `accumulator` values.
  4507. * @param {Function} iteratee The iteratee to transform values.
  4508. * @param {Object} accumulator The initial inverted object.
  4509. * @returns {Function} Returns `accumulator`.
  4510. */
  4511. function baseInverter(object, setter, iteratee, accumulator) {
  4512. baseForOwn(object, function(value, key, object) {
  4513. setter(accumulator, iteratee(value), key, object);
  4514. });
  4515. return accumulator;
  4516. }
  4517. /**
  4518. * The base implementation of `_.invoke` without support for individual
  4519. * method arguments.
  4520. *
  4521. * @private
  4522. * @param {Object} object The object to query.
  4523. * @param {Array|string} path The path of the method to invoke.
  4524. * @param {Array} args The arguments to invoke the method with.
  4525. * @returns {*} Returns the result of the invoked method.
  4526. */
  4527. function baseInvoke(object, path, args) {
  4528. path = castPath(path, object);
  4529. object = parent(object, path);
  4530. var func = object == null ? object : object[toKey(last(path))];
  4531. return func == null ? undefined : apply(func, object, args);
  4532. }
  4533. /**
  4534. * The base implementation of `_.isArguments`.
  4535. *
  4536. * @private
  4537. * @param {*} value The value to check.
  4538. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  4539. */
  4540. function baseIsArguments(value) {
  4541. return isObjectLike(value) && baseGetTag(value) == argsTag;
  4542. }
  4543. /**
  4544. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  4545. *
  4546. * @private
  4547. * @param {*} value The value to check.
  4548. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  4549. */
  4550. function baseIsArrayBuffer(value) {
  4551. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  4552. }
  4553. /**
  4554. * The base implementation of `_.isDate` without Node.js optimizations.
  4555. *
  4556. * @private
  4557. * @param {*} value The value to check.
  4558. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  4559. */
  4560. function baseIsDate(value) {
  4561. return isObjectLike(value) && baseGetTag(value) == dateTag;
  4562. }
  4563. /**
  4564. * The base implementation of `_.isEqual` which supports partial comparisons
  4565. * and tracks traversed objects.
  4566. *
  4567. * @private
  4568. * @param {*} value The value to compare.
  4569. * @param {*} other The other value to compare.
  4570. * @param {boolean} bitmask The bitmask flags.
  4571. * 1 - Unordered comparison
  4572. * 2 - Partial comparison
  4573. * @param {Function} [customizer] The function to customize comparisons.
  4574. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  4575. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  4576. */
  4577. function baseIsEqual(value, other, bitmask, customizer, stack) {
  4578. if (value === other) {
  4579. return true;
  4580. }
  4581. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  4582. return value !== value && other !== other;
  4583. }
  4584. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  4585. }
  4586. /**
  4587. * A specialized version of `baseIsEqual` for arrays and objects which performs
  4588. * deep comparisons and tracks traversed objects enabling objects with circular
  4589. * references to be compared.
  4590. *
  4591. * @private
  4592. * @param {Object} object The object to compare.
  4593. * @param {Object} other The other object to compare.
  4594. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  4595. * @param {Function} customizer The function to customize comparisons.
  4596. * @param {Function} equalFunc The function to determine equivalents of values.
  4597. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  4598. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4599. */
  4600. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  4601. var objIsArr = isArray(object),
  4602. othIsArr = isArray(other),
  4603. objTag = objIsArr ? arrayTag : getTag(object),
  4604. othTag = othIsArr ? arrayTag : getTag(other);
  4605. objTag = objTag == argsTag ? objectTag : objTag;
  4606. othTag = othTag == argsTag ? objectTag : othTag;
  4607. var objIsObj = objTag == objectTag,
  4608. othIsObj = othTag == objectTag,
  4609. isSameTag = objTag == othTag;
  4610. if (isSameTag && isBuffer(object)) {
  4611. if (!isBuffer(other)) {
  4612. return false;
  4613. }
  4614. objIsArr = true;
  4615. objIsObj = false;
  4616. }
  4617. if (isSameTag && !objIsObj) {
  4618. stack || (stack = new Stack);
  4619. return (objIsArr || isTypedArray(object))
  4620. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  4621. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  4622. }
  4623. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  4624. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  4625. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  4626. if (objIsWrapped || othIsWrapped) {
  4627. var objUnwrapped = objIsWrapped ? object.value() : object,
  4628. othUnwrapped = othIsWrapped ? other.value() : other;
  4629. stack || (stack = new Stack);
  4630. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  4631. }
  4632. }
  4633. if (!isSameTag) {
  4634. return false;
  4635. }
  4636. stack || (stack = new Stack);
  4637. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  4638. }
  4639. /**
  4640. * The base implementation of `_.isMap` without Node.js optimizations.
  4641. *
  4642. * @private
  4643. * @param {*} value The value to check.
  4644. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  4645. */
  4646. function baseIsMap(value) {
  4647. return isObjectLike(value) && getTag(value) == mapTag;
  4648. }
  4649. /**
  4650. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  4651. *
  4652. * @private
  4653. * @param {Object} object The object to inspect.
  4654. * @param {Object} source The object of property values to match.
  4655. * @param {Array} matchData The property names, values, and compare flags to match.
  4656. * @param {Function} [customizer] The function to customize comparisons.
  4657. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  4658. */
  4659. function baseIsMatch(object, source, matchData, customizer) {
  4660. var index = matchData.length,
  4661. length = index,
  4662. noCustomizer = !customizer;
  4663. if (object == null) {
  4664. return !length;
  4665. }
  4666. object = Object(object);
  4667. while (index--) {
  4668. var data = matchData[index];
  4669. if ((noCustomizer && data[2])
  4670. ? data[1] !== object[data[0]]
  4671. : !(data[0] in object)
  4672. ) {
  4673. return false;
  4674. }
  4675. }
  4676. while (++index < length) {
  4677. data = matchData[index];
  4678. var key = data[0],
  4679. objValue = object[key],
  4680. srcValue = data[1];
  4681. if (noCustomizer && data[2]) {
  4682. if (objValue === undefined && !(key in object)) {
  4683. return false;
  4684. }
  4685. } else {
  4686. var stack = new Stack;
  4687. if (customizer) {
  4688. var result = customizer(objValue, srcValue, key, object, source, stack);
  4689. }
  4690. if (!(result === undefined
  4691. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  4692. : result
  4693. )) {
  4694. return false;
  4695. }
  4696. }
  4697. }
  4698. return true;
  4699. }
  4700. /**
  4701. * The base implementation of `_.isNative` without bad shim checks.
  4702. *
  4703. * @private
  4704. * @param {*} value The value to check.
  4705. * @returns {boolean} Returns `true` if `value` is a native function,
  4706. * else `false`.
  4707. */
  4708. function baseIsNative(value) {
  4709. if (!isObject(value) || isMasked(value)) {
  4710. return false;
  4711. }
  4712. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  4713. return pattern.test(toSource(value));
  4714. }
  4715. /**
  4716. * The base implementation of `_.isRegExp` without Node.js optimizations.
  4717. *
  4718. * @private
  4719. * @param {*} value The value to check.
  4720. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  4721. */
  4722. function baseIsRegExp(value) {
  4723. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  4724. }
  4725. /**
  4726. * The base implementation of `_.isSet` without Node.js optimizations.
  4727. *
  4728. * @private
  4729. * @param {*} value The value to check.
  4730. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  4731. */
  4732. function baseIsSet(value) {
  4733. return isObjectLike(value) && getTag(value) == setTag;
  4734. }
  4735. /**
  4736. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  4737. *
  4738. * @private
  4739. * @param {*} value The value to check.
  4740. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  4741. */
  4742. function baseIsTypedArray(value) {
  4743. return isObjectLike(value) &&
  4744. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  4745. }
  4746. /**
  4747. * The base implementation of `_.iteratee`.
  4748. *
  4749. * @private
  4750. * @param {*} [value=_.identity] The value to convert to an iteratee.
  4751. * @returns {Function} Returns the iteratee.
  4752. */
  4753. function baseIteratee(value) {
  4754. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  4755. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  4756. if (typeof value == 'function') {
  4757. return value;
  4758. }
  4759. if (value == null) {
  4760. return identity;
  4761. }
  4762. if (typeof value == 'object') {
  4763. return isArray(value)
  4764. ? baseMatchesProperty(value[0], value[1])
  4765. : baseMatches(value);
  4766. }
  4767. return property(value);
  4768. }
  4769. /**
  4770. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  4771. *
  4772. * @private
  4773. * @param {Object} object The object to query.
  4774. * @returns {Array} Returns the array of property names.
  4775. */
  4776. function baseKeys(object) {
  4777. if (!isPrototype(object)) {
  4778. return nativeKeys(object);
  4779. }
  4780. var result = [];
  4781. for (var key in Object(object)) {
  4782. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  4783. result.push(key);
  4784. }
  4785. }
  4786. return result;
  4787. }
  4788. /**
  4789. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  4790. *
  4791. * @private
  4792. * @param {Object} object The object to query.
  4793. * @returns {Array} Returns the array of property names.
  4794. */
  4795. function baseKeysIn(object) {
  4796. if (!isObject(object)) {
  4797. return nativeKeysIn(object);
  4798. }
  4799. var isProto = isPrototype(object),
  4800. result = [];
  4801. for (var key in object) {
  4802. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  4803. result.push(key);
  4804. }
  4805. }
  4806. return result;
  4807. }
  4808. /**
  4809. * The base implementation of `_.lt` which doesn't coerce arguments.
  4810. *
  4811. * @private
  4812. * @param {*} value The value to compare.
  4813. * @param {*} other The other value to compare.
  4814. * @returns {boolean} Returns `true` if `value` is less than `other`,
  4815. * else `false`.
  4816. */
  4817. function baseLt(value, other) {
  4818. return value < other;
  4819. }
  4820. /**
  4821. * The base implementation of `_.map` without support for iteratee shorthands.
  4822. *
  4823. * @private
  4824. * @param {Array|Object} collection The collection to iterate over.
  4825. * @param {Function} iteratee The function invoked per iteration.
  4826. * @returns {Array} Returns the new mapped array.
  4827. */
  4828. function baseMap(collection, iteratee) {
  4829. var index = -1,
  4830. result = isArrayLike(collection) ? Array(collection.length) : [];
  4831. baseEach(collection, function(value, key, collection) {
  4832. result[++index] = iteratee(value, key, collection);
  4833. });
  4834. return result;
  4835. }
  4836. /**
  4837. * The base implementation of `_.matches` which doesn't clone `source`.
  4838. *
  4839. * @private
  4840. * @param {Object} source The object of property values to match.
  4841. * @returns {Function} Returns the new spec function.
  4842. */
  4843. function baseMatches(source) {
  4844. var matchData = getMatchData(source);
  4845. if (matchData.length == 1 && matchData[0][2]) {
  4846. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  4847. }
  4848. return function(object) {
  4849. return object === source || baseIsMatch(object, source, matchData);
  4850. };
  4851. }
  4852. /**
  4853. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  4854. *
  4855. * @private
  4856. * @param {string} path The path of the property to get.
  4857. * @param {*} srcValue The value to match.
  4858. * @returns {Function} Returns the new spec function.
  4859. */
  4860. function baseMatchesProperty(path, srcValue) {
  4861. if (isKey(path) && isStrictComparable(srcValue)) {
  4862. return matchesStrictComparable(toKey(path), srcValue);
  4863. }
  4864. return function(object) {
  4865. var objValue = get(object, path);
  4866. return (objValue === undefined && objValue === srcValue)
  4867. ? hasIn(object, path)
  4868. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  4869. };
  4870. }
  4871. /**
  4872. * The base implementation of `_.merge` without support for multiple sources.
  4873. *
  4874. * @private
  4875. * @param {Object} object The destination object.
  4876. * @param {Object} source The source object.
  4877. * @param {number} srcIndex The index of `source`.
  4878. * @param {Function} [customizer] The function to customize merged values.
  4879. * @param {Object} [stack] Tracks traversed source values and their merged
  4880. * counterparts.
  4881. */
  4882. function baseMerge(object, source, srcIndex, customizer, stack) {
  4883. if (object === source) {
  4884. return;
  4885. }
  4886. baseFor(source, function(srcValue, key) {
  4887. stack || (stack = new Stack);
  4888. if (isObject(srcValue)) {
  4889. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  4890. }
  4891. else {
  4892. var newValue = customizer
  4893. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  4894. : undefined;
  4895. if (newValue === undefined) {
  4896. newValue = srcValue;
  4897. }
  4898. assignMergeValue(object, key, newValue);
  4899. }
  4900. }, keysIn);
  4901. }
  4902. /**
  4903. * A specialized version of `baseMerge` for arrays and objects which performs
  4904. * deep merges and tracks traversed objects enabling objects with circular
  4905. * references to be merged.
  4906. *
  4907. * @private
  4908. * @param {Object} object The destination object.
  4909. * @param {Object} source The source object.
  4910. * @param {string} key The key of the value to merge.
  4911. * @param {number} srcIndex The index of `source`.
  4912. * @param {Function} mergeFunc The function to merge values.
  4913. * @param {Function} [customizer] The function to customize assigned values.
  4914. * @param {Object} [stack] Tracks traversed source values and their merged
  4915. * counterparts.
  4916. */
  4917. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  4918. var objValue = safeGet(object, key),
  4919. srcValue = safeGet(source, key),
  4920. stacked = stack.get(srcValue);
  4921. if (stacked) {
  4922. assignMergeValue(object, key, stacked);
  4923. return;
  4924. }
  4925. var newValue = customizer
  4926. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  4927. : undefined;
  4928. var isCommon = newValue === undefined;
  4929. if (isCommon) {
  4930. var isArr = isArray(srcValue),
  4931. isBuff = !isArr && isBuffer(srcValue),
  4932. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  4933. newValue = srcValue;
  4934. if (isArr || isBuff || isTyped) {
  4935. if (isArray(objValue)) {
  4936. newValue = objValue;
  4937. }
  4938. else if (isArrayLikeObject(objValue)) {
  4939. newValue = copyArray(objValue);
  4940. }
  4941. else if (isBuff) {
  4942. isCommon = false;
  4943. newValue = cloneBuffer(srcValue, true);
  4944. }
  4945. else if (isTyped) {
  4946. isCommon = false;
  4947. newValue = cloneTypedArray(srcValue, true);
  4948. }
  4949. else {
  4950. newValue = [];
  4951. }
  4952. }
  4953. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  4954. newValue = objValue;
  4955. if (isArguments(objValue)) {
  4956. newValue = toPlainObject(objValue);
  4957. }
  4958. else if (!isObject(objValue) || isFunction(objValue)) {
  4959. newValue = initCloneObject(srcValue);
  4960. }
  4961. }
  4962. else {
  4963. isCommon = false;
  4964. }
  4965. }
  4966. if (isCommon) {
  4967. // Recursively merge objects and arrays (susceptible to call stack limits).
  4968. stack.set(srcValue, newValue);
  4969. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  4970. stack['delete'](srcValue);
  4971. }
  4972. assignMergeValue(object, key, newValue);
  4973. }
  4974. /**
  4975. * The base implementation of `_.nth` which doesn't coerce arguments.
  4976. *
  4977. * @private
  4978. * @param {Array} array The array to query.
  4979. * @param {number} n The index of the element to return.
  4980. * @returns {*} Returns the nth element of `array`.
  4981. */
  4982. function baseNth(array, n) {
  4983. var length = array.length;
  4984. if (!length) {
  4985. return;
  4986. }
  4987. n += n < 0 ? length : 0;
  4988. return isIndex(n, length) ? array[n] : undefined;
  4989. }
  4990. /**
  4991. * The base implementation of `_.orderBy` without param guards.
  4992. *
  4993. * @private
  4994. * @param {Array|Object} collection The collection to iterate over.
  4995. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  4996. * @param {string[]} orders The sort orders of `iteratees`.
  4997. * @returns {Array} Returns the new sorted array.
  4998. */
  4999. function baseOrderBy(collection, iteratees, orders) {
  5000. if (iteratees.length) {
  5001. iteratees = arrayMap(iteratees, function(iteratee) {
  5002. if (isArray(iteratee)) {
  5003. return function(value) {
  5004. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  5005. }
  5006. }
  5007. return iteratee;
  5008. });
  5009. } else {
  5010. iteratees = [identity];
  5011. }
  5012. var index = -1;
  5013. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  5014. var result = baseMap(collection, function(value, key, collection) {
  5015. var criteria = arrayMap(iteratees, function(iteratee) {
  5016. return iteratee(value);
  5017. });
  5018. return { 'criteria': criteria, 'index': ++index, 'value': value };
  5019. });
  5020. return baseSortBy(result, function(object, other) {
  5021. return compareMultiple(object, other, orders);
  5022. });
  5023. }
  5024. /**
  5025. * The base implementation of `_.pick` without support for individual
  5026. * property identifiers.
  5027. *
  5028. * @private
  5029. * @param {Object} object The source object.
  5030. * @param {string[]} paths The property paths to pick.
  5031. * @returns {Object} Returns the new object.
  5032. */
  5033. function basePick(object, paths) {
  5034. return basePickBy(object, paths, function(value, path) {
  5035. return hasIn(object, path);
  5036. });
  5037. }
  5038. /**
  5039. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  5040. *
  5041. * @private
  5042. * @param {Object} object The source object.
  5043. * @param {string[]} paths The property paths to pick.
  5044. * @param {Function} predicate The function invoked per property.
  5045. * @returns {Object} Returns the new object.
  5046. */
  5047. function basePickBy(object, paths, predicate) {
  5048. var index = -1,
  5049. length = paths.length,
  5050. result = {};
  5051. while (++index < length) {
  5052. var path = paths[index],
  5053. value = baseGet(object, path);
  5054. if (predicate(value, path)) {
  5055. baseSet(result, castPath(path, object), value);
  5056. }
  5057. }
  5058. return result;
  5059. }
  5060. /**
  5061. * A specialized version of `baseProperty` which supports deep paths.
  5062. *
  5063. * @private
  5064. * @param {Array|string} path The path of the property to get.
  5065. * @returns {Function} Returns the new accessor function.
  5066. */
  5067. function basePropertyDeep(path) {
  5068. return function(object) {
  5069. return baseGet(object, path);
  5070. };
  5071. }
  5072. /**
  5073. * The base implementation of `_.pullAllBy` without support for iteratee
  5074. * shorthands.
  5075. *
  5076. * @private
  5077. * @param {Array} array The array to modify.
  5078. * @param {Array} values The values to remove.
  5079. * @param {Function} [iteratee] The iteratee invoked per element.
  5080. * @param {Function} [comparator] The comparator invoked per element.
  5081. * @returns {Array} Returns `array`.
  5082. */
  5083. function basePullAll(array, values, iteratee, comparator) {
  5084. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  5085. index = -1,
  5086. length = values.length,
  5087. seen = array;
  5088. if (array === values) {
  5089. values = copyArray(values);
  5090. }
  5091. if (iteratee) {
  5092. seen = arrayMap(array, baseUnary(iteratee));
  5093. }
  5094. while (++index < length) {
  5095. var fromIndex = 0,
  5096. value = values[index],
  5097. computed = iteratee ? iteratee(value) : value;
  5098. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  5099. if (seen !== array) {
  5100. splice.call(seen, fromIndex, 1);
  5101. }
  5102. splice.call(array, fromIndex, 1);
  5103. }
  5104. }
  5105. return array;
  5106. }
  5107. /**
  5108. * The base implementation of `_.pullAt` without support for individual
  5109. * indexes or capturing the removed elements.
  5110. *
  5111. * @private
  5112. * @param {Array} array The array to modify.
  5113. * @param {number[]} indexes The indexes of elements to remove.
  5114. * @returns {Array} Returns `array`.
  5115. */
  5116. function basePullAt(array, indexes) {
  5117. var length = array ? indexes.length : 0,
  5118. lastIndex = length - 1;
  5119. while (length--) {
  5120. var index = indexes[length];
  5121. if (length == lastIndex || index !== previous) {
  5122. var previous = index;
  5123. if (isIndex(index)) {
  5124. splice.call(array, index, 1);
  5125. } else {
  5126. baseUnset(array, index);
  5127. }
  5128. }
  5129. }
  5130. return array;
  5131. }
  5132. /**
  5133. * The base implementation of `_.random` without support for returning
  5134. * floating-point numbers.
  5135. *
  5136. * @private
  5137. * @param {number} lower The lower bound.
  5138. * @param {number} upper The upper bound.
  5139. * @returns {number} Returns the random number.
  5140. */
  5141. function baseRandom(lower, upper) {
  5142. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  5143. }
  5144. /**
  5145. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  5146. * coerce arguments.
  5147. *
  5148. * @private
  5149. * @param {number} start The start of the range.
  5150. * @param {number} end The end of the range.
  5151. * @param {number} step The value to increment or decrement by.
  5152. * @param {boolean} [fromRight] Specify iterating from right to left.
  5153. * @returns {Array} Returns the range of numbers.
  5154. */
  5155. function baseRange(start, end, step, fromRight) {
  5156. var index = -1,
  5157. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  5158. result = Array(length);
  5159. while (length--) {
  5160. result[fromRight ? length : ++index] = start;
  5161. start += step;
  5162. }
  5163. return result;
  5164. }
  5165. /**
  5166. * The base implementation of `_.repeat` which doesn't coerce arguments.
  5167. *
  5168. * @private
  5169. * @param {string} string The string to repeat.
  5170. * @param {number} n The number of times to repeat the string.
  5171. * @returns {string} Returns the repeated string.
  5172. */
  5173. function baseRepeat(string, n) {
  5174. var result = '';
  5175. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  5176. return result;
  5177. }
  5178. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  5179. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  5180. do {
  5181. if (n % 2) {
  5182. result += string;
  5183. }
  5184. n = nativeFloor(n / 2);
  5185. if (n) {
  5186. string += string;
  5187. }
  5188. } while (n);
  5189. return result;
  5190. }
  5191. /**
  5192. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  5193. *
  5194. * @private
  5195. * @param {Function} func The function to apply a rest parameter to.
  5196. * @param {number} [start=func.length-1] The start position of the rest parameter.
  5197. * @returns {Function} Returns the new function.
  5198. */
  5199. function baseRest(func, start) {
  5200. return setToString(overRest(func, start, identity), func + '');
  5201. }
  5202. /**
  5203. * The base implementation of `_.sample`.
  5204. *
  5205. * @private
  5206. * @param {Array|Object} collection The collection to sample.
  5207. * @returns {*} Returns the random element.
  5208. */
  5209. function baseSample(collection) {
  5210. return arraySample(values(collection));
  5211. }
  5212. /**
  5213. * The base implementation of `_.sampleSize` without param guards.
  5214. *
  5215. * @private
  5216. * @param {Array|Object} collection The collection to sample.
  5217. * @param {number} n The number of elements to sample.
  5218. * @returns {Array} Returns the random elements.
  5219. */
  5220. function baseSampleSize(collection, n) {
  5221. var array = values(collection);
  5222. return shuffleSelf(array, baseClamp(n, 0, array.length));
  5223. }
  5224. /**
  5225. * The base implementation of `_.set`.
  5226. *
  5227. * @private
  5228. * @param {Object} object The object to modify.
  5229. * @param {Array|string} path The path of the property to set.
  5230. * @param {*} value The value to set.
  5231. * @param {Function} [customizer] The function to customize path creation.
  5232. * @returns {Object} Returns `object`.
  5233. */
  5234. function baseSet(object, path, value, customizer) {
  5235. if (!isObject(object)) {
  5236. return object;
  5237. }
  5238. path = castPath(path, object);
  5239. var index = -1,
  5240. length = path.length,
  5241. lastIndex = length - 1,
  5242. nested = object;
  5243. while (nested != null && ++index < length) {
  5244. var key = toKey(path[index]),
  5245. newValue = value;
  5246. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  5247. return object;
  5248. }
  5249. if (index != lastIndex) {
  5250. var objValue = nested[key];
  5251. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  5252. if (newValue === undefined) {
  5253. newValue = isObject(objValue)
  5254. ? objValue
  5255. : (isIndex(path[index + 1]) ? [] : {});
  5256. }
  5257. }
  5258. assignValue(nested, key, newValue);
  5259. nested = nested[key];
  5260. }
  5261. return object;
  5262. }
  5263. /**
  5264. * The base implementation of `setData` without support for hot loop shorting.
  5265. *
  5266. * @private
  5267. * @param {Function} func The function to associate metadata with.
  5268. * @param {*} data The metadata.
  5269. * @returns {Function} Returns `func`.
  5270. */
  5271. var baseSetData = !metaMap ? identity : function(func, data) {
  5272. metaMap.set(func, data);
  5273. return func;
  5274. };
  5275. /**
  5276. * The base implementation of `setToString` without support for hot loop shorting.
  5277. *
  5278. * @private
  5279. * @param {Function} func The function to modify.
  5280. * @param {Function} string The `toString` result.
  5281. * @returns {Function} Returns `func`.
  5282. */
  5283. var baseSetToString = !defineProperty ? identity : function(func, string) {
  5284. return defineProperty(func, 'toString', {
  5285. 'configurable': true,
  5286. 'enumerable': false,
  5287. 'value': constant(string),
  5288. 'writable': true
  5289. });
  5290. };
  5291. /**
  5292. * The base implementation of `_.shuffle`.
  5293. *
  5294. * @private
  5295. * @param {Array|Object} collection The collection to shuffle.
  5296. * @returns {Array} Returns the new shuffled array.
  5297. */
  5298. function baseShuffle(collection) {
  5299. return shuffleSelf(values(collection));
  5300. }
  5301. /**
  5302. * The base implementation of `_.slice` without an iteratee call guard.
  5303. *
  5304. * @private
  5305. * @param {Array} array The array to slice.
  5306. * @param {number} [start=0] The start position.
  5307. * @param {number} [end=array.length] The end position.
  5308. * @returns {Array} Returns the slice of `array`.
  5309. */
  5310. function baseSlice(array, start, end) {
  5311. var index = -1,
  5312. length = array.length;
  5313. if (start < 0) {
  5314. start = -start > length ? 0 : (length + start);
  5315. }
  5316. end = end > length ? length : end;
  5317. if (end < 0) {
  5318. end += length;
  5319. }
  5320. length = start > end ? 0 : ((end - start) >>> 0);
  5321. start >>>= 0;
  5322. var result = Array(length);
  5323. while (++index < length) {
  5324. result[index] = array[index + start];
  5325. }
  5326. return result;
  5327. }
  5328. /**
  5329. * The base implementation of `_.some` without support for iteratee shorthands.
  5330. *
  5331. * @private
  5332. * @param {Array|Object} collection The collection to iterate over.
  5333. * @param {Function} predicate The function invoked per iteration.
  5334. * @returns {boolean} Returns `true` if any element passes the predicate check,
  5335. * else `false`.
  5336. */
  5337. function baseSome(collection, predicate) {
  5338. var result;
  5339. baseEach(collection, function(value, index, collection) {
  5340. result = predicate(value, index, collection);
  5341. return !result;
  5342. });
  5343. return !!result;
  5344. }
  5345. /**
  5346. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  5347. * performs a binary search of `array` to determine the index at which `value`
  5348. * should be inserted into `array` in order to maintain its sort order.
  5349. *
  5350. * @private
  5351. * @param {Array} array The sorted array to inspect.
  5352. * @param {*} value The value to evaluate.
  5353. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  5354. * @returns {number} Returns the index at which `value` should be inserted
  5355. * into `array`.
  5356. */
  5357. function baseSortedIndex(array, value, retHighest) {
  5358. var low = 0,
  5359. high = array == null ? low : array.length;
  5360. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  5361. while (low < high) {
  5362. var mid = (low + high) >>> 1,
  5363. computed = array[mid];
  5364. if (computed !== null && !isSymbol(computed) &&
  5365. (retHighest ? (computed <= value) : (computed < value))) {
  5366. low = mid + 1;
  5367. } else {
  5368. high = mid;
  5369. }
  5370. }
  5371. return high;
  5372. }
  5373. return baseSortedIndexBy(array, value, identity, retHighest);
  5374. }
  5375. /**
  5376. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  5377. * which invokes `iteratee` for `value` and each element of `array` to compute
  5378. * their sort ranking. The iteratee is invoked with one argument; (value).
  5379. *
  5380. * @private
  5381. * @param {Array} array The sorted array to inspect.
  5382. * @param {*} value The value to evaluate.
  5383. * @param {Function} iteratee The iteratee invoked per element.
  5384. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  5385. * @returns {number} Returns the index at which `value` should be inserted
  5386. * into `array`.
  5387. */
  5388. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  5389. var low = 0,
  5390. high = array == null ? 0 : array.length;
  5391. if (high === 0) {
  5392. return 0;
  5393. }
  5394. value = iteratee(value);
  5395. var valIsNaN = value !== value,
  5396. valIsNull = value === null,
  5397. valIsSymbol = isSymbol(value),
  5398. valIsUndefined = value === undefined;
  5399. while (low < high) {
  5400. var mid = nativeFloor((low + high) / 2),
  5401. computed = iteratee(array[mid]),
  5402. othIsDefined = computed !== undefined,
  5403. othIsNull = computed === null,
  5404. othIsReflexive = computed === computed,
  5405. othIsSymbol = isSymbol(computed);
  5406. if (valIsNaN) {
  5407. var setLow = retHighest || othIsReflexive;
  5408. } else if (valIsUndefined) {
  5409. setLow = othIsReflexive && (retHighest || othIsDefined);
  5410. } else if (valIsNull) {
  5411. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  5412. } else if (valIsSymbol) {
  5413. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  5414. } else if (othIsNull || othIsSymbol) {
  5415. setLow = false;
  5416. } else {
  5417. setLow = retHighest ? (computed <= value) : (computed < value);
  5418. }
  5419. if (setLow) {
  5420. low = mid + 1;
  5421. } else {
  5422. high = mid;
  5423. }
  5424. }
  5425. return nativeMin(high, MAX_ARRAY_INDEX);
  5426. }
  5427. /**
  5428. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  5429. * support for iteratee shorthands.
  5430. *
  5431. * @private
  5432. * @param {Array} array The array to inspect.
  5433. * @param {Function} [iteratee] The iteratee invoked per element.
  5434. * @returns {Array} Returns the new duplicate free array.
  5435. */
  5436. function baseSortedUniq(array, iteratee) {
  5437. var index = -1,
  5438. length = array.length,
  5439. resIndex = 0,
  5440. result = [];
  5441. while (++index < length) {
  5442. var value = array[index],
  5443. computed = iteratee ? iteratee(value) : value;
  5444. if (!index || !eq(computed, seen)) {
  5445. var seen = computed;
  5446. result[resIndex++] = value === 0 ? 0 : value;
  5447. }
  5448. }
  5449. return result;
  5450. }
  5451. /**
  5452. * The base implementation of `_.toNumber` which doesn't ensure correct
  5453. * conversions of binary, hexadecimal, or octal string values.
  5454. *
  5455. * @private
  5456. * @param {*} value The value to process.
  5457. * @returns {number} Returns the number.
  5458. */
  5459. function baseToNumber(value) {
  5460. if (typeof value == 'number') {
  5461. return value;
  5462. }
  5463. if (isSymbol(value)) {
  5464. return NAN;
  5465. }
  5466. return +value;
  5467. }
  5468. /**
  5469. * The base implementation of `_.toString` which doesn't convert nullish
  5470. * values to empty strings.
  5471. *
  5472. * @private
  5473. * @param {*} value The value to process.
  5474. * @returns {string} Returns the string.
  5475. */
  5476. function baseToString(value) {
  5477. // Exit early for strings to avoid a performance hit in some environments.
  5478. if (typeof value == 'string') {
  5479. return value;
  5480. }
  5481. if (isArray(value)) {
  5482. // Recursively convert values (susceptible to call stack limits).
  5483. return arrayMap(value, baseToString) + '';
  5484. }
  5485. if (isSymbol(value)) {
  5486. return symbolToString ? symbolToString.call(value) : '';
  5487. }
  5488. var result = (value + '');
  5489. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  5490. }
  5491. /**
  5492. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  5493. *
  5494. * @private
  5495. * @param {Array} array The array to inspect.
  5496. * @param {Function} [iteratee] The iteratee invoked per element.
  5497. * @param {Function} [comparator] The comparator invoked per element.
  5498. * @returns {Array} Returns the new duplicate free array.
  5499. */
  5500. function baseUniq(array, iteratee, comparator) {
  5501. var index = -1,
  5502. includes = arrayIncludes,
  5503. length = array.length,
  5504. isCommon = true,
  5505. result = [],
  5506. seen = result;
  5507. if (comparator) {
  5508. isCommon = false;
  5509. includes = arrayIncludesWith;
  5510. }
  5511. else if (length >= LARGE_ARRAY_SIZE) {
  5512. var set = iteratee ? null : createSet(array);
  5513. if (set) {
  5514. return setToArray(set);
  5515. }
  5516. isCommon = false;
  5517. includes = cacheHas;
  5518. seen = new SetCache;
  5519. }
  5520. else {
  5521. seen = iteratee ? [] : result;
  5522. }
  5523. outer:
  5524. while (++index < length) {
  5525. var value = array[index],
  5526. computed = iteratee ? iteratee(value) : value;
  5527. value = (comparator || value !== 0) ? value : 0;
  5528. if (isCommon && computed === computed) {
  5529. var seenIndex = seen.length;
  5530. while (seenIndex--) {
  5531. if (seen[seenIndex] === computed) {
  5532. continue outer;
  5533. }
  5534. }
  5535. if (iteratee) {
  5536. seen.push(computed);
  5537. }
  5538. result.push(value);
  5539. }
  5540. else if (!includes(seen, computed, comparator)) {
  5541. if (seen !== result) {
  5542. seen.push(computed);
  5543. }
  5544. result.push(value);
  5545. }
  5546. }
  5547. return result;
  5548. }
  5549. /**
  5550. * The base implementation of `_.unset`.
  5551. *
  5552. * @private
  5553. * @param {Object} object The object to modify.
  5554. * @param {Array|string} path The property path to unset.
  5555. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  5556. */
  5557. function baseUnset(object, path) {
  5558. path = castPath(path, object);
  5559. object = parent(object, path);
  5560. return object == null || delete object[toKey(last(path))];
  5561. }
  5562. /**
  5563. * The base implementation of `_.update`.
  5564. *
  5565. * @private
  5566. * @param {Object} object The object to modify.
  5567. * @param {Array|string} path The path of the property to update.
  5568. * @param {Function} updater The function to produce the updated value.
  5569. * @param {Function} [customizer] The function to customize path creation.
  5570. * @returns {Object} Returns `object`.
  5571. */
  5572. function baseUpdate(object, path, updater, customizer) {
  5573. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  5574. }
  5575. /**
  5576. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  5577. * without support for iteratee shorthands.
  5578. *
  5579. * @private
  5580. * @param {Array} array The array to query.
  5581. * @param {Function} predicate The function invoked per iteration.
  5582. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  5583. * @param {boolean} [fromRight] Specify iterating from right to left.
  5584. * @returns {Array} Returns the slice of `array`.
  5585. */
  5586. function baseWhile(array, predicate, isDrop, fromRight) {
  5587. var length = array.length,
  5588. index = fromRight ? length : -1;
  5589. while ((fromRight ? index-- : ++index < length) &&
  5590. predicate(array[index], index, array)) {}
  5591. return isDrop
  5592. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  5593. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  5594. }
  5595. /**
  5596. * The base implementation of `wrapperValue` which returns the result of
  5597. * performing a sequence of actions on the unwrapped `value`, where each
  5598. * successive action is supplied the return value of the previous.
  5599. *
  5600. * @private
  5601. * @param {*} value The unwrapped value.
  5602. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  5603. * @returns {*} Returns the resolved value.
  5604. */
  5605. function baseWrapperValue(value, actions) {
  5606. var result = value;
  5607. if (result instanceof LazyWrapper) {
  5608. result = result.value();
  5609. }
  5610. return arrayReduce(actions, function(result, action) {
  5611. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  5612. }, result);
  5613. }
  5614. /**
  5615. * The base implementation of methods like `_.xor`, without support for
  5616. * iteratee shorthands, that accepts an array of arrays to inspect.
  5617. *
  5618. * @private
  5619. * @param {Array} arrays The arrays to inspect.
  5620. * @param {Function} [iteratee] The iteratee invoked per element.
  5621. * @param {Function} [comparator] The comparator invoked per element.
  5622. * @returns {Array} Returns the new array of values.
  5623. */
  5624. function baseXor(arrays, iteratee, comparator) {
  5625. var length = arrays.length;
  5626. if (length < 2) {
  5627. return length ? baseUniq(arrays[0]) : [];
  5628. }
  5629. var index = -1,
  5630. result = Array(length);
  5631. while (++index < length) {
  5632. var array = arrays[index],
  5633. othIndex = -1;
  5634. while (++othIndex < length) {
  5635. if (othIndex != index) {
  5636. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  5637. }
  5638. }
  5639. }
  5640. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  5641. }
  5642. /**
  5643. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  5644. *
  5645. * @private
  5646. * @param {Array} props The property identifiers.
  5647. * @param {Array} values The property values.
  5648. * @param {Function} assignFunc The function to assign values.
  5649. * @returns {Object} Returns the new object.
  5650. */
  5651. function baseZipObject(props, values, assignFunc) {
  5652. var index = -1,
  5653. length = props.length,
  5654. valsLength = values.length,
  5655. result = {};
  5656. while (++index < length) {
  5657. var value = index < valsLength ? values[index] : undefined;
  5658. assignFunc(result, props[index], value);
  5659. }
  5660. return result;
  5661. }
  5662. /**
  5663. * Casts `value` to an empty array if it's not an array like object.
  5664. *
  5665. * @private
  5666. * @param {*} value The value to inspect.
  5667. * @returns {Array|Object} Returns the cast array-like object.
  5668. */
  5669. function castArrayLikeObject(value) {
  5670. return isArrayLikeObject(value) ? value : [];
  5671. }
  5672. /**
  5673. * Casts `value` to `identity` if it's not a function.
  5674. *
  5675. * @private
  5676. * @param {*} value The value to inspect.
  5677. * @returns {Function} Returns cast function.
  5678. */
  5679. function castFunction(value) {
  5680. return typeof value == 'function' ? value : identity;
  5681. }
  5682. /**
  5683. * Casts `value` to a path array if it's not one.
  5684. *
  5685. * @private
  5686. * @param {*} value The value to inspect.
  5687. * @param {Object} [object] The object to query keys on.
  5688. * @returns {Array} Returns the cast property path array.
  5689. */
  5690. function castPath(value, object) {
  5691. if (isArray(value)) {
  5692. return value;
  5693. }
  5694. return isKey(value, object) ? [value] : stringToPath(toString(value));
  5695. }
  5696. /**
  5697. * A `baseRest` alias which can be replaced with `identity` by module
  5698. * replacement plugins.
  5699. *
  5700. * @private
  5701. * @type {Function}
  5702. * @param {Function} func The function to apply a rest parameter to.
  5703. * @returns {Function} Returns the new function.
  5704. */
  5705. var castRest = baseRest;
  5706. /**
  5707. * Casts `array` to a slice if it's needed.
  5708. *
  5709. * @private
  5710. * @param {Array} array The array to inspect.
  5711. * @param {number} start The start position.
  5712. * @param {number} [end=array.length] The end position.
  5713. * @returns {Array} Returns the cast slice.
  5714. */
  5715. function castSlice(array, start, end) {
  5716. var length = array.length;
  5717. end = end === undefined ? length : end;
  5718. return (!start && end >= length) ? array : baseSlice(array, start, end);
  5719. }
  5720. /**
  5721. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  5722. *
  5723. * @private
  5724. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  5725. */
  5726. var clearTimeout = ctxClearTimeout || function(id) {
  5727. return root.clearTimeout(id);
  5728. };
  5729. /**
  5730. * Creates a clone of `buffer`.
  5731. *
  5732. * @private
  5733. * @param {Buffer} buffer The buffer to clone.
  5734. * @param {boolean} [isDeep] Specify a deep clone.
  5735. * @returns {Buffer} Returns the cloned buffer.
  5736. */
  5737. function cloneBuffer(buffer, isDeep) {
  5738. if (isDeep) {
  5739. return buffer.slice();
  5740. }
  5741. var length = buffer.length,
  5742. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  5743. buffer.copy(result);
  5744. return result;
  5745. }
  5746. /**
  5747. * Creates a clone of `arrayBuffer`.
  5748. *
  5749. * @private
  5750. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  5751. * @returns {ArrayBuffer} Returns the cloned array buffer.
  5752. */
  5753. function cloneArrayBuffer(arrayBuffer) {
  5754. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  5755. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  5756. return result;
  5757. }
  5758. /**
  5759. * Creates a clone of `dataView`.
  5760. *
  5761. * @private
  5762. * @param {Object} dataView The data view to clone.
  5763. * @param {boolean} [isDeep] Specify a deep clone.
  5764. * @returns {Object} Returns the cloned data view.
  5765. */
  5766. function cloneDataView(dataView, isDeep) {
  5767. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  5768. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  5769. }
  5770. /**
  5771. * Creates a clone of `regexp`.
  5772. *
  5773. * @private
  5774. * @param {Object} regexp The regexp to clone.
  5775. * @returns {Object} Returns the cloned regexp.
  5776. */
  5777. function cloneRegExp(regexp) {
  5778. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  5779. result.lastIndex = regexp.lastIndex;
  5780. return result;
  5781. }
  5782. /**
  5783. * Creates a clone of the `symbol` object.
  5784. *
  5785. * @private
  5786. * @param {Object} symbol The symbol object to clone.
  5787. * @returns {Object} Returns the cloned symbol object.
  5788. */
  5789. function cloneSymbol(symbol) {
  5790. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  5791. }
  5792. /**
  5793. * Creates a clone of `typedArray`.
  5794. *
  5795. * @private
  5796. * @param {Object} typedArray The typed array to clone.
  5797. * @param {boolean} [isDeep] Specify a deep clone.
  5798. * @returns {Object} Returns the cloned typed array.
  5799. */
  5800. function cloneTypedArray(typedArray, isDeep) {
  5801. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  5802. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  5803. }
  5804. /**
  5805. * Compares values to sort them in ascending order.
  5806. *
  5807. * @private
  5808. * @param {*} value The value to compare.
  5809. * @param {*} other The other value to compare.
  5810. * @returns {number} Returns the sort order indicator for `value`.
  5811. */
  5812. function compareAscending(value, other) {
  5813. if (value !== other) {
  5814. var valIsDefined = value !== undefined,
  5815. valIsNull = value === null,
  5816. valIsReflexive = value === value,
  5817. valIsSymbol = isSymbol(value);
  5818. var othIsDefined = other !== undefined,
  5819. othIsNull = other === null,
  5820. othIsReflexive = other === other,
  5821. othIsSymbol = isSymbol(other);
  5822. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  5823. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  5824. (valIsNull && othIsDefined && othIsReflexive) ||
  5825. (!valIsDefined && othIsReflexive) ||
  5826. !valIsReflexive) {
  5827. return 1;
  5828. }
  5829. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  5830. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  5831. (othIsNull && valIsDefined && valIsReflexive) ||
  5832. (!othIsDefined && valIsReflexive) ||
  5833. !othIsReflexive) {
  5834. return -1;
  5835. }
  5836. }
  5837. return 0;
  5838. }
  5839. /**
  5840. * Used by `_.orderBy` to compare multiple properties of a value to another
  5841. * and stable sort them.
  5842. *
  5843. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  5844. * specify an order of "desc" for descending or "asc" for ascending sort order
  5845. * of corresponding values.
  5846. *
  5847. * @private
  5848. * @param {Object} object The object to compare.
  5849. * @param {Object} other The other object to compare.
  5850. * @param {boolean[]|string[]} orders The order to sort by for each property.
  5851. * @returns {number} Returns the sort order indicator for `object`.
  5852. */
  5853. function compareMultiple(object, other, orders) {
  5854. var index = -1,
  5855. objCriteria = object.criteria,
  5856. othCriteria = other.criteria,
  5857. length = objCriteria.length,
  5858. ordersLength = orders.length;
  5859. while (++index < length) {
  5860. var result = compareAscending(objCriteria[index], othCriteria[index]);
  5861. if (result) {
  5862. if (index >= ordersLength) {
  5863. return result;
  5864. }
  5865. var order = orders[index];
  5866. return result * (order == 'desc' ? -1 : 1);
  5867. }
  5868. }
  5869. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  5870. // that causes it, under certain circumstances, to provide the same value for
  5871. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  5872. // for more details.
  5873. //
  5874. // This also ensures a stable sort in V8 and other engines.
  5875. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  5876. return object.index - other.index;
  5877. }
  5878. /**
  5879. * Creates an array that is the composition of partially applied arguments,
  5880. * placeholders, and provided arguments into a single array of arguments.
  5881. *
  5882. * @private
  5883. * @param {Array} args The provided arguments.
  5884. * @param {Array} partials The arguments to prepend to those provided.
  5885. * @param {Array} holders The `partials` placeholder indexes.
  5886. * @params {boolean} [isCurried] Specify composing for a curried function.
  5887. * @returns {Array} Returns the new array of composed arguments.
  5888. */
  5889. function composeArgs(args, partials, holders, isCurried) {
  5890. var argsIndex = -1,
  5891. argsLength = args.length,
  5892. holdersLength = holders.length,
  5893. leftIndex = -1,
  5894. leftLength = partials.length,
  5895. rangeLength = nativeMax(argsLength - holdersLength, 0),
  5896. result = Array(leftLength + rangeLength),
  5897. isUncurried = !isCurried;
  5898. while (++leftIndex < leftLength) {
  5899. result[leftIndex] = partials[leftIndex];
  5900. }
  5901. while (++argsIndex < holdersLength) {
  5902. if (isUncurried || argsIndex < argsLength) {
  5903. result[holders[argsIndex]] = args[argsIndex];
  5904. }
  5905. }
  5906. while (rangeLength--) {
  5907. result[leftIndex++] = args[argsIndex++];
  5908. }
  5909. return result;
  5910. }
  5911. /**
  5912. * This function is like `composeArgs` except that the arguments composition
  5913. * is tailored for `_.partialRight`.
  5914. *
  5915. * @private
  5916. * @param {Array} args The provided arguments.
  5917. * @param {Array} partials The arguments to append to those provided.
  5918. * @param {Array} holders The `partials` placeholder indexes.
  5919. * @params {boolean} [isCurried] Specify composing for a curried function.
  5920. * @returns {Array} Returns the new array of composed arguments.
  5921. */
  5922. function composeArgsRight(args, partials, holders, isCurried) {
  5923. var argsIndex = -1,
  5924. argsLength = args.length,
  5925. holdersIndex = -1,
  5926. holdersLength = holders.length,
  5927. rightIndex = -1,
  5928. rightLength = partials.length,
  5929. rangeLength = nativeMax(argsLength - holdersLength, 0),
  5930. result = Array(rangeLength + rightLength),
  5931. isUncurried = !isCurried;
  5932. while (++argsIndex < rangeLength) {
  5933. result[argsIndex] = args[argsIndex];
  5934. }
  5935. var offset = argsIndex;
  5936. while (++rightIndex < rightLength) {
  5937. result[offset + rightIndex] = partials[rightIndex];
  5938. }
  5939. while (++holdersIndex < holdersLength) {
  5940. if (isUncurried || argsIndex < argsLength) {
  5941. result[offset + holders[holdersIndex]] = args[argsIndex++];
  5942. }
  5943. }
  5944. return result;
  5945. }
  5946. /**
  5947. * Copies the values of `source` to `array`.
  5948. *
  5949. * @private
  5950. * @param {Array} source The array to copy values from.
  5951. * @param {Array} [array=[]] The array to copy values to.
  5952. * @returns {Array} Returns `array`.
  5953. */
  5954. function copyArray(source, array) {
  5955. var index = -1,
  5956. length = source.length;
  5957. array || (array = Array(length));
  5958. while (++index < length) {
  5959. array[index] = source[index];
  5960. }
  5961. return array;
  5962. }
  5963. /**
  5964. * Copies properties of `source` to `object`.
  5965. *
  5966. * @private
  5967. * @param {Object} source The object to copy properties from.
  5968. * @param {Array} props The property identifiers to copy.
  5969. * @param {Object} [object={}] The object to copy properties to.
  5970. * @param {Function} [customizer] The function to customize copied values.
  5971. * @returns {Object} Returns `object`.
  5972. */
  5973. function copyObject(source, props, object, customizer) {
  5974. var isNew = !object;
  5975. object || (object = {});
  5976. var index = -1,
  5977. length = props.length;
  5978. while (++index < length) {
  5979. var key = props[index];
  5980. var newValue = customizer
  5981. ? customizer(object[key], source[key], key, object, source)
  5982. : undefined;
  5983. if (newValue === undefined) {
  5984. newValue = source[key];
  5985. }
  5986. if (isNew) {
  5987. baseAssignValue(object, key, newValue);
  5988. } else {
  5989. assignValue(object, key, newValue);
  5990. }
  5991. }
  5992. return object;
  5993. }
  5994. /**
  5995. * Copies own symbols of `source` to `object`.
  5996. *
  5997. * @private
  5998. * @param {Object} source The object to copy symbols from.
  5999. * @param {Object} [object={}] The object to copy symbols to.
  6000. * @returns {Object} Returns `object`.
  6001. */
  6002. function copySymbols(source, object) {
  6003. return copyObject(source, getSymbols(source), object);
  6004. }
  6005. /**
  6006. * Copies own and inherited symbols of `source` to `object`.
  6007. *
  6008. * @private
  6009. * @param {Object} source The object to copy symbols from.
  6010. * @param {Object} [object={}] The object to copy symbols to.
  6011. * @returns {Object} Returns `object`.
  6012. */
  6013. function copySymbolsIn(source, object) {
  6014. return copyObject(source, getSymbolsIn(source), object);
  6015. }
  6016. /**
  6017. * Creates a function like `_.groupBy`.
  6018. *
  6019. * @private
  6020. * @param {Function} setter The function to set accumulator values.
  6021. * @param {Function} [initializer] The accumulator object initializer.
  6022. * @returns {Function} Returns the new aggregator function.
  6023. */
  6024. function createAggregator(setter, initializer) {
  6025. return function(collection, iteratee) {
  6026. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  6027. accumulator = initializer ? initializer() : {};
  6028. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  6029. };
  6030. }
  6031. /**
  6032. * Creates a function like `_.assign`.
  6033. *
  6034. * @private
  6035. * @param {Function} assigner The function to assign values.
  6036. * @returns {Function} Returns the new assigner function.
  6037. */
  6038. function createAssigner(assigner) {
  6039. return baseRest(function(object, sources) {
  6040. var index = -1,
  6041. length = sources.length,
  6042. customizer = length > 1 ? sources[length - 1] : undefined,
  6043. guard = length > 2 ? sources[2] : undefined;
  6044. customizer = (assigner.length > 3 && typeof customizer == 'function')
  6045. ? (length--, customizer)
  6046. : undefined;
  6047. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  6048. customizer = length < 3 ? undefined : customizer;
  6049. length = 1;
  6050. }
  6051. object = Object(object);
  6052. while (++index < length) {
  6053. var source = sources[index];
  6054. if (source) {
  6055. assigner(object, source, index, customizer);
  6056. }
  6057. }
  6058. return object;
  6059. });
  6060. }
  6061. /**
  6062. * Creates a `baseEach` or `baseEachRight` function.
  6063. *
  6064. * @private
  6065. * @param {Function} eachFunc The function to iterate over a collection.
  6066. * @param {boolean} [fromRight] Specify iterating from right to left.
  6067. * @returns {Function} Returns the new base function.
  6068. */
  6069. function createBaseEach(eachFunc, fromRight) {
  6070. return function(collection, iteratee) {
  6071. if (collection == null) {
  6072. return collection;
  6073. }
  6074. if (!isArrayLike(collection)) {
  6075. return eachFunc(collection, iteratee);
  6076. }
  6077. var length = collection.length,
  6078. index = fromRight ? length : -1,
  6079. iterable = Object(collection);
  6080. while ((fromRight ? index-- : ++index < length)) {
  6081. if (iteratee(iterable[index], index, iterable) === false) {
  6082. break;
  6083. }
  6084. }
  6085. return collection;
  6086. };
  6087. }
  6088. /**
  6089. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  6090. *
  6091. * @private
  6092. * @param {boolean} [fromRight] Specify iterating from right to left.
  6093. * @returns {Function} Returns the new base function.
  6094. */
  6095. function createBaseFor(fromRight) {
  6096. return function(object, iteratee, keysFunc) {
  6097. var index = -1,
  6098. iterable = Object(object),
  6099. props = keysFunc(object),
  6100. length = props.length;
  6101. while (length--) {
  6102. var key = props[fromRight ? length : ++index];
  6103. if (iteratee(iterable[key], key, iterable) === false) {
  6104. break;
  6105. }
  6106. }
  6107. return object;
  6108. };
  6109. }
  6110. /**
  6111. * Creates a function that wraps `func` to invoke it with the optional `this`
  6112. * binding of `thisArg`.
  6113. *
  6114. * @private
  6115. * @param {Function} func The function to wrap.
  6116. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6117. * @param {*} [thisArg] The `this` binding of `func`.
  6118. * @returns {Function} Returns the new wrapped function.
  6119. */
  6120. function createBind(func, bitmask, thisArg) {
  6121. var isBind = bitmask & WRAP_BIND_FLAG,
  6122. Ctor = createCtor(func);
  6123. function wrapper() {
  6124. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  6125. return fn.apply(isBind ? thisArg : this, arguments);
  6126. }
  6127. return wrapper;
  6128. }
  6129. /**
  6130. * Creates a function like `_.lowerFirst`.
  6131. *
  6132. * @private
  6133. * @param {string} methodName The name of the `String` case method to use.
  6134. * @returns {Function} Returns the new case function.
  6135. */
  6136. function createCaseFirst(methodName) {
  6137. return function(string) {
  6138. string = toString(string);
  6139. var strSymbols = hasUnicode(string)
  6140. ? stringToArray(string)
  6141. : undefined;
  6142. var chr = strSymbols
  6143. ? strSymbols[0]
  6144. : string.charAt(0);
  6145. var trailing = strSymbols
  6146. ? castSlice(strSymbols, 1).join('')
  6147. : string.slice(1);
  6148. return chr[methodName]() + trailing;
  6149. };
  6150. }
  6151. /**
  6152. * Creates a function like `_.camelCase`.
  6153. *
  6154. * @private
  6155. * @param {Function} callback The function to combine each word.
  6156. * @returns {Function} Returns the new compounder function.
  6157. */
  6158. function createCompounder(callback) {
  6159. return function(string) {
  6160. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  6161. };
  6162. }
  6163. /**
  6164. * Creates a function that produces an instance of `Ctor` regardless of
  6165. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  6166. *
  6167. * @private
  6168. * @param {Function} Ctor The constructor to wrap.
  6169. * @returns {Function} Returns the new wrapped function.
  6170. */
  6171. function createCtor(Ctor) {
  6172. return function() {
  6173. // Use a `switch` statement to work with class constructors. See
  6174. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  6175. // for more details.
  6176. var args = arguments;
  6177. switch (args.length) {
  6178. case 0: return new Ctor;
  6179. case 1: return new Ctor(args[0]);
  6180. case 2: return new Ctor(args[0], args[1]);
  6181. case 3: return new Ctor(args[0], args[1], args[2]);
  6182. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  6183. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  6184. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  6185. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  6186. }
  6187. var thisBinding = baseCreate(Ctor.prototype),
  6188. result = Ctor.apply(thisBinding, args);
  6189. // Mimic the constructor's `return` behavior.
  6190. // See https://es5.github.io/#x13.2.2 for more details.
  6191. return isObject(result) ? result : thisBinding;
  6192. };
  6193. }
  6194. /**
  6195. * Creates a function that wraps `func` to enable currying.
  6196. *
  6197. * @private
  6198. * @param {Function} func The function to wrap.
  6199. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6200. * @param {number} arity The arity of `func`.
  6201. * @returns {Function} Returns the new wrapped function.
  6202. */
  6203. function createCurry(func, bitmask, arity) {
  6204. var Ctor = createCtor(func);
  6205. function wrapper() {
  6206. var length = arguments.length,
  6207. args = Array(length),
  6208. index = length,
  6209. placeholder = getHolder(wrapper);
  6210. while (index--) {
  6211. args[index] = arguments[index];
  6212. }
  6213. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  6214. ? []
  6215. : replaceHolders(args, placeholder);
  6216. length -= holders.length;
  6217. if (length < arity) {
  6218. return createRecurry(
  6219. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  6220. args, holders, undefined, undefined, arity - length);
  6221. }
  6222. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  6223. return apply(fn, this, args);
  6224. }
  6225. return wrapper;
  6226. }
  6227. /**
  6228. * Creates a `_.find` or `_.findLast` function.
  6229. *
  6230. * @private
  6231. * @param {Function} findIndexFunc The function to find the collection index.
  6232. * @returns {Function} Returns the new find function.
  6233. */
  6234. function createFind(findIndexFunc) {
  6235. return function(collection, predicate, fromIndex) {
  6236. var iterable = Object(collection);
  6237. if (!isArrayLike(collection)) {
  6238. var iteratee = getIteratee(predicate, 3);
  6239. collection = keys(collection);
  6240. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  6241. }
  6242. var index = findIndexFunc(collection, predicate, fromIndex);
  6243. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  6244. };
  6245. }
  6246. /**
  6247. * Creates a `_.flow` or `_.flowRight` function.
  6248. *
  6249. * @private
  6250. * @param {boolean} [fromRight] Specify iterating from right to left.
  6251. * @returns {Function} Returns the new flow function.
  6252. */
  6253. function createFlow(fromRight) {
  6254. return flatRest(function(funcs) {
  6255. var length = funcs.length,
  6256. index = length,
  6257. prereq = LodashWrapper.prototype.thru;
  6258. if (fromRight) {
  6259. funcs.reverse();
  6260. }
  6261. while (index--) {
  6262. var func = funcs[index];
  6263. if (typeof func != 'function') {
  6264. throw new TypeError(FUNC_ERROR_TEXT);
  6265. }
  6266. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  6267. var wrapper = new LodashWrapper([], true);
  6268. }
  6269. }
  6270. index = wrapper ? index : length;
  6271. while (++index < length) {
  6272. func = funcs[index];
  6273. var funcName = getFuncName(func),
  6274. data = funcName == 'wrapper' ? getData(func) : undefined;
  6275. if (data && isLaziable(data[0]) &&
  6276. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  6277. !data[4].length && data[9] == 1
  6278. ) {
  6279. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  6280. } else {
  6281. wrapper = (func.length == 1 && isLaziable(func))
  6282. ? wrapper[funcName]()
  6283. : wrapper.thru(func);
  6284. }
  6285. }
  6286. return function() {
  6287. var args = arguments,
  6288. value = args[0];
  6289. if (wrapper && args.length == 1 && isArray(value)) {
  6290. return wrapper.plant(value).value();
  6291. }
  6292. var index = 0,
  6293. result = length ? funcs[index].apply(this, args) : value;
  6294. while (++index < length) {
  6295. result = funcs[index].call(this, result);
  6296. }
  6297. return result;
  6298. };
  6299. });
  6300. }
  6301. /**
  6302. * Creates a function that wraps `func` to invoke it with optional `this`
  6303. * binding of `thisArg`, partial application, and currying.
  6304. *
  6305. * @private
  6306. * @param {Function|string} func The function or method name to wrap.
  6307. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6308. * @param {*} [thisArg] The `this` binding of `func`.
  6309. * @param {Array} [partials] The arguments to prepend to those provided to
  6310. * the new function.
  6311. * @param {Array} [holders] The `partials` placeholder indexes.
  6312. * @param {Array} [partialsRight] The arguments to append to those provided
  6313. * to the new function.
  6314. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  6315. * @param {Array} [argPos] The argument positions of the new function.
  6316. * @param {number} [ary] The arity cap of `func`.
  6317. * @param {number} [arity] The arity of `func`.
  6318. * @returns {Function} Returns the new wrapped function.
  6319. */
  6320. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  6321. var isAry = bitmask & WRAP_ARY_FLAG,
  6322. isBind = bitmask & WRAP_BIND_FLAG,
  6323. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  6324. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  6325. isFlip = bitmask & WRAP_FLIP_FLAG,
  6326. Ctor = isBindKey ? undefined : createCtor(func);
  6327. function wrapper() {
  6328. var length = arguments.length,
  6329. args = Array(length),
  6330. index = length;
  6331. while (index--) {
  6332. args[index] = arguments[index];
  6333. }
  6334. if (isCurried) {
  6335. var placeholder = getHolder(wrapper),
  6336. holdersCount = countHolders(args, placeholder);
  6337. }
  6338. if (partials) {
  6339. args = composeArgs(args, partials, holders, isCurried);
  6340. }
  6341. if (partialsRight) {
  6342. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  6343. }
  6344. length -= holdersCount;
  6345. if (isCurried && length < arity) {
  6346. var newHolders = replaceHolders(args, placeholder);
  6347. return createRecurry(
  6348. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  6349. args, newHolders, argPos, ary, arity - length
  6350. );
  6351. }
  6352. var thisBinding = isBind ? thisArg : this,
  6353. fn = isBindKey ? thisBinding[func] : func;
  6354. length = args.length;
  6355. if (argPos) {
  6356. args = reorder(args, argPos);
  6357. } else if (isFlip && length > 1) {
  6358. args.reverse();
  6359. }
  6360. if (isAry && ary < length) {
  6361. args.length = ary;
  6362. }
  6363. if (this && this !== root && this instanceof wrapper) {
  6364. fn = Ctor || createCtor(fn);
  6365. }
  6366. return fn.apply(thisBinding, args);
  6367. }
  6368. return wrapper;
  6369. }
  6370. /**
  6371. * Creates a function like `_.invertBy`.
  6372. *
  6373. * @private
  6374. * @param {Function} setter The function to set accumulator values.
  6375. * @param {Function} toIteratee The function to resolve iteratees.
  6376. * @returns {Function} Returns the new inverter function.
  6377. */
  6378. function createInverter(setter, toIteratee) {
  6379. return function(object, iteratee) {
  6380. return baseInverter(object, setter, toIteratee(iteratee), {});
  6381. };
  6382. }
  6383. /**
  6384. * Creates a function that performs a mathematical operation on two values.
  6385. *
  6386. * @private
  6387. * @param {Function} operator The function to perform the operation.
  6388. * @param {number} [defaultValue] The value used for `undefined` arguments.
  6389. * @returns {Function} Returns the new mathematical operation function.
  6390. */
  6391. function createMathOperation(operator, defaultValue) {
  6392. return function(value, other) {
  6393. var result;
  6394. if (value === undefined && other === undefined) {
  6395. return defaultValue;
  6396. }
  6397. if (value !== undefined) {
  6398. result = value;
  6399. }
  6400. if (other !== undefined) {
  6401. if (result === undefined) {
  6402. return other;
  6403. }
  6404. if (typeof value == 'string' || typeof other == 'string') {
  6405. value = baseToString(value);
  6406. other = baseToString(other);
  6407. } else {
  6408. value = baseToNumber(value);
  6409. other = baseToNumber(other);
  6410. }
  6411. result = operator(value, other);
  6412. }
  6413. return result;
  6414. };
  6415. }
  6416. /**
  6417. * Creates a function like `_.over`.
  6418. *
  6419. * @private
  6420. * @param {Function} arrayFunc The function to iterate over iteratees.
  6421. * @returns {Function} Returns the new over function.
  6422. */
  6423. function createOver(arrayFunc) {
  6424. return flatRest(function(iteratees) {
  6425. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  6426. return baseRest(function(args) {
  6427. var thisArg = this;
  6428. return arrayFunc(iteratees, function(iteratee) {
  6429. return apply(iteratee, thisArg, args);
  6430. });
  6431. });
  6432. });
  6433. }
  6434. /**
  6435. * Creates the padding for `string` based on `length`. The `chars` string
  6436. * is truncated if the number of characters exceeds `length`.
  6437. *
  6438. * @private
  6439. * @param {number} length The padding length.
  6440. * @param {string} [chars=' '] The string used as padding.
  6441. * @returns {string} Returns the padding for `string`.
  6442. */
  6443. function createPadding(length, chars) {
  6444. chars = chars === undefined ? ' ' : baseToString(chars);
  6445. var charsLength = chars.length;
  6446. if (charsLength < 2) {
  6447. return charsLength ? baseRepeat(chars, length) : chars;
  6448. }
  6449. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  6450. return hasUnicode(chars)
  6451. ? castSlice(stringToArray(result), 0, length).join('')
  6452. : result.slice(0, length);
  6453. }
  6454. /**
  6455. * Creates a function that wraps `func` to invoke it with the `this` binding
  6456. * of `thisArg` and `partials` prepended to the arguments it receives.
  6457. *
  6458. * @private
  6459. * @param {Function} func The function to wrap.
  6460. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6461. * @param {*} thisArg The `this` binding of `func`.
  6462. * @param {Array} partials The arguments to prepend to those provided to
  6463. * the new function.
  6464. * @returns {Function} Returns the new wrapped function.
  6465. */
  6466. function createPartial(func, bitmask, thisArg, partials) {
  6467. var isBind = bitmask & WRAP_BIND_FLAG,
  6468. Ctor = createCtor(func);
  6469. function wrapper() {
  6470. var argsIndex = -1,
  6471. argsLength = arguments.length,
  6472. leftIndex = -1,
  6473. leftLength = partials.length,
  6474. args = Array(leftLength + argsLength),
  6475. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  6476. while (++leftIndex < leftLength) {
  6477. args[leftIndex] = partials[leftIndex];
  6478. }
  6479. while (argsLength--) {
  6480. args[leftIndex++] = arguments[++argsIndex];
  6481. }
  6482. return apply(fn, isBind ? thisArg : this, args);
  6483. }
  6484. return wrapper;
  6485. }
  6486. /**
  6487. * Creates a `_.range` or `_.rangeRight` function.
  6488. *
  6489. * @private
  6490. * @param {boolean} [fromRight] Specify iterating from right to left.
  6491. * @returns {Function} Returns the new range function.
  6492. */
  6493. function createRange(fromRight) {
  6494. return function(start, end, step) {
  6495. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  6496. end = step = undefined;
  6497. }
  6498. // Ensure the sign of `-0` is preserved.
  6499. start = toFinite(start);
  6500. if (end === undefined) {
  6501. end = start;
  6502. start = 0;
  6503. } else {
  6504. end = toFinite(end);
  6505. }
  6506. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  6507. return baseRange(start, end, step, fromRight);
  6508. };
  6509. }
  6510. /**
  6511. * Creates a function that performs a relational operation on two values.
  6512. *
  6513. * @private
  6514. * @param {Function} operator The function to perform the operation.
  6515. * @returns {Function} Returns the new relational operation function.
  6516. */
  6517. function createRelationalOperation(operator) {
  6518. return function(value, other) {
  6519. if (!(typeof value == 'string' && typeof other == 'string')) {
  6520. value = toNumber(value);
  6521. other = toNumber(other);
  6522. }
  6523. return operator(value, other);
  6524. };
  6525. }
  6526. /**
  6527. * Creates a function that wraps `func` to continue currying.
  6528. *
  6529. * @private
  6530. * @param {Function} func The function to wrap.
  6531. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6532. * @param {Function} wrapFunc The function to create the `func` wrapper.
  6533. * @param {*} placeholder The placeholder value.
  6534. * @param {*} [thisArg] The `this` binding of `func`.
  6535. * @param {Array} [partials] The arguments to prepend to those provided to
  6536. * the new function.
  6537. * @param {Array} [holders] The `partials` placeholder indexes.
  6538. * @param {Array} [argPos] The argument positions of the new function.
  6539. * @param {number} [ary] The arity cap of `func`.
  6540. * @param {number} [arity] The arity of `func`.
  6541. * @returns {Function} Returns the new wrapped function.
  6542. */
  6543. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  6544. var isCurry = bitmask & WRAP_CURRY_FLAG,
  6545. newHolders = isCurry ? holders : undefined,
  6546. newHoldersRight = isCurry ? undefined : holders,
  6547. newPartials = isCurry ? partials : undefined,
  6548. newPartialsRight = isCurry ? undefined : partials;
  6549. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  6550. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  6551. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  6552. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  6553. }
  6554. var newData = [
  6555. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  6556. newHoldersRight, argPos, ary, arity
  6557. ];
  6558. var result = wrapFunc.apply(undefined, newData);
  6559. if (isLaziable(func)) {
  6560. setData(result, newData);
  6561. }
  6562. result.placeholder = placeholder;
  6563. return setWrapToString(result, func, bitmask);
  6564. }
  6565. /**
  6566. * Creates a function like `_.round`.
  6567. *
  6568. * @private
  6569. * @param {string} methodName The name of the `Math` method to use when rounding.
  6570. * @returns {Function} Returns the new round function.
  6571. */
  6572. function createRound(methodName) {
  6573. var func = Math[methodName];
  6574. return function(number, precision) {
  6575. number = toNumber(number);
  6576. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  6577. if (precision && nativeIsFinite(number)) {
  6578. // Shift with exponential notation to avoid floating-point issues.
  6579. // See [MDN](https://mdn.io/round#Examples) for more details.
  6580. var pair = (toString(number) + 'e').split('e'),
  6581. value = func(pair[0] + 'e' + (+pair[1] + precision));
  6582. pair = (toString(value) + 'e').split('e');
  6583. return +(pair[0] + 'e' + (+pair[1] - precision));
  6584. }
  6585. return func(number);
  6586. };
  6587. }
  6588. /**
  6589. * Creates a set object of `values`.
  6590. *
  6591. * @private
  6592. * @param {Array} values The values to add to the set.
  6593. * @returns {Object} Returns the new set.
  6594. */
  6595. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  6596. return new Set(values);
  6597. };
  6598. /**
  6599. * Creates a `_.toPairs` or `_.toPairsIn` function.
  6600. *
  6601. * @private
  6602. * @param {Function} keysFunc The function to get the keys of a given object.
  6603. * @returns {Function} Returns the new pairs function.
  6604. */
  6605. function createToPairs(keysFunc) {
  6606. return function(object) {
  6607. var tag = getTag(object);
  6608. if (tag == mapTag) {
  6609. return mapToArray(object);
  6610. }
  6611. if (tag == setTag) {
  6612. return setToPairs(object);
  6613. }
  6614. return baseToPairs(object, keysFunc(object));
  6615. };
  6616. }
  6617. /**
  6618. * Creates a function that either curries or invokes `func` with optional
  6619. * `this` binding and partially applied arguments.
  6620. *
  6621. * @private
  6622. * @param {Function|string} func The function or method name to wrap.
  6623. * @param {number} bitmask The bitmask flags.
  6624. * 1 - `_.bind`
  6625. * 2 - `_.bindKey`
  6626. * 4 - `_.curry` or `_.curryRight` of a bound function
  6627. * 8 - `_.curry`
  6628. * 16 - `_.curryRight`
  6629. * 32 - `_.partial`
  6630. * 64 - `_.partialRight`
  6631. * 128 - `_.rearg`
  6632. * 256 - `_.ary`
  6633. * 512 - `_.flip`
  6634. * @param {*} [thisArg] The `this` binding of `func`.
  6635. * @param {Array} [partials] The arguments to be partially applied.
  6636. * @param {Array} [holders] The `partials` placeholder indexes.
  6637. * @param {Array} [argPos] The argument positions of the new function.
  6638. * @param {number} [ary] The arity cap of `func`.
  6639. * @param {number} [arity] The arity of `func`.
  6640. * @returns {Function} Returns the new wrapped function.
  6641. */
  6642. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  6643. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  6644. if (!isBindKey && typeof func != 'function') {
  6645. throw new TypeError(FUNC_ERROR_TEXT);
  6646. }
  6647. var length = partials ? partials.length : 0;
  6648. if (!length) {
  6649. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  6650. partials = holders = undefined;
  6651. }
  6652. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  6653. arity = arity === undefined ? arity : toInteger(arity);
  6654. length -= holders ? holders.length : 0;
  6655. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  6656. var partialsRight = partials,
  6657. holdersRight = holders;
  6658. partials = holders = undefined;
  6659. }
  6660. var data = isBindKey ? undefined : getData(func);
  6661. var newData = [
  6662. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  6663. argPos, ary, arity
  6664. ];
  6665. if (data) {
  6666. mergeData(newData, data);
  6667. }
  6668. func = newData[0];
  6669. bitmask = newData[1];
  6670. thisArg = newData[2];
  6671. partials = newData[3];
  6672. holders = newData[4];
  6673. arity = newData[9] = newData[9] === undefined
  6674. ? (isBindKey ? 0 : func.length)
  6675. : nativeMax(newData[9] - length, 0);
  6676. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  6677. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  6678. }
  6679. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  6680. var result = createBind(func, bitmask, thisArg);
  6681. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  6682. result = createCurry(func, bitmask, arity);
  6683. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  6684. result = createPartial(func, bitmask, thisArg, partials);
  6685. } else {
  6686. result = createHybrid.apply(undefined, newData);
  6687. }
  6688. var setter = data ? baseSetData : setData;
  6689. return setWrapToString(setter(result, newData), func, bitmask);
  6690. }
  6691. /**
  6692. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  6693. * of source objects to the destination object for all destination properties
  6694. * that resolve to `undefined`.
  6695. *
  6696. * @private
  6697. * @param {*} objValue The destination value.
  6698. * @param {*} srcValue The source value.
  6699. * @param {string} key The key of the property to assign.
  6700. * @param {Object} object The parent object of `objValue`.
  6701. * @returns {*} Returns the value to assign.
  6702. */
  6703. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  6704. if (objValue === undefined ||
  6705. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  6706. return srcValue;
  6707. }
  6708. return objValue;
  6709. }
  6710. /**
  6711. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  6712. * objects into destination objects that are passed thru.
  6713. *
  6714. * @private
  6715. * @param {*} objValue The destination value.
  6716. * @param {*} srcValue The source value.
  6717. * @param {string} key The key of the property to merge.
  6718. * @param {Object} object The parent object of `objValue`.
  6719. * @param {Object} source The parent object of `srcValue`.
  6720. * @param {Object} [stack] Tracks traversed source values and their merged
  6721. * counterparts.
  6722. * @returns {*} Returns the value to assign.
  6723. */
  6724. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  6725. if (isObject(objValue) && isObject(srcValue)) {
  6726. // Recursively merge objects and arrays (susceptible to call stack limits).
  6727. stack.set(srcValue, objValue);
  6728. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  6729. stack['delete'](srcValue);
  6730. }
  6731. return objValue;
  6732. }
  6733. /**
  6734. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  6735. * objects.
  6736. *
  6737. * @private
  6738. * @param {*} value The value to inspect.
  6739. * @param {string} key The key of the property to inspect.
  6740. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  6741. */
  6742. function customOmitClone(value) {
  6743. return isPlainObject(value) ? undefined : value;
  6744. }
  6745. /**
  6746. * A specialized version of `baseIsEqualDeep` for arrays with support for
  6747. * partial deep comparisons.
  6748. *
  6749. * @private
  6750. * @param {Array} array The array to compare.
  6751. * @param {Array} other The other array to compare.
  6752. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  6753. * @param {Function} customizer The function to customize comparisons.
  6754. * @param {Function} equalFunc The function to determine equivalents of values.
  6755. * @param {Object} stack Tracks traversed `array` and `other` objects.
  6756. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  6757. */
  6758. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  6759. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  6760. arrLength = array.length,
  6761. othLength = other.length;
  6762. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  6763. return false;
  6764. }
  6765. // Check that cyclic values are equal.
  6766. var arrStacked = stack.get(array);
  6767. var othStacked = stack.get(other);
  6768. if (arrStacked && othStacked) {
  6769. return arrStacked == other && othStacked == array;
  6770. }
  6771. var index = -1,
  6772. result = true,
  6773. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  6774. stack.set(array, other);
  6775. stack.set(other, array);
  6776. // Ignore non-index properties.
  6777. while (++index < arrLength) {
  6778. var arrValue = array[index],
  6779. othValue = other[index];
  6780. if (customizer) {
  6781. var compared = isPartial
  6782. ? customizer(othValue, arrValue, index, other, array, stack)
  6783. : customizer(arrValue, othValue, index, array, other, stack);
  6784. }
  6785. if (compared !== undefined) {
  6786. if (compared) {
  6787. continue;
  6788. }
  6789. result = false;
  6790. break;
  6791. }
  6792. // Recursively compare arrays (susceptible to call stack limits).
  6793. if (seen) {
  6794. if (!arraySome(other, function(othValue, othIndex) {
  6795. if (!cacheHas(seen, othIndex) &&
  6796. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  6797. return seen.push(othIndex);
  6798. }
  6799. })) {
  6800. result = false;
  6801. break;
  6802. }
  6803. } else if (!(
  6804. arrValue === othValue ||
  6805. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  6806. )) {
  6807. result = false;
  6808. break;
  6809. }
  6810. }
  6811. stack['delete'](array);
  6812. stack['delete'](other);
  6813. return result;
  6814. }
  6815. /**
  6816. * A specialized version of `baseIsEqualDeep` for comparing objects of
  6817. * the same `toStringTag`.
  6818. *
  6819. * **Note:** This function only supports comparing values with tags of
  6820. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  6821. *
  6822. * @private
  6823. * @param {Object} object The object to compare.
  6824. * @param {Object} other The other object to compare.
  6825. * @param {string} tag The `toStringTag` of the objects to compare.
  6826. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  6827. * @param {Function} customizer The function to customize comparisons.
  6828. * @param {Function} equalFunc The function to determine equivalents of values.
  6829. * @param {Object} stack Tracks traversed `object` and `other` objects.
  6830. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  6831. */
  6832. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  6833. switch (tag) {
  6834. case dataViewTag:
  6835. if ((object.byteLength != other.byteLength) ||
  6836. (object.byteOffset != other.byteOffset)) {
  6837. return false;
  6838. }
  6839. object = object.buffer;
  6840. other = other.buffer;
  6841. case arrayBufferTag:
  6842. if ((object.byteLength != other.byteLength) ||
  6843. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  6844. return false;
  6845. }
  6846. return true;
  6847. case boolTag:
  6848. case dateTag:
  6849. case numberTag:
  6850. // Coerce booleans to `1` or `0` and dates to milliseconds.
  6851. // Invalid dates are coerced to `NaN`.
  6852. return eq(+object, +other);
  6853. case errorTag:
  6854. return object.name == other.name && object.message == other.message;
  6855. case regexpTag:
  6856. case stringTag:
  6857. // Coerce regexes to strings and treat strings, primitives and objects,
  6858. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  6859. // for more details.
  6860. return object == (other + '');
  6861. case mapTag:
  6862. var convert = mapToArray;
  6863. case setTag:
  6864. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  6865. convert || (convert = setToArray);
  6866. if (object.size != other.size && !isPartial) {
  6867. return false;
  6868. }
  6869. // Assume cyclic values are equal.
  6870. var stacked = stack.get(object);
  6871. if (stacked) {
  6872. return stacked == other;
  6873. }
  6874. bitmask |= COMPARE_UNORDERED_FLAG;
  6875. // Recursively compare objects (susceptible to call stack limits).
  6876. stack.set(object, other);
  6877. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  6878. stack['delete'](object);
  6879. return result;
  6880. case symbolTag:
  6881. if (symbolValueOf) {
  6882. return symbolValueOf.call(object) == symbolValueOf.call(other);
  6883. }
  6884. }
  6885. return false;
  6886. }
  6887. /**
  6888. * A specialized version of `baseIsEqualDeep` for objects with support for
  6889. * partial deep comparisons.
  6890. *
  6891. * @private
  6892. * @param {Object} object The object to compare.
  6893. * @param {Object} other The other object to compare.
  6894. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  6895. * @param {Function} customizer The function to customize comparisons.
  6896. * @param {Function} equalFunc The function to determine equivalents of values.
  6897. * @param {Object} stack Tracks traversed `object` and `other` objects.
  6898. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  6899. */
  6900. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  6901. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  6902. objProps = getAllKeys(object),
  6903. objLength = objProps.length,
  6904. othProps = getAllKeys(other),
  6905. othLength = othProps.length;
  6906. if (objLength != othLength && !isPartial) {
  6907. return false;
  6908. }
  6909. var index = objLength;
  6910. while (index--) {
  6911. var key = objProps[index];
  6912. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  6913. return false;
  6914. }
  6915. }
  6916. // Check that cyclic values are equal.
  6917. var objStacked = stack.get(object);
  6918. var othStacked = stack.get(other);
  6919. if (objStacked && othStacked) {
  6920. return objStacked == other && othStacked == object;
  6921. }
  6922. var result = true;
  6923. stack.set(object, other);
  6924. stack.set(other, object);
  6925. var skipCtor = isPartial;
  6926. while (++index < objLength) {
  6927. key = objProps[index];
  6928. var objValue = object[key],
  6929. othValue = other[key];
  6930. if (customizer) {
  6931. var compared = isPartial
  6932. ? customizer(othValue, objValue, key, other, object, stack)
  6933. : customizer(objValue, othValue, key, object, other, stack);
  6934. }
  6935. // Recursively compare objects (susceptible to call stack limits).
  6936. if (!(compared === undefined
  6937. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  6938. : compared
  6939. )) {
  6940. result = false;
  6941. break;
  6942. }
  6943. skipCtor || (skipCtor = key == 'constructor');
  6944. }
  6945. if (result && !skipCtor) {
  6946. var objCtor = object.constructor,
  6947. othCtor = other.constructor;
  6948. // Non `Object` object instances with different constructors are not equal.
  6949. if (objCtor != othCtor &&
  6950. ('constructor' in object && 'constructor' in other) &&
  6951. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  6952. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  6953. result = false;
  6954. }
  6955. }
  6956. stack['delete'](object);
  6957. stack['delete'](other);
  6958. return result;
  6959. }
  6960. /**
  6961. * A specialized version of `baseRest` which flattens the rest array.
  6962. *
  6963. * @private
  6964. * @param {Function} func The function to apply a rest parameter to.
  6965. * @returns {Function} Returns the new function.
  6966. */
  6967. function flatRest(func) {
  6968. return setToString(overRest(func, undefined, flatten), func + '');
  6969. }
  6970. /**
  6971. * Creates an array of own enumerable property names and symbols of `object`.
  6972. *
  6973. * @private
  6974. * @param {Object} object The object to query.
  6975. * @returns {Array} Returns the array of property names and symbols.
  6976. */
  6977. function getAllKeys(object) {
  6978. return baseGetAllKeys(object, keys, getSymbols);
  6979. }
  6980. /**
  6981. * Creates an array of own and inherited enumerable property names and
  6982. * symbols of `object`.
  6983. *
  6984. * @private
  6985. * @param {Object} object The object to query.
  6986. * @returns {Array} Returns the array of property names and symbols.
  6987. */
  6988. function getAllKeysIn(object) {
  6989. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  6990. }
  6991. /**
  6992. * Gets metadata for `func`.
  6993. *
  6994. * @private
  6995. * @param {Function} func The function to query.
  6996. * @returns {*} Returns the metadata for `func`.
  6997. */
  6998. var getData = !metaMap ? noop : function(func) {
  6999. return metaMap.get(func);
  7000. };
  7001. /**
  7002. * Gets the name of `func`.
  7003. *
  7004. * @private
  7005. * @param {Function} func The function to query.
  7006. * @returns {string} Returns the function name.
  7007. */
  7008. function getFuncName(func) {
  7009. var result = (func.name + ''),
  7010. array = realNames[result],
  7011. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  7012. while (length--) {
  7013. var data = array[length],
  7014. otherFunc = data.func;
  7015. if (otherFunc == null || otherFunc == func) {
  7016. return data.name;
  7017. }
  7018. }
  7019. return result;
  7020. }
  7021. /**
  7022. * Gets the argument placeholder value for `func`.
  7023. *
  7024. * @private
  7025. * @param {Function} func The function to inspect.
  7026. * @returns {*} Returns the placeholder value.
  7027. */
  7028. function getHolder(func) {
  7029. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  7030. return object.placeholder;
  7031. }
  7032. /**
  7033. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  7034. * this function returns the custom method, otherwise it returns `baseIteratee`.
  7035. * If arguments are provided, the chosen function is invoked with them and
  7036. * its result is returned.
  7037. *
  7038. * @private
  7039. * @param {*} [value] The value to convert to an iteratee.
  7040. * @param {number} [arity] The arity of the created iteratee.
  7041. * @returns {Function} Returns the chosen function or its result.
  7042. */
  7043. function getIteratee() {
  7044. var result = lodash.iteratee || iteratee;
  7045. result = result === iteratee ? baseIteratee : result;
  7046. return arguments.length ? result(arguments[0], arguments[1]) : result;
  7047. }
  7048. /**
  7049. * Gets the data for `map`.
  7050. *
  7051. * @private
  7052. * @param {Object} map The map to query.
  7053. * @param {string} key The reference key.
  7054. * @returns {*} Returns the map data.
  7055. */
  7056. function getMapData(map, key) {
  7057. var data = map.__data__;
  7058. return isKeyable(key)
  7059. ? data[typeof key == 'string' ? 'string' : 'hash']
  7060. : data.map;
  7061. }
  7062. /**
  7063. * Gets the property names, values, and compare flags of `object`.
  7064. *
  7065. * @private
  7066. * @param {Object} object The object to query.
  7067. * @returns {Array} Returns the match data of `object`.
  7068. */
  7069. function getMatchData(object) {
  7070. var result = keys(object),
  7071. length = result.length;
  7072. while (length--) {
  7073. var key = result[length],
  7074. value = object[key];
  7075. result[length] = [key, value, isStrictComparable(value)];
  7076. }
  7077. return result;
  7078. }
  7079. /**
  7080. * Gets the native function at `key` of `object`.
  7081. *
  7082. * @private
  7083. * @param {Object} object The object to query.
  7084. * @param {string} key The key of the method to get.
  7085. * @returns {*} Returns the function if it's native, else `undefined`.
  7086. */
  7087. function getNative(object, key) {
  7088. var value = getValue(object, key);
  7089. return baseIsNative(value) ? value : undefined;
  7090. }
  7091. /**
  7092. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  7093. *
  7094. * @private
  7095. * @param {*} value The value to query.
  7096. * @returns {string} Returns the raw `toStringTag`.
  7097. */
  7098. function getRawTag(value) {
  7099. var isOwn = hasOwnProperty.call(value, symToStringTag),
  7100. tag = value[symToStringTag];
  7101. try {
  7102. value[symToStringTag] = undefined;
  7103. var unmasked = true;
  7104. } catch (e) {}
  7105. var result = nativeObjectToString.call(value);
  7106. if (unmasked) {
  7107. if (isOwn) {
  7108. value[symToStringTag] = tag;
  7109. } else {
  7110. delete value[symToStringTag];
  7111. }
  7112. }
  7113. return result;
  7114. }
  7115. /**
  7116. * Creates an array of the own enumerable symbols of `object`.
  7117. *
  7118. * @private
  7119. * @param {Object} object The object to query.
  7120. * @returns {Array} Returns the array of symbols.
  7121. */
  7122. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  7123. if (object == null) {
  7124. return [];
  7125. }
  7126. object = Object(object);
  7127. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  7128. return propertyIsEnumerable.call(object, symbol);
  7129. });
  7130. };
  7131. /**
  7132. * Creates an array of the own and inherited enumerable symbols of `object`.
  7133. *
  7134. * @private
  7135. * @param {Object} object The object to query.
  7136. * @returns {Array} Returns the array of symbols.
  7137. */
  7138. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  7139. var result = [];
  7140. while (object) {
  7141. arrayPush(result, getSymbols(object));
  7142. object = getPrototype(object);
  7143. }
  7144. return result;
  7145. };
  7146. /**
  7147. * Gets the `toStringTag` of `value`.
  7148. *
  7149. * @private
  7150. * @param {*} value The value to query.
  7151. * @returns {string} Returns the `toStringTag`.
  7152. */
  7153. var getTag = baseGetTag;
  7154. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  7155. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  7156. (Map && getTag(new Map) != mapTag) ||
  7157. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  7158. (Set && getTag(new Set) != setTag) ||
  7159. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  7160. getTag = function(value) {
  7161. var result = baseGetTag(value),
  7162. Ctor = result == objectTag ? value.constructor : undefined,
  7163. ctorString = Ctor ? toSource(Ctor) : '';
  7164. if (ctorString) {
  7165. switch (ctorString) {
  7166. case dataViewCtorString: return dataViewTag;
  7167. case mapCtorString: return mapTag;
  7168. case promiseCtorString: return promiseTag;
  7169. case setCtorString: return setTag;
  7170. case weakMapCtorString: return weakMapTag;
  7171. }
  7172. }
  7173. return result;
  7174. };
  7175. }
  7176. /**
  7177. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  7178. *
  7179. * @private
  7180. * @param {number} start The start of the view.
  7181. * @param {number} end The end of the view.
  7182. * @param {Array} transforms The transformations to apply to the view.
  7183. * @returns {Object} Returns an object containing the `start` and `end`
  7184. * positions of the view.
  7185. */
  7186. function getView(start, end, transforms) {
  7187. var index = -1,
  7188. length = transforms.length;
  7189. while (++index < length) {
  7190. var data = transforms[index],
  7191. size = data.size;
  7192. switch (data.type) {
  7193. case 'drop': start += size; break;
  7194. case 'dropRight': end -= size; break;
  7195. case 'take': end = nativeMin(end, start + size); break;
  7196. case 'takeRight': start = nativeMax(start, end - size); break;
  7197. }
  7198. }
  7199. return { 'start': start, 'end': end };
  7200. }
  7201. /**
  7202. * Extracts wrapper details from the `source` body comment.
  7203. *
  7204. * @private
  7205. * @param {string} source The source to inspect.
  7206. * @returns {Array} Returns the wrapper details.
  7207. */
  7208. function getWrapDetails(source) {
  7209. var match = source.match(reWrapDetails);
  7210. return match ? match[1].split(reSplitDetails) : [];
  7211. }
  7212. /**
  7213. * Checks if `path` exists on `object`.
  7214. *
  7215. * @private
  7216. * @param {Object} object The object to query.
  7217. * @param {Array|string} path The path to check.
  7218. * @param {Function} hasFunc The function to check properties.
  7219. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  7220. */
  7221. function hasPath(object, path, hasFunc) {
  7222. path = castPath(path, object);
  7223. var index = -1,
  7224. length = path.length,
  7225. result = false;
  7226. while (++index < length) {
  7227. var key = toKey(path[index]);
  7228. if (!(result = object != null && hasFunc(object, key))) {
  7229. break;
  7230. }
  7231. object = object[key];
  7232. }
  7233. if (result || ++index != length) {
  7234. return result;
  7235. }
  7236. length = object == null ? 0 : object.length;
  7237. return !!length && isLength(length) && isIndex(key, length) &&
  7238. (isArray(object) || isArguments(object));
  7239. }
  7240. /**
  7241. * Initializes an array clone.
  7242. *
  7243. * @private
  7244. * @param {Array} array The array to clone.
  7245. * @returns {Array} Returns the initialized clone.
  7246. */
  7247. function initCloneArray(array) {
  7248. var length = array.length,
  7249. result = new array.constructor(length);
  7250. // Add properties assigned by `RegExp#exec`.
  7251. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  7252. result.index = array.index;
  7253. result.input = array.input;
  7254. }
  7255. return result;
  7256. }
  7257. /**
  7258. * Initializes an object clone.
  7259. *
  7260. * @private
  7261. * @param {Object} object The object to clone.
  7262. * @returns {Object} Returns the initialized clone.
  7263. */
  7264. function initCloneObject(object) {
  7265. return (typeof object.constructor == 'function' && !isPrototype(object))
  7266. ? baseCreate(getPrototype(object))
  7267. : {};
  7268. }
  7269. /**
  7270. * Initializes an object clone based on its `toStringTag`.
  7271. *
  7272. * **Note:** This function only supports cloning values with tags of
  7273. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  7274. *
  7275. * @private
  7276. * @param {Object} object The object to clone.
  7277. * @param {string} tag The `toStringTag` of the object to clone.
  7278. * @param {boolean} [isDeep] Specify a deep clone.
  7279. * @returns {Object} Returns the initialized clone.
  7280. */
  7281. function initCloneByTag(object, tag, isDeep) {
  7282. var Ctor = object.constructor;
  7283. switch (tag) {
  7284. case arrayBufferTag:
  7285. return cloneArrayBuffer(object);
  7286. case boolTag:
  7287. case dateTag:
  7288. return new Ctor(+object);
  7289. case dataViewTag:
  7290. return cloneDataView(object, isDeep);
  7291. case float32Tag: case float64Tag:
  7292. case int8Tag: case int16Tag: case int32Tag:
  7293. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  7294. return cloneTypedArray(object, isDeep);
  7295. case mapTag:
  7296. return new Ctor;
  7297. case numberTag:
  7298. case stringTag:
  7299. return new Ctor(object);
  7300. case regexpTag:
  7301. return cloneRegExp(object);
  7302. case setTag:
  7303. return new Ctor;
  7304. case symbolTag:
  7305. return cloneSymbol(object);
  7306. }
  7307. }
  7308. /**
  7309. * Inserts wrapper `details` in a comment at the top of the `source` body.
  7310. *
  7311. * @private
  7312. * @param {string} source The source to modify.
  7313. * @returns {Array} details The details to insert.
  7314. * @returns {string} Returns the modified source.
  7315. */
  7316. function insertWrapDetails(source, details) {
  7317. var length = details.length;
  7318. if (!length) {
  7319. return source;
  7320. }
  7321. var lastIndex = length - 1;
  7322. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  7323. details = details.join(length > 2 ? ', ' : ' ');
  7324. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  7325. }
  7326. /**
  7327. * Checks if `value` is a flattenable `arguments` object or array.
  7328. *
  7329. * @private
  7330. * @param {*} value The value to check.
  7331. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  7332. */
  7333. function isFlattenable(value) {
  7334. return isArray(value) || isArguments(value) ||
  7335. !!(spreadableSymbol && value && value[spreadableSymbol]);
  7336. }
  7337. /**
  7338. * Checks if `value` is a valid array-like index.
  7339. *
  7340. * @private
  7341. * @param {*} value The value to check.
  7342. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  7343. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  7344. */
  7345. function isIndex(value, length) {
  7346. var type = typeof value;
  7347. length = length == null ? MAX_SAFE_INTEGER : length;
  7348. return !!length &&
  7349. (type == 'number' ||
  7350. (type != 'symbol' && reIsUint.test(value))) &&
  7351. (value > -1 && value % 1 == 0 && value < length);
  7352. }
  7353. /**
  7354. * Checks if the given arguments are from an iteratee call.
  7355. *
  7356. * @private
  7357. * @param {*} value The potential iteratee value argument.
  7358. * @param {*} index The potential iteratee index or key argument.
  7359. * @param {*} object The potential iteratee object argument.
  7360. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  7361. * else `false`.
  7362. */
  7363. function isIterateeCall(value, index, object) {
  7364. if (!isObject(object)) {
  7365. return false;
  7366. }
  7367. var type = typeof index;
  7368. if (type == 'number'
  7369. ? (isArrayLike(object) && isIndex(index, object.length))
  7370. : (type == 'string' && index in object)
  7371. ) {
  7372. return eq(object[index], value);
  7373. }
  7374. return false;
  7375. }
  7376. /**
  7377. * Checks if `value` is a property name and not a property path.
  7378. *
  7379. * @private
  7380. * @param {*} value The value to check.
  7381. * @param {Object} [object] The object to query keys on.
  7382. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  7383. */
  7384. function isKey(value, object) {
  7385. if (isArray(value)) {
  7386. return false;
  7387. }
  7388. var type = typeof value;
  7389. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  7390. value == null || isSymbol(value)) {
  7391. return true;
  7392. }
  7393. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  7394. (object != null && value in Object(object));
  7395. }
  7396. /**
  7397. * Checks if `value` is suitable for use as unique object key.
  7398. *
  7399. * @private
  7400. * @param {*} value The value to check.
  7401. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  7402. */
  7403. function isKeyable(value) {
  7404. var type = typeof value;
  7405. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  7406. ? (value !== '__proto__')
  7407. : (value === null);
  7408. }
  7409. /**
  7410. * Checks if `func` has a lazy counterpart.
  7411. *
  7412. * @private
  7413. * @param {Function} func The function to check.
  7414. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  7415. * else `false`.
  7416. */
  7417. function isLaziable(func) {
  7418. var funcName = getFuncName(func),
  7419. other = lodash[funcName];
  7420. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  7421. return false;
  7422. }
  7423. if (func === other) {
  7424. return true;
  7425. }
  7426. var data = getData(other);
  7427. return !!data && func === data[0];
  7428. }
  7429. /**
  7430. * Checks if `func` has its source masked.
  7431. *
  7432. * @private
  7433. * @param {Function} func The function to check.
  7434. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  7435. */
  7436. function isMasked(func) {
  7437. return !!maskSrcKey && (maskSrcKey in func);
  7438. }
  7439. /**
  7440. * Checks if `func` is capable of being masked.
  7441. *
  7442. * @private
  7443. * @param {*} value The value to check.
  7444. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  7445. */
  7446. var isMaskable = coreJsData ? isFunction : stubFalse;
  7447. /**
  7448. * Checks if `value` is likely a prototype object.
  7449. *
  7450. * @private
  7451. * @param {*} value The value to check.
  7452. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  7453. */
  7454. function isPrototype(value) {
  7455. var Ctor = value && value.constructor,
  7456. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  7457. return value === proto;
  7458. }
  7459. /**
  7460. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  7461. *
  7462. * @private
  7463. * @param {*} value The value to check.
  7464. * @returns {boolean} Returns `true` if `value` if suitable for strict
  7465. * equality comparisons, else `false`.
  7466. */
  7467. function isStrictComparable(value) {
  7468. return value === value && !isObject(value);
  7469. }
  7470. /**
  7471. * A specialized version of `matchesProperty` for source values suitable
  7472. * for strict equality comparisons, i.e. `===`.
  7473. *
  7474. * @private
  7475. * @param {string} key The key of the property to get.
  7476. * @param {*} srcValue The value to match.
  7477. * @returns {Function} Returns the new spec function.
  7478. */
  7479. function matchesStrictComparable(key, srcValue) {
  7480. return function(object) {
  7481. if (object == null) {
  7482. return false;
  7483. }
  7484. return object[key] === srcValue &&
  7485. (srcValue !== undefined || (key in Object(object)));
  7486. };
  7487. }
  7488. /**
  7489. * A specialized version of `_.memoize` which clears the memoized function's
  7490. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  7491. *
  7492. * @private
  7493. * @param {Function} func The function to have its output memoized.
  7494. * @returns {Function} Returns the new memoized function.
  7495. */
  7496. function memoizeCapped(func) {
  7497. var result = memoize(func, function(key) {
  7498. if (cache.size === MAX_MEMOIZE_SIZE) {
  7499. cache.clear();
  7500. }
  7501. return key;
  7502. });
  7503. var cache = result.cache;
  7504. return result;
  7505. }
  7506. /**
  7507. * Merges the function metadata of `source` into `data`.
  7508. *
  7509. * Merging metadata reduces the number of wrappers used to invoke a function.
  7510. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  7511. * may be applied regardless of execution order. Methods like `_.ary` and
  7512. * `_.rearg` modify function arguments, making the order in which they are
  7513. * executed important, preventing the merging of metadata. However, we make
  7514. * an exception for a safe combined case where curried functions have `_.ary`
  7515. * and or `_.rearg` applied.
  7516. *
  7517. * @private
  7518. * @param {Array} data The destination metadata.
  7519. * @param {Array} source The source metadata.
  7520. * @returns {Array} Returns `data`.
  7521. */
  7522. function mergeData(data, source) {
  7523. var bitmask = data[1],
  7524. srcBitmask = source[1],
  7525. newBitmask = bitmask | srcBitmask,
  7526. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  7527. var isCombo =
  7528. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  7529. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  7530. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  7531. // Exit early if metadata can't be merged.
  7532. if (!(isCommon || isCombo)) {
  7533. return data;
  7534. }
  7535. // Use source `thisArg` if available.
  7536. if (srcBitmask & WRAP_BIND_FLAG) {
  7537. data[2] = source[2];
  7538. // Set when currying a bound function.
  7539. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  7540. }
  7541. // Compose partial arguments.
  7542. var value = source[3];
  7543. if (value) {
  7544. var partials = data[3];
  7545. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  7546. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  7547. }
  7548. // Compose partial right arguments.
  7549. value = source[5];
  7550. if (value) {
  7551. partials = data[5];
  7552. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  7553. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  7554. }
  7555. // Use source `argPos` if available.
  7556. value = source[7];
  7557. if (value) {
  7558. data[7] = value;
  7559. }
  7560. // Use source `ary` if it's smaller.
  7561. if (srcBitmask & WRAP_ARY_FLAG) {
  7562. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  7563. }
  7564. // Use source `arity` if one is not provided.
  7565. if (data[9] == null) {
  7566. data[9] = source[9];
  7567. }
  7568. // Use source `func` and merge bitmasks.
  7569. data[0] = source[0];
  7570. data[1] = newBitmask;
  7571. return data;
  7572. }
  7573. /**
  7574. * This function is like
  7575. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  7576. * except that it includes inherited enumerable properties.
  7577. *
  7578. * @private
  7579. * @param {Object} object The object to query.
  7580. * @returns {Array} Returns the array of property names.
  7581. */
  7582. function nativeKeysIn(object) {
  7583. var result = [];
  7584. if (object != null) {
  7585. for (var key in Object(object)) {
  7586. result.push(key);
  7587. }
  7588. }
  7589. return result;
  7590. }
  7591. /**
  7592. * Converts `value` to a string using `Object.prototype.toString`.
  7593. *
  7594. * @private
  7595. * @param {*} value The value to convert.
  7596. * @returns {string} Returns the converted string.
  7597. */
  7598. function objectToString(value) {
  7599. return nativeObjectToString.call(value);
  7600. }
  7601. /**
  7602. * A specialized version of `baseRest` which transforms the rest array.
  7603. *
  7604. * @private
  7605. * @param {Function} func The function to apply a rest parameter to.
  7606. * @param {number} [start=func.length-1] The start position of the rest parameter.
  7607. * @param {Function} transform The rest array transform.
  7608. * @returns {Function} Returns the new function.
  7609. */
  7610. function overRest(func, start, transform) {
  7611. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  7612. return function() {
  7613. var args = arguments,
  7614. index = -1,
  7615. length = nativeMax(args.length - start, 0),
  7616. array = Array(length);
  7617. while (++index < length) {
  7618. array[index] = args[start + index];
  7619. }
  7620. index = -1;
  7621. var otherArgs = Array(start + 1);
  7622. while (++index < start) {
  7623. otherArgs[index] = args[index];
  7624. }
  7625. otherArgs[start] = transform(array);
  7626. return apply(func, this, otherArgs);
  7627. };
  7628. }
  7629. /**
  7630. * Gets the parent value at `path` of `object`.
  7631. *
  7632. * @private
  7633. * @param {Object} object The object to query.
  7634. * @param {Array} path The path to get the parent value of.
  7635. * @returns {*} Returns the parent value.
  7636. */
  7637. function parent(object, path) {
  7638. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  7639. }
  7640. /**
  7641. * Reorder `array` according to the specified indexes where the element at
  7642. * the first index is assigned as the first element, the element at
  7643. * the second index is assigned as the second element, and so on.
  7644. *
  7645. * @private
  7646. * @param {Array} array The array to reorder.
  7647. * @param {Array} indexes The arranged array indexes.
  7648. * @returns {Array} Returns `array`.
  7649. */
  7650. function reorder(array, indexes) {
  7651. var arrLength = array.length,
  7652. length = nativeMin(indexes.length, arrLength),
  7653. oldArray = copyArray(array);
  7654. while (length--) {
  7655. var index = indexes[length];
  7656. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  7657. }
  7658. return array;
  7659. }
  7660. /**
  7661. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  7662. *
  7663. * @private
  7664. * @param {Object} object The object to query.
  7665. * @param {string} key The key of the property to get.
  7666. * @returns {*} Returns the property value.
  7667. */
  7668. function safeGet(object, key) {
  7669. if (key === 'constructor' && typeof object[key] === 'function') {
  7670. return;
  7671. }
  7672. if (key == '__proto__') {
  7673. return;
  7674. }
  7675. return object[key];
  7676. }
  7677. /**
  7678. * Sets metadata for `func`.
  7679. *
  7680. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  7681. * period of time, it will trip its breaker and transition to an identity
  7682. * function to avoid garbage collection pauses in V8. See
  7683. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  7684. * for more details.
  7685. *
  7686. * @private
  7687. * @param {Function} func The function to associate metadata with.
  7688. * @param {*} data The metadata.
  7689. * @returns {Function} Returns `func`.
  7690. */
  7691. var setData = shortOut(baseSetData);
  7692. /**
  7693. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  7694. *
  7695. * @private
  7696. * @param {Function} func The function to delay.
  7697. * @param {number} wait The number of milliseconds to delay invocation.
  7698. * @returns {number|Object} Returns the timer id or timeout object.
  7699. */
  7700. var setTimeout = ctxSetTimeout || function(func, wait) {
  7701. return root.setTimeout(func, wait);
  7702. };
  7703. /**
  7704. * Sets the `toString` method of `func` to return `string`.
  7705. *
  7706. * @private
  7707. * @param {Function} func The function to modify.
  7708. * @param {Function} string The `toString` result.
  7709. * @returns {Function} Returns `func`.
  7710. */
  7711. var setToString = shortOut(baseSetToString);
  7712. /**
  7713. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  7714. * with wrapper details in a comment at the top of the source body.
  7715. *
  7716. * @private
  7717. * @param {Function} wrapper The function to modify.
  7718. * @param {Function} reference The reference function.
  7719. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7720. * @returns {Function} Returns `wrapper`.
  7721. */
  7722. function setWrapToString(wrapper, reference, bitmask) {
  7723. var source = (reference + '');
  7724. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  7725. }
  7726. /**
  7727. * Creates a function that'll short out and invoke `identity` instead
  7728. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  7729. * milliseconds.
  7730. *
  7731. * @private
  7732. * @param {Function} func The function to restrict.
  7733. * @returns {Function} Returns the new shortable function.
  7734. */
  7735. function shortOut(func) {
  7736. var count = 0,
  7737. lastCalled = 0;
  7738. return function() {
  7739. var stamp = nativeNow(),
  7740. remaining = HOT_SPAN - (stamp - lastCalled);
  7741. lastCalled = stamp;
  7742. if (remaining > 0) {
  7743. if (++count >= HOT_COUNT) {
  7744. return arguments[0];
  7745. }
  7746. } else {
  7747. count = 0;
  7748. }
  7749. return func.apply(undefined, arguments);
  7750. };
  7751. }
  7752. /**
  7753. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  7754. *
  7755. * @private
  7756. * @param {Array} array The array to shuffle.
  7757. * @param {number} [size=array.length] The size of `array`.
  7758. * @returns {Array} Returns `array`.
  7759. */
  7760. function shuffleSelf(array, size) {
  7761. var index = -1,
  7762. length = array.length,
  7763. lastIndex = length - 1;
  7764. size = size === undefined ? length : size;
  7765. while (++index < size) {
  7766. var rand = baseRandom(index, lastIndex),
  7767. value = array[rand];
  7768. array[rand] = array[index];
  7769. array[index] = value;
  7770. }
  7771. array.length = size;
  7772. return array;
  7773. }
  7774. /**
  7775. * Converts `string` to a property path array.
  7776. *
  7777. * @private
  7778. * @param {string} string The string to convert.
  7779. * @returns {Array} Returns the property path array.
  7780. */
  7781. var stringToPath = memoizeCapped(function(string) {
  7782. var result = [];
  7783. if (string.charCodeAt(0) === 46 /* . */) {
  7784. result.push('');
  7785. }
  7786. string.replace(rePropName, function(match, number, quote, subString) {
  7787. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  7788. });
  7789. return result;
  7790. });
  7791. /**
  7792. * Converts `value` to a string key if it's not a string or symbol.
  7793. *
  7794. * @private
  7795. * @param {*} value The value to inspect.
  7796. * @returns {string|symbol} Returns the key.
  7797. */
  7798. function toKey(value) {
  7799. if (typeof value == 'string' || isSymbol(value)) {
  7800. return value;
  7801. }
  7802. var result = (value + '');
  7803. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  7804. }
  7805. /**
  7806. * Converts `func` to its source code.
  7807. *
  7808. * @private
  7809. * @param {Function} func The function to convert.
  7810. * @returns {string} Returns the source code.
  7811. */
  7812. function toSource(func) {
  7813. if (func != null) {
  7814. try {
  7815. return funcToString.call(func);
  7816. } catch (e) {}
  7817. try {
  7818. return (func + '');
  7819. } catch (e) {}
  7820. }
  7821. return '';
  7822. }
  7823. /**
  7824. * Updates wrapper `details` based on `bitmask` flags.
  7825. *
  7826. * @private
  7827. * @returns {Array} details The details to modify.
  7828. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7829. * @returns {Array} Returns `details`.
  7830. */
  7831. function updateWrapDetails(details, bitmask) {
  7832. arrayEach(wrapFlags, function(pair) {
  7833. var value = '_.' + pair[0];
  7834. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  7835. details.push(value);
  7836. }
  7837. });
  7838. return details.sort();
  7839. }
  7840. /**
  7841. * Creates a clone of `wrapper`.
  7842. *
  7843. * @private
  7844. * @param {Object} wrapper The wrapper to clone.
  7845. * @returns {Object} Returns the cloned wrapper.
  7846. */
  7847. function wrapperClone(wrapper) {
  7848. if (wrapper instanceof LazyWrapper) {
  7849. return wrapper.clone();
  7850. }
  7851. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  7852. result.__actions__ = copyArray(wrapper.__actions__);
  7853. result.__index__ = wrapper.__index__;
  7854. result.__values__ = wrapper.__values__;
  7855. return result;
  7856. }
  7857. /*------------------------------------------------------------------------*/
  7858. /**
  7859. * Creates an array of elements split into groups the length of `size`.
  7860. * If `array` can't be split evenly, the final chunk will be the remaining
  7861. * elements.
  7862. *
  7863. * @static
  7864. * @memberOf _
  7865. * @since 3.0.0
  7866. * @category Array
  7867. * @param {Array} array The array to process.
  7868. * @param {number} [size=1] The length of each chunk
  7869. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7870. * @returns {Array} Returns the new array of chunks.
  7871. * @example
  7872. *
  7873. * _.chunk(['a', 'b', 'c', 'd'], 2);
  7874. * // => [['a', 'b'], ['c', 'd']]
  7875. *
  7876. * _.chunk(['a', 'b', 'c', 'd'], 3);
  7877. * // => [['a', 'b', 'c'], ['d']]
  7878. */
  7879. function chunk(array, size, guard) {
  7880. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  7881. size = 1;
  7882. } else {
  7883. size = nativeMax(toInteger(size), 0);
  7884. }
  7885. var length = array == null ? 0 : array.length;
  7886. if (!length || size < 1) {
  7887. return [];
  7888. }
  7889. var index = 0,
  7890. resIndex = 0,
  7891. result = Array(nativeCeil(length / size));
  7892. while (index < length) {
  7893. result[resIndex++] = baseSlice(array, index, (index += size));
  7894. }
  7895. return result;
  7896. }
  7897. /**
  7898. * Creates an array with all falsey values removed. The values `false`, `null`,
  7899. * `0`, `""`, `undefined`, and `NaN` are falsey.
  7900. *
  7901. * @static
  7902. * @memberOf _
  7903. * @since 0.1.0
  7904. * @category Array
  7905. * @param {Array} array The array to compact.
  7906. * @returns {Array} Returns the new array of filtered values.
  7907. * @example
  7908. *
  7909. * _.compact([0, 1, false, 2, '', 3]);
  7910. * // => [1, 2, 3]
  7911. */
  7912. function compact(array) {
  7913. var index = -1,
  7914. length = array == null ? 0 : array.length,
  7915. resIndex = 0,
  7916. result = [];
  7917. while (++index < length) {
  7918. var value = array[index];
  7919. if (value) {
  7920. result[resIndex++] = value;
  7921. }
  7922. }
  7923. return result;
  7924. }
  7925. /**
  7926. * Creates a new array concatenating `array` with any additional arrays
  7927. * and/or values.
  7928. *
  7929. * @static
  7930. * @memberOf _
  7931. * @since 4.0.0
  7932. * @category Array
  7933. * @param {Array} array The array to concatenate.
  7934. * @param {...*} [values] The values to concatenate.
  7935. * @returns {Array} Returns the new concatenated array.
  7936. * @example
  7937. *
  7938. * var array = [1];
  7939. * var other = _.concat(array, 2, [3], [[4]]);
  7940. *
  7941. * console.log(other);
  7942. * // => [1, 2, 3, [4]]
  7943. *
  7944. * console.log(array);
  7945. * // => [1]
  7946. */
  7947. function concat() {
  7948. var length = arguments.length;
  7949. if (!length) {
  7950. return [];
  7951. }
  7952. var args = Array(length - 1),
  7953. array = arguments[0],
  7954. index = length;
  7955. while (index--) {
  7956. args[index - 1] = arguments[index];
  7957. }
  7958. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  7959. }
  7960. /**
  7961. * Creates an array of `array` values not included in the other given arrays
  7962. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7963. * for equality comparisons. The order and references of result values are
  7964. * determined by the first array.
  7965. *
  7966. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  7967. *
  7968. * @static
  7969. * @memberOf _
  7970. * @since 0.1.0
  7971. * @category Array
  7972. * @param {Array} array The array to inspect.
  7973. * @param {...Array} [values] The values to exclude.
  7974. * @returns {Array} Returns the new array of filtered values.
  7975. * @see _.without, _.xor
  7976. * @example
  7977. *
  7978. * _.difference([2, 1], [2, 3]);
  7979. * // => [1]
  7980. */
  7981. var difference = baseRest(function(array, values) {
  7982. return isArrayLikeObject(array)
  7983. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  7984. : [];
  7985. });
  7986. /**
  7987. * This method is like `_.difference` except that it accepts `iteratee` which
  7988. * is invoked for each element of `array` and `values` to generate the criterion
  7989. * by which they're compared. The order and references of result values are
  7990. * determined by the first array. The iteratee is invoked with one argument:
  7991. * (value).
  7992. *
  7993. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  7994. *
  7995. * @static
  7996. * @memberOf _
  7997. * @since 4.0.0
  7998. * @category Array
  7999. * @param {Array} array The array to inspect.
  8000. * @param {...Array} [values] The values to exclude.
  8001. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8002. * @returns {Array} Returns the new array of filtered values.
  8003. * @example
  8004. *
  8005. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  8006. * // => [1.2]
  8007. *
  8008. * // The `_.property` iteratee shorthand.
  8009. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  8010. * // => [{ 'x': 2 }]
  8011. */
  8012. var differenceBy = baseRest(function(array, values) {
  8013. var iteratee = last(values);
  8014. if (isArrayLikeObject(iteratee)) {
  8015. iteratee = undefined;
  8016. }
  8017. return isArrayLikeObject(array)
  8018. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  8019. : [];
  8020. });
  8021. /**
  8022. * This method is like `_.difference` except that it accepts `comparator`
  8023. * which is invoked to compare elements of `array` to `values`. The order and
  8024. * references of result values are determined by the first array. The comparator
  8025. * is invoked with two arguments: (arrVal, othVal).
  8026. *
  8027. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  8028. *
  8029. * @static
  8030. * @memberOf _
  8031. * @since 4.0.0
  8032. * @category Array
  8033. * @param {Array} array The array to inspect.
  8034. * @param {...Array} [values] The values to exclude.
  8035. * @param {Function} [comparator] The comparator invoked per element.
  8036. * @returns {Array} Returns the new array of filtered values.
  8037. * @example
  8038. *
  8039. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8040. *
  8041. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  8042. * // => [{ 'x': 2, 'y': 1 }]
  8043. */
  8044. var differenceWith = baseRest(function(array, values) {
  8045. var comparator = last(values);
  8046. if (isArrayLikeObject(comparator)) {
  8047. comparator = undefined;
  8048. }
  8049. return isArrayLikeObject(array)
  8050. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  8051. : [];
  8052. });
  8053. /**
  8054. * Creates a slice of `array` with `n` elements dropped from the beginning.
  8055. *
  8056. * @static
  8057. * @memberOf _
  8058. * @since 0.5.0
  8059. * @category Array
  8060. * @param {Array} array The array to query.
  8061. * @param {number} [n=1] The number of elements to drop.
  8062. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8063. * @returns {Array} Returns the slice of `array`.
  8064. * @example
  8065. *
  8066. * _.drop([1, 2, 3]);
  8067. * // => [2, 3]
  8068. *
  8069. * _.drop([1, 2, 3], 2);
  8070. * // => [3]
  8071. *
  8072. * _.drop([1, 2, 3], 5);
  8073. * // => []
  8074. *
  8075. * _.drop([1, 2, 3], 0);
  8076. * // => [1, 2, 3]
  8077. */
  8078. function drop(array, n, guard) {
  8079. var length = array == null ? 0 : array.length;
  8080. if (!length) {
  8081. return [];
  8082. }
  8083. n = (guard || n === undefined) ? 1 : toInteger(n);
  8084. return baseSlice(array, n < 0 ? 0 : n, length);
  8085. }
  8086. /**
  8087. * Creates a slice of `array` with `n` elements dropped from the end.
  8088. *
  8089. * @static
  8090. * @memberOf _
  8091. * @since 3.0.0
  8092. * @category Array
  8093. * @param {Array} array The array to query.
  8094. * @param {number} [n=1] The number of elements to drop.
  8095. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8096. * @returns {Array} Returns the slice of `array`.
  8097. * @example
  8098. *
  8099. * _.dropRight([1, 2, 3]);
  8100. * // => [1, 2]
  8101. *
  8102. * _.dropRight([1, 2, 3], 2);
  8103. * // => [1]
  8104. *
  8105. * _.dropRight([1, 2, 3], 5);
  8106. * // => []
  8107. *
  8108. * _.dropRight([1, 2, 3], 0);
  8109. * // => [1, 2, 3]
  8110. */
  8111. function dropRight(array, n, guard) {
  8112. var length = array == null ? 0 : array.length;
  8113. if (!length) {
  8114. return [];
  8115. }
  8116. n = (guard || n === undefined) ? 1 : toInteger(n);
  8117. n = length - n;
  8118. return baseSlice(array, 0, n < 0 ? 0 : n);
  8119. }
  8120. /**
  8121. * Creates a slice of `array` excluding elements dropped from the end.
  8122. * Elements are dropped until `predicate` returns falsey. The predicate is
  8123. * invoked with three arguments: (value, index, array).
  8124. *
  8125. * @static
  8126. * @memberOf _
  8127. * @since 3.0.0
  8128. * @category Array
  8129. * @param {Array} array The array to query.
  8130. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8131. * @returns {Array} Returns the slice of `array`.
  8132. * @example
  8133. *
  8134. * var users = [
  8135. * { 'user': 'barney', 'active': true },
  8136. * { 'user': 'fred', 'active': false },
  8137. * { 'user': 'pebbles', 'active': false }
  8138. * ];
  8139. *
  8140. * _.dropRightWhile(users, function(o) { return !o.active; });
  8141. * // => objects for ['barney']
  8142. *
  8143. * // The `_.matches` iteratee shorthand.
  8144. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  8145. * // => objects for ['barney', 'fred']
  8146. *
  8147. * // The `_.matchesProperty` iteratee shorthand.
  8148. * _.dropRightWhile(users, ['active', false]);
  8149. * // => objects for ['barney']
  8150. *
  8151. * // The `_.property` iteratee shorthand.
  8152. * _.dropRightWhile(users, 'active');
  8153. * // => objects for ['barney', 'fred', 'pebbles']
  8154. */
  8155. function dropRightWhile(array, predicate) {
  8156. return (array && array.length)
  8157. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  8158. : [];
  8159. }
  8160. /**
  8161. * Creates a slice of `array` excluding elements dropped from the beginning.
  8162. * Elements are dropped until `predicate` returns falsey. The predicate is
  8163. * invoked with three arguments: (value, index, array).
  8164. *
  8165. * @static
  8166. * @memberOf _
  8167. * @since 3.0.0
  8168. * @category Array
  8169. * @param {Array} array The array to query.
  8170. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8171. * @returns {Array} Returns the slice of `array`.
  8172. * @example
  8173. *
  8174. * var users = [
  8175. * { 'user': 'barney', 'active': false },
  8176. * { 'user': 'fred', 'active': false },
  8177. * { 'user': 'pebbles', 'active': true }
  8178. * ];
  8179. *
  8180. * _.dropWhile(users, function(o) { return !o.active; });
  8181. * // => objects for ['pebbles']
  8182. *
  8183. * // The `_.matches` iteratee shorthand.
  8184. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  8185. * // => objects for ['fred', 'pebbles']
  8186. *
  8187. * // The `_.matchesProperty` iteratee shorthand.
  8188. * _.dropWhile(users, ['active', false]);
  8189. * // => objects for ['pebbles']
  8190. *
  8191. * // The `_.property` iteratee shorthand.
  8192. * _.dropWhile(users, 'active');
  8193. * // => objects for ['barney', 'fred', 'pebbles']
  8194. */
  8195. function dropWhile(array, predicate) {
  8196. return (array && array.length)
  8197. ? baseWhile(array, getIteratee(predicate, 3), true)
  8198. : [];
  8199. }
  8200. /**
  8201. * Fills elements of `array` with `value` from `start` up to, but not
  8202. * including, `end`.
  8203. *
  8204. * **Note:** This method mutates `array`.
  8205. *
  8206. * @static
  8207. * @memberOf _
  8208. * @since 3.2.0
  8209. * @category Array
  8210. * @param {Array} array The array to fill.
  8211. * @param {*} value The value to fill `array` with.
  8212. * @param {number} [start=0] The start position.
  8213. * @param {number} [end=array.length] The end position.
  8214. * @returns {Array} Returns `array`.
  8215. * @example
  8216. *
  8217. * var array = [1, 2, 3];
  8218. *
  8219. * _.fill(array, 'a');
  8220. * console.log(array);
  8221. * // => ['a', 'a', 'a']
  8222. *
  8223. * _.fill(Array(3), 2);
  8224. * // => [2, 2, 2]
  8225. *
  8226. * _.fill([4, 6, 8, 10], '*', 1, 3);
  8227. * // => [4, '*', '*', 10]
  8228. */
  8229. function fill(array, value, start, end) {
  8230. var length = array == null ? 0 : array.length;
  8231. if (!length) {
  8232. return [];
  8233. }
  8234. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  8235. start = 0;
  8236. end = length;
  8237. }
  8238. return baseFill(array, value, start, end);
  8239. }
  8240. /**
  8241. * This method is like `_.find` except that it returns the index of the first
  8242. * element `predicate` returns truthy for instead of the element itself.
  8243. *
  8244. * @static
  8245. * @memberOf _
  8246. * @since 1.1.0
  8247. * @category Array
  8248. * @param {Array} array The array to inspect.
  8249. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8250. * @param {number} [fromIndex=0] The index to search from.
  8251. * @returns {number} Returns the index of the found element, else `-1`.
  8252. * @example
  8253. *
  8254. * var users = [
  8255. * { 'user': 'barney', 'active': false },
  8256. * { 'user': 'fred', 'active': false },
  8257. * { 'user': 'pebbles', 'active': true }
  8258. * ];
  8259. *
  8260. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  8261. * // => 0
  8262. *
  8263. * // The `_.matches` iteratee shorthand.
  8264. * _.findIndex(users, { 'user': 'fred', 'active': false });
  8265. * // => 1
  8266. *
  8267. * // The `_.matchesProperty` iteratee shorthand.
  8268. * _.findIndex(users, ['active', false]);
  8269. * // => 0
  8270. *
  8271. * // The `_.property` iteratee shorthand.
  8272. * _.findIndex(users, 'active');
  8273. * // => 2
  8274. */
  8275. function findIndex(array, predicate, fromIndex) {
  8276. var length = array == null ? 0 : array.length;
  8277. if (!length) {
  8278. return -1;
  8279. }
  8280. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  8281. if (index < 0) {
  8282. index = nativeMax(length + index, 0);
  8283. }
  8284. return baseFindIndex(array, getIteratee(predicate, 3), index);
  8285. }
  8286. /**
  8287. * This method is like `_.findIndex` except that it iterates over elements
  8288. * of `collection` from right to left.
  8289. *
  8290. * @static
  8291. * @memberOf _
  8292. * @since 2.0.0
  8293. * @category Array
  8294. * @param {Array} array The array to inspect.
  8295. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8296. * @param {number} [fromIndex=array.length-1] The index to search from.
  8297. * @returns {number} Returns the index of the found element, else `-1`.
  8298. * @example
  8299. *
  8300. * var users = [
  8301. * { 'user': 'barney', 'active': true },
  8302. * { 'user': 'fred', 'active': false },
  8303. * { 'user': 'pebbles', 'active': false }
  8304. * ];
  8305. *
  8306. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  8307. * // => 2
  8308. *
  8309. * // The `_.matches` iteratee shorthand.
  8310. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  8311. * // => 0
  8312. *
  8313. * // The `_.matchesProperty` iteratee shorthand.
  8314. * _.findLastIndex(users, ['active', false]);
  8315. * // => 2
  8316. *
  8317. * // The `_.property` iteratee shorthand.
  8318. * _.findLastIndex(users, 'active');
  8319. * // => 0
  8320. */
  8321. function findLastIndex(array, predicate, fromIndex) {
  8322. var length = array == null ? 0 : array.length;
  8323. if (!length) {
  8324. return -1;
  8325. }
  8326. var index = length - 1;
  8327. if (fromIndex !== undefined) {
  8328. index = toInteger(fromIndex);
  8329. index = fromIndex < 0
  8330. ? nativeMax(length + index, 0)
  8331. : nativeMin(index, length - 1);
  8332. }
  8333. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  8334. }
  8335. /**
  8336. * Flattens `array` a single level deep.
  8337. *
  8338. * @static
  8339. * @memberOf _
  8340. * @since 0.1.0
  8341. * @category Array
  8342. * @param {Array} array The array to flatten.
  8343. * @returns {Array} Returns the new flattened array.
  8344. * @example
  8345. *
  8346. * _.flatten([1, [2, [3, [4]], 5]]);
  8347. * // => [1, 2, [3, [4]], 5]
  8348. */
  8349. function flatten(array) {
  8350. var length = array == null ? 0 : array.length;
  8351. return length ? baseFlatten(array, 1) : [];
  8352. }
  8353. /**
  8354. * Recursively flattens `array`.
  8355. *
  8356. * @static
  8357. * @memberOf _
  8358. * @since 3.0.0
  8359. * @category Array
  8360. * @param {Array} array The array to flatten.
  8361. * @returns {Array} Returns the new flattened array.
  8362. * @example
  8363. *
  8364. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  8365. * // => [1, 2, 3, 4, 5]
  8366. */
  8367. function flattenDeep(array) {
  8368. var length = array == null ? 0 : array.length;
  8369. return length ? baseFlatten(array, INFINITY) : [];
  8370. }
  8371. /**
  8372. * Recursively flatten `array` up to `depth` times.
  8373. *
  8374. * @static
  8375. * @memberOf _
  8376. * @since 4.4.0
  8377. * @category Array
  8378. * @param {Array} array The array to flatten.
  8379. * @param {number} [depth=1] The maximum recursion depth.
  8380. * @returns {Array} Returns the new flattened array.
  8381. * @example
  8382. *
  8383. * var array = [1, [2, [3, [4]], 5]];
  8384. *
  8385. * _.flattenDepth(array, 1);
  8386. * // => [1, 2, [3, [4]], 5]
  8387. *
  8388. * _.flattenDepth(array, 2);
  8389. * // => [1, 2, 3, [4], 5]
  8390. */
  8391. function flattenDepth(array, depth) {
  8392. var length = array == null ? 0 : array.length;
  8393. if (!length) {
  8394. return [];
  8395. }
  8396. depth = depth === undefined ? 1 : toInteger(depth);
  8397. return baseFlatten(array, depth);
  8398. }
  8399. /**
  8400. * The inverse of `_.toPairs`; this method returns an object composed
  8401. * from key-value `pairs`.
  8402. *
  8403. * @static
  8404. * @memberOf _
  8405. * @since 4.0.0
  8406. * @category Array
  8407. * @param {Array} pairs The key-value pairs.
  8408. * @returns {Object} Returns the new object.
  8409. * @example
  8410. *
  8411. * _.fromPairs([['a', 1], ['b', 2]]);
  8412. * // => { 'a': 1, 'b': 2 }
  8413. */
  8414. function fromPairs(pairs) {
  8415. var index = -1,
  8416. length = pairs == null ? 0 : pairs.length,
  8417. result = {};
  8418. while (++index < length) {
  8419. var pair = pairs[index];
  8420. result[pair[0]] = pair[1];
  8421. }
  8422. return result;
  8423. }
  8424. /**
  8425. * Gets the first element of `array`.
  8426. *
  8427. * @static
  8428. * @memberOf _
  8429. * @since 0.1.0
  8430. * @alias first
  8431. * @category Array
  8432. * @param {Array} array The array to query.
  8433. * @returns {*} Returns the first element of `array`.
  8434. * @example
  8435. *
  8436. * _.head([1, 2, 3]);
  8437. * // => 1
  8438. *
  8439. * _.head([]);
  8440. * // => undefined
  8441. */
  8442. function head(array) {
  8443. return (array && array.length) ? array[0] : undefined;
  8444. }
  8445. /**
  8446. * Gets the index at which the first occurrence of `value` is found in `array`
  8447. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8448. * for equality comparisons. If `fromIndex` is negative, it's used as the
  8449. * offset from the end of `array`.
  8450. *
  8451. * @static
  8452. * @memberOf _
  8453. * @since 0.1.0
  8454. * @category Array
  8455. * @param {Array} array The array to inspect.
  8456. * @param {*} value The value to search for.
  8457. * @param {number} [fromIndex=0] The index to search from.
  8458. * @returns {number} Returns the index of the matched value, else `-1`.
  8459. * @example
  8460. *
  8461. * _.indexOf([1, 2, 1, 2], 2);
  8462. * // => 1
  8463. *
  8464. * // Search from the `fromIndex`.
  8465. * _.indexOf([1, 2, 1, 2], 2, 2);
  8466. * // => 3
  8467. */
  8468. function indexOf(array, value, fromIndex) {
  8469. var length = array == null ? 0 : array.length;
  8470. if (!length) {
  8471. return -1;
  8472. }
  8473. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  8474. if (index < 0) {
  8475. index = nativeMax(length + index, 0);
  8476. }
  8477. return baseIndexOf(array, value, index);
  8478. }
  8479. /**
  8480. * Gets all but the last element of `array`.
  8481. *
  8482. * @static
  8483. * @memberOf _
  8484. * @since 0.1.0
  8485. * @category Array
  8486. * @param {Array} array The array to query.
  8487. * @returns {Array} Returns the slice of `array`.
  8488. * @example
  8489. *
  8490. * _.initial([1, 2, 3]);
  8491. * // => [1, 2]
  8492. */
  8493. function initial(array) {
  8494. var length = array == null ? 0 : array.length;
  8495. return length ? baseSlice(array, 0, -1) : [];
  8496. }
  8497. /**
  8498. * Creates an array of unique values that are included in all given arrays
  8499. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8500. * for equality comparisons. The order and references of result values are
  8501. * determined by the first array.
  8502. *
  8503. * @static
  8504. * @memberOf _
  8505. * @since 0.1.0
  8506. * @category Array
  8507. * @param {...Array} [arrays] The arrays to inspect.
  8508. * @returns {Array} Returns the new array of intersecting values.
  8509. * @example
  8510. *
  8511. * _.intersection([2, 1], [2, 3]);
  8512. * // => [2]
  8513. */
  8514. var intersection = baseRest(function(arrays) {
  8515. var mapped = arrayMap(arrays, castArrayLikeObject);
  8516. return (mapped.length && mapped[0] === arrays[0])
  8517. ? baseIntersection(mapped)
  8518. : [];
  8519. });
  8520. /**
  8521. * This method is like `_.intersection` except that it accepts `iteratee`
  8522. * which is invoked for each element of each `arrays` to generate the criterion
  8523. * by which they're compared. The order and references of result values are
  8524. * determined by the first array. The iteratee is invoked with one argument:
  8525. * (value).
  8526. *
  8527. * @static
  8528. * @memberOf _
  8529. * @since 4.0.0
  8530. * @category Array
  8531. * @param {...Array} [arrays] The arrays to inspect.
  8532. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8533. * @returns {Array} Returns the new array of intersecting values.
  8534. * @example
  8535. *
  8536. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  8537. * // => [2.1]
  8538. *
  8539. * // The `_.property` iteratee shorthand.
  8540. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  8541. * // => [{ 'x': 1 }]
  8542. */
  8543. var intersectionBy = baseRest(function(arrays) {
  8544. var iteratee = last(arrays),
  8545. mapped = arrayMap(arrays, castArrayLikeObject);
  8546. if (iteratee === last(mapped)) {
  8547. iteratee = undefined;
  8548. } else {
  8549. mapped.pop();
  8550. }
  8551. return (mapped.length && mapped[0] === arrays[0])
  8552. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  8553. : [];
  8554. });
  8555. /**
  8556. * This method is like `_.intersection` except that it accepts `comparator`
  8557. * which is invoked to compare elements of `arrays`. The order and references
  8558. * of result values are determined by the first array. The comparator is
  8559. * invoked with two arguments: (arrVal, othVal).
  8560. *
  8561. * @static
  8562. * @memberOf _
  8563. * @since 4.0.0
  8564. * @category Array
  8565. * @param {...Array} [arrays] The arrays to inspect.
  8566. * @param {Function} [comparator] The comparator invoked per element.
  8567. * @returns {Array} Returns the new array of intersecting values.
  8568. * @example
  8569. *
  8570. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8571. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8572. *
  8573. * _.intersectionWith(objects, others, _.isEqual);
  8574. * // => [{ 'x': 1, 'y': 2 }]
  8575. */
  8576. var intersectionWith = baseRest(function(arrays) {
  8577. var comparator = last(arrays),
  8578. mapped = arrayMap(arrays, castArrayLikeObject);
  8579. comparator = typeof comparator == 'function' ? comparator : undefined;
  8580. if (comparator) {
  8581. mapped.pop();
  8582. }
  8583. return (mapped.length && mapped[0] === arrays[0])
  8584. ? baseIntersection(mapped, undefined, comparator)
  8585. : [];
  8586. });
  8587. /**
  8588. * Converts all elements in `array` into a string separated by `separator`.
  8589. *
  8590. * @static
  8591. * @memberOf _
  8592. * @since 4.0.0
  8593. * @category Array
  8594. * @param {Array} array The array to convert.
  8595. * @param {string} [separator=','] The element separator.
  8596. * @returns {string} Returns the joined string.
  8597. * @example
  8598. *
  8599. * _.join(['a', 'b', 'c'], '~');
  8600. * // => 'a~b~c'
  8601. */
  8602. function join(array, separator) {
  8603. return array == null ? '' : nativeJoin.call(array, separator);
  8604. }
  8605. /**
  8606. * Gets the last element of `array`.
  8607. *
  8608. * @static
  8609. * @memberOf _
  8610. * @since 0.1.0
  8611. * @category Array
  8612. * @param {Array} array The array to query.
  8613. * @returns {*} Returns the last element of `array`.
  8614. * @example
  8615. *
  8616. * _.last([1, 2, 3]);
  8617. * // => 3
  8618. */
  8619. function last(array) {
  8620. var length = array == null ? 0 : array.length;
  8621. return length ? array[length - 1] : undefined;
  8622. }
  8623. /**
  8624. * This method is like `_.indexOf` except that it iterates over elements of
  8625. * `array` from right to left.
  8626. *
  8627. * @static
  8628. * @memberOf _
  8629. * @since 0.1.0
  8630. * @category Array
  8631. * @param {Array} array The array to inspect.
  8632. * @param {*} value The value to search for.
  8633. * @param {number} [fromIndex=array.length-1] The index to search from.
  8634. * @returns {number} Returns the index of the matched value, else `-1`.
  8635. * @example
  8636. *
  8637. * _.lastIndexOf([1, 2, 1, 2], 2);
  8638. * // => 3
  8639. *
  8640. * // Search from the `fromIndex`.
  8641. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  8642. * // => 1
  8643. */
  8644. function lastIndexOf(array, value, fromIndex) {
  8645. var length = array == null ? 0 : array.length;
  8646. if (!length) {
  8647. return -1;
  8648. }
  8649. var index = length;
  8650. if (fromIndex !== undefined) {
  8651. index = toInteger(fromIndex);
  8652. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  8653. }
  8654. return value === value
  8655. ? strictLastIndexOf(array, value, index)
  8656. : baseFindIndex(array, baseIsNaN, index, true);
  8657. }
  8658. /**
  8659. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  8660. * element from the end is returned.
  8661. *
  8662. * @static
  8663. * @memberOf _
  8664. * @since 4.11.0
  8665. * @category Array
  8666. * @param {Array} array The array to query.
  8667. * @param {number} [n=0] The index of the element to return.
  8668. * @returns {*} Returns the nth element of `array`.
  8669. * @example
  8670. *
  8671. * var array = ['a', 'b', 'c', 'd'];
  8672. *
  8673. * _.nth(array, 1);
  8674. * // => 'b'
  8675. *
  8676. * _.nth(array, -2);
  8677. * // => 'c';
  8678. */
  8679. function nth(array, n) {
  8680. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  8681. }
  8682. /**
  8683. * Removes all given values from `array` using
  8684. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8685. * for equality comparisons.
  8686. *
  8687. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  8688. * to remove elements from an array by predicate.
  8689. *
  8690. * @static
  8691. * @memberOf _
  8692. * @since 2.0.0
  8693. * @category Array
  8694. * @param {Array} array The array to modify.
  8695. * @param {...*} [values] The values to remove.
  8696. * @returns {Array} Returns `array`.
  8697. * @example
  8698. *
  8699. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  8700. *
  8701. * _.pull(array, 'a', 'c');
  8702. * console.log(array);
  8703. * // => ['b', 'b']
  8704. */
  8705. var pull = baseRest(pullAll);
  8706. /**
  8707. * This method is like `_.pull` except that it accepts an array of values to remove.
  8708. *
  8709. * **Note:** Unlike `_.difference`, this method mutates `array`.
  8710. *
  8711. * @static
  8712. * @memberOf _
  8713. * @since 4.0.0
  8714. * @category Array
  8715. * @param {Array} array The array to modify.
  8716. * @param {Array} values The values to remove.
  8717. * @returns {Array} Returns `array`.
  8718. * @example
  8719. *
  8720. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  8721. *
  8722. * _.pullAll(array, ['a', 'c']);
  8723. * console.log(array);
  8724. * // => ['b', 'b']
  8725. */
  8726. function pullAll(array, values) {
  8727. return (array && array.length && values && values.length)
  8728. ? basePullAll(array, values)
  8729. : array;
  8730. }
  8731. /**
  8732. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  8733. * invoked for each element of `array` and `values` to generate the criterion
  8734. * by which they're compared. The iteratee is invoked with one argument: (value).
  8735. *
  8736. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  8737. *
  8738. * @static
  8739. * @memberOf _
  8740. * @since 4.0.0
  8741. * @category Array
  8742. * @param {Array} array The array to modify.
  8743. * @param {Array} values The values to remove.
  8744. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8745. * @returns {Array} Returns `array`.
  8746. * @example
  8747. *
  8748. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  8749. *
  8750. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  8751. * console.log(array);
  8752. * // => [{ 'x': 2 }]
  8753. */
  8754. function pullAllBy(array, values, iteratee) {
  8755. return (array && array.length && values && values.length)
  8756. ? basePullAll(array, values, getIteratee(iteratee, 2))
  8757. : array;
  8758. }
  8759. /**
  8760. * This method is like `_.pullAll` except that it accepts `comparator` which
  8761. * is invoked to compare elements of `array` to `values`. The comparator is
  8762. * invoked with two arguments: (arrVal, othVal).
  8763. *
  8764. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  8765. *
  8766. * @static
  8767. * @memberOf _
  8768. * @since 4.6.0
  8769. * @category Array
  8770. * @param {Array} array The array to modify.
  8771. * @param {Array} values The values to remove.
  8772. * @param {Function} [comparator] The comparator invoked per element.
  8773. * @returns {Array} Returns `array`.
  8774. * @example
  8775. *
  8776. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  8777. *
  8778. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  8779. * console.log(array);
  8780. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  8781. */
  8782. function pullAllWith(array, values, comparator) {
  8783. return (array && array.length && values && values.length)
  8784. ? basePullAll(array, values, undefined, comparator)
  8785. : array;
  8786. }
  8787. /**
  8788. * Removes elements from `array` corresponding to `indexes` and returns an
  8789. * array of removed elements.
  8790. *
  8791. * **Note:** Unlike `_.at`, this method mutates `array`.
  8792. *
  8793. * @static
  8794. * @memberOf _
  8795. * @since 3.0.0
  8796. * @category Array
  8797. * @param {Array} array The array to modify.
  8798. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  8799. * @returns {Array} Returns the new array of removed elements.
  8800. * @example
  8801. *
  8802. * var array = ['a', 'b', 'c', 'd'];
  8803. * var pulled = _.pullAt(array, [1, 3]);
  8804. *
  8805. * console.log(array);
  8806. * // => ['a', 'c']
  8807. *
  8808. * console.log(pulled);
  8809. * // => ['b', 'd']
  8810. */
  8811. var pullAt = flatRest(function(array, indexes) {
  8812. var length = array == null ? 0 : array.length,
  8813. result = baseAt(array, indexes);
  8814. basePullAt(array, arrayMap(indexes, function(index) {
  8815. return isIndex(index, length) ? +index : index;
  8816. }).sort(compareAscending));
  8817. return result;
  8818. });
  8819. /**
  8820. * Removes all elements from `array` that `predicate` returns truthy for
  8821. * and returns an array of the removed elements. The predicate is invoked
  8822. * with three arguments: (value, index, array).
  8823. *
  8824. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  8825. * to pull elements from an array by value.
  8826. *
  8827. * @static
  8828. * @memberOf _
  8829. * @since 2.0.0
  8830. * @category Array
  8831. * @param {Array} array The array to modify.
  8832. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8833. * @returns {Array} Returns the new array of removed elements.
  8834. * @example
  8835. *
  8836. * var array = [1, 2, 3, 4];
  8837. * var evens = _.remove(array, function(n) {
  8838. * return n % 2 == 0;
  8839. * });
  8840. *
  8841. * console.log(array);
  8842. * // => [1, 3]
  8843. *
  8844. * console.log(evens);
  8845. * // => [2, 4]
  8846. */
  8847. function remove(array, predicate) {
  8848. var result = [];
  8849. if (!(array && array.length)) {
  8850. return result;
  8851. }
  8852. var index = -1,
  8853. indexes = [],
  8854. length = array.length;
  8855. predicate = getIteratee(predicate, 3);
  8856. while (++index < length) {
  8857. var value = array[index];
  8858. if (predicate(value, index, array)) {
  8859. result.push(value);
  8860. indexes.push(index);
  8861. }
  8862. }
  8863. basePullAt(array, indexes);
  8864. return result;
  8865. }
  8866. /**
  8867. * Reverses `array` so that the first element becomes the last, the second
  8868. * element becomes the second to last, and so on.
  8869. *
  8870. * **Note:** This method mutates `array` and is based on
  8871. * [`Array#reverse`](https://mdn.io/Array/reverse).
  8872. *
  8873. * @static
  8874. * @memberOf _
  8875. * @since 4.0.0
  8876. * @category Array
  8877. * @param {Array} array The array to modify.
  8878. * @returns {Array} Returns `array`.
  8879. * @example
  8880. *
  8881. * var array = [1, 2, 3];
  8882. *
  8883. * _.reverse(array);
  8884. * // => [3, 2, 1]
  8885. *
  8886. * console.log(array);
  8887. * // => [3, 2, 1]
  8888. */
  8889. function reverse(array) {
  8890. return array == null ? array : nativeReverse.call(array);
  8891. }
  8892. /**
  8893. * Creates a slice of `array` from `start` up to, but not including, `end`.
  8894. *
  8895. * **Note:** This method is used instead of
  8896. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  8897. * returned.
  8898. *
  8899. * @static
  8900. * @memberOf _
  8901. * @since 3.0.0
  8902. * @category Array
  8903. * @param {Array} array The array to slice.
  8904. * @param {number} [start=0] The start position.
  8905. * @param {number} [end=array.length] The end position.
  8906. * @returns {Array} Returns the slice of `array`.
  8907. */
  8908. function slice(array, start, end) {
  8909. var length = array == null ? 0 : array.length;
  8910. if (!length) {
  8911. return [];
  8912. }
  8913. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  8914. start = 0;
  8915. end = length;
  8916. }
  8917. else {
  8918. start = start == null ? 0 : toInteger(start);
  8919. end = end === undefined ? length : toInteger(end);
  8920. }
  8921. return baseSlice(array, start, end);
  8922. }
  8923. /**
  8924. * Uses a binary search to determine the lowest index at which `value`
  8925. * should be inserted into `array` in order to maintain its sort order.
  8926. *
  8927. * @static
  8928. * @memberOf _
  8929. * @since 0.1.0
  8930. * @category Array
  8931. * @param {Array} array The sorted array to inspect.
  8932. * @param {*} value The value to evaluate.
  8933. * @returns {number} Returns the index at which `value` should be inserted
  8934. * into `array`.
  8935. * @example
  8936. *
  8937. * _.sortedIndex([30, 50], 40);
  8938. * // => 1
  8939. */
  8940. function sortedIndex(array, value) {
  8941. return baseSortedIndex(array, value);
  8942. }
  8943. /**
  8944. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  8945. * which is invoked for `value` and each element of `array` to compute their
  8946. * sort ranking. The iteratee is invoked with one argument: (value).
  8947. *
  8948. * @static
  8949. * @memberOf _
  8950. * @since 4.0.0
  8951. * @category Array
  8952. * @param {Array} array The sorted array to inspect.
  8953. * @param {*} value The value to evaluate.
  8954. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8955. * @returns {number} Returns the index at which `value` should be inserted
  8956. * into `array`.
  8957. * @example
  8958. *
  8959. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  8960. *
  8961. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  8962. * // => 0
  8963. *
  8964. * // The `_.property` iteratee shorthand.
  8965. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  8966. * // => 0
  8967. */
  8968. function sortedIndexBy(array, value, iteratee) {
  8969. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  8970. }
  8971. /**
  8972. * This method is like `_.indexOf` except that it performs a binary
  8973. * search on a sorted `array`.
  8974. *
  8975. * @static
  8976. * @memberOf _
  8977. * @since 4.0.0
  8978. * @category Array
  8979. * @param {Array} array The array to inspect.
  8980. * @param {*} value The value to search for.
  8981. * @returns {number} Returns the index of the matched value, else `-1`.
  8982. * @example
  8983. *
  8984. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  8985. * // => 1
  8986. */
  8987. function sortedIndexOf(array, value) {
  8988. var length = array == null ? 0 : array.length;
  8989. if (length) {
  8990. var index = baseSortedIndex(array, value);
  8991. if (index < length && eq(array[index], value)) {
  8992. return index;
  8993. }
  8994. }
  8995. return -1;
  8996. }
  8997. /**
  8998. * This method is like `_.sortedIndex` except that it returns the highest
  8999. * index at which `value` should be inserted into `array` in order to
  9000. * maintain its sort order.
  9001. *
  9002. * @static
  9003. * @memberOf _
  9004. * @since 3.0.0
  9005. * @category Array
  9006. * @param {Array} array The sorted array to inspect.
  9007. * @param {*} value The value to evaluate.
  9008. * @returns {number} Returns the index at which `value` should be inserted
  9009. * into `array`.
  9010. * @example
  9011. *
  9012. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  9013. * // => 4
  9014. */
  9015. function sortedLastIndex(array, value) {
  9016. return baseSortedIndex(array, value, true);
  9017. }
  9018. /**
  9019. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  9020. * which is invoked for `value` and each element of `array` to compute their
  9021. * sort ranking. The iteratee is invoked with one argument: (value).
  9022. *
  9023. * @static
  9024. * @memberOf _
  9025. * @since 4.0.0
  9026. * @category Array
  9027. * @param {Array} array The sorted array to inspect.
  9028. * @param {*} value The value to evaluate.
  9029. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9030. * @returns {number} Returns the index at which `value` should be inserted
  9031. * into `array`.
  9032. * @example
  9033. *
  9034. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  9035. *
  9036. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  9037. * // => 1
  9038. *
  9039. * // The `_.property` iteratee shorthand.
  9040. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  9041. * // => 1
  9042. */
  9043. function sortedLastIndexBy(array, value, iteratee) {
  9044. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  9045. }
  9046. /**
  9047. * This method is like `_.lastIndexOf` except that it performs a binary
  9048. * search on a sorted `array`.
  9049. *
  9050. * @static
  9051. * @memberOf _
  9052. * @since 4.0.0
  9053. * @category Array
  9054. * @param {Array} array The array to inspect.
  9055. * @param {*} value The value to search for.
  9056. * @returns {number} Returns the index of the matched value, else `-1`.
  9057. * @example
  9058. *
  9059. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  9060. * // => 3
  9061. */
  9062. function sortedLastIndexOf(array, value) {
  9063. var length = array == null ? 0 : array.length;
  9064. if (length) {
  9065. var index = baseSortedIndex(array, value, true) - 1;
  9066. if (eq(array[index], value)) {
  9067. return index;
  9068. }
  9069. }
  9070. return -1;
  9071. }
  9072. /**
  9073. * This method is like `_.uniq` except that it's designed and optimized
  9074. * for sorted arrays.
  9075. *
  9076. * @static
  9077. * @memberOf _
  9078. * @since 4.0.0
  9079. * @category Array
  9080. * @param {Array} array The array to inspect.
  9081. * @returns {Array} Returns the new duplicate free array.
  9082. * @example
  9083. *
  9084. * _.sortedUniq([1, 1, 2]);
  9085. * // => [1, 2]
  9086. */
  9087. function sortedUniq(array) {
  9088. return (array && array.length)
  9089. ? baseSortedUniq(array)
  9090. : [];
  9091. }
  9092. /**
  9093. * This method is like `_.uniqBy` except that it's designed and optimized
  9094. * for sorted arrays.
  9095. *
  9096. * @static
  9097. * @memberOf _
  9098. * @since 4.0.0
  9099. * @category Array
  9100. * @param {Array} array The array to inspect.
  9101. * @param {Function} [iteratee] The iteratee invoked per element.
  9102. * @returns {Array} Returns the new duplicate free array.
  9103. * @example
  9104. *
  9105. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  9106. * // => [1.1, 2.3]
  9107. */
  9108. function sortedUniqBy(array, iteratee) {
  9109. return (array && array.length)
  9110. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  9111. : [];
  9112. }
  9113. /**
  9114. * Gets all but the first element of `array`.
  9115. *
  9116. * @static
  9117. * @memberOf _
  9118. * @since 4.0.0
  9119. * @category Array
  9120. * @param {Array} array The array to query.
  9121. * @returns {Array} Returns the slice of `array`.
  9122. * @example
  9123. *
  9124. * _.tail([1, 2, 3]);
  9125. * // => [2, 3]
  9126. */
  9127. function tail(array) {
  9128. var length = array == null ? 0 : array.length;
  9129. return length ? baseSlice(array, 1, length) : [];
  9130. }
  9131. /**
  9132. * Creates a slice of `array` with `n` elements taken from the beginning.
  9133. *
  9134. * @static
  9135. * @memberOf _
  9136. * @since 0.1.0
  9137. * @category Array
  9138. * @param {Array} array The array to query.
  9139. * @param {number} [n=1] The number of elements to take.
  9140. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9141. * @returns {Array} Returns the slice of `array`.
  9142. * @example
  9143. *
  9144. * _.take([1, 2, 3]);
  9145. * // => [1]
  9146. *
  9147. * _.take([1, 2, 3], 2);
  9148. * // => [1, 2]
  9149. *
  9150. * _.take([1, 2, 3], 5);
  9151. * // => [1, 2, 3]
  9152. *
  9153. * _.take([1, 2, 3], 0);
  9154. * // => []
  9155. */
  9156. function take(array, n, guard) {
  9157. if (!(array && array.length)) {
  9158. return [];
  9159. }
  9160. n = (guard || n === undefined) ? 1 : toInteger(n);
  9161. return baseSlice(array, 0, n < 0 ? 0 : n);
  9162. }
  9163. /**
  9164. * Creates a slice of `array` with `n` elements taken from the end.
  9165. *
  9166. * @static
  9167. * @memberOf _
  9168. * @since 3.0.0
  9169. * @category Array
  9170. * @param {Array} array The array to query.
  9171. * @param {number} [n=1] The number of elements to take.
  9172. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9173. * @returns {Array} Returns the slice of `array`.
  9174. * @example
  9175. *
  9176. * _.takeRight([1, 2, 3]);
  9177. * // => [3]
  9178. *
  9179. * _.takeRight([1, 2, 3], 2);
  9180. * // => [2, 3]
  9181. *
  9182. * _.takeRight([1, 2, 3], 5);
  9183. * // => [1, 2, 3]
  9184. *
  9185. * _.takeRight([1, 2, 3], 0);
  9186. * // => []
  9187. */
  9188. function takeRight(array, n, guard) {
  9189. var length = array == null ? 0 : array.length;
  9190. if (!length) {
  9191. return [];
  9192. }
  9193. n = (guard || n === undefined) ? 1 : toInteger(n);
  9194. n = length - n;
  9195. return baseSlice(array, n < 0 ? 0 : n, length);
  9196. }
  9197. /**
  9198. * Creates a slice of `array` with elements taken from the end. Elements are
  9199. * taken until `predicate` returns falsey. The predicate is invoked with
  9200. * three arguments: (value, index, array).
  9201. *
  9202. * @static
  9203. * @memberOf _
  9204. * @since 3.0.0
  9205. * @category Array
  9206. * @param {Array} array The array to query.
  9207. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9208. * @returns {Array} Returns the slice of `array`.
  9209. * @example
  9210. *
  9211. * var users = [
  9212. * { 'user': 'barney', 'active': true },
  9213. * { 'user': 'fred', 'active': false },
  9214. * { 'user': 'pebbles', 'active': false }
  9215. * ];
  9216. *
  9217. * _.takeRightWhile(users, function(o) { return !o.active; });
  9218. * // => objects for ['fred', 'pebbles']
  9219. *
  9220. * // The `_.matches` iteratee shorthand.
  9221. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  9222. * // => objects for ['pebbles']
  9223. *
  9224. * // The `_.matchesProperty` iteratee shorthand.
  9225. * _.takeRightWhile(users, ['active', false]);
  9226. * // => objects for ['fred', 'pebbles']
  9227. *
  9228. * // The `_.property` iteratee shorthand.
  9229. * _.takeRightWhile(users, 'active');
  9230. * // => []
  9231. */
  9232. function takeRightWhile(array, predicate) {
  9233. return (array && array.length)
  9234. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  9235. : [];
  9236. }
  9237. /**
  9238. * Creates a slice of `array` with elements taken from the beginning. Elements
  9239. * are taken until `predicate` returns falsey. The predicate is invoked with
  9240. * three arguments: (value, index, array).
  9241. *
  9242. * @static
  9243. * @memberOf _
  9244. * @since 3.0.0
  9245. * @category Array
  9246. * @param {Array} array The array to query.
  9247. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9248. * @returns {Array} Returns the slice of `array`.
  9249. * @example
  9250. *
  9251. * var users = [
  9252. * { 'user': 'barney', 'active': false },
  9253. * { 'user': 'fred', 'active': false },
  9254. * { 'user': 'pebbles', 'active': true }
  9255. * ];
  9256. *
  9257. * _.takeWhile(users, function(o) { return !o.active; });
  9258. * // => objects for ['barney', 'fred']
  9259. *
  9260. * // The `_.matches` iteratee shorthand.
  9261. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  9262. * // => objects for ['barney']
  9263. *
  9264. * // The `_.matchesProperty` iteratee shorthand.
  9265. * _.takeWhile(users, ['active', false]);
  9266. * // => objects for ['barney', 'fred']
  9267. *
  9268. * // The `_.property` iteratee shorthand.
  9269. * _.takeWhile(users, 'active');
  9270. * // => []
  9271. */
  9272. function takeWhile(array, predicate) {
  9273. return (array && array.length)
  9274. ? baseWhile(array, getIteratee(predicate, 3))
  9275. : [];
  9276. }
  9277. /**
  9278. * Creates an array of unique values, in order, from all given arrays using
  9279. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9280. * for equality comparisons.
  9281. *
  9282. * @static
  9283. * @memberOf _
  9284. * @since 0.1.0
  9285. * @category Array
  9286. * @param {...Array} [arrays] The arrays to inspect.
  9287. * @returns {Array} Returns the new array of combined values.
  9288. * @example
  9289. *
  9290. * _.union([2], [1, 2]);
  9291. * // => [2, 1]
  9292. */
  9293. var union = baseRest(function(arrays) {
  9294. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  9295. });
  9296. /**
  9297. * This method is like `_.union` except that it accepts `iteratee` which is
  9298. * invoked for each element of each `arrays` to generate the criterion by
  9299. * which uniqueness is computed. Result values are chosen from the first
  9300. * array in which the value occurs. The iteratee is invoked with one argument:
  9301. * (value).
  9302. *
  9303. * @static
  9304. * @memberOf _
  9305. * @since 4.0.0
  9306. * @category Array
  9307. * @param {...Array} [arrays] The arrays to inspect.
  9308. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9309. * @returns {Array} Returns the new array of combined values.
  9310. * @example
  9311. *
  9312. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  9313. * // => [2.1, 1.2]
  9314. *
  9315. * // The `_.property` iteratee shorthand.
  9316. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  9317. * // => [{ 'x': 1 }, { 'x': 2 }]
  9318. */
  9319. var unionBy = baseRest(function(arrays) {
  9320. var iteratee = last(arrays);
  9321. if (isArrayLikeObject(iteratee)) {
  9322. iteratee = undefined;
  9323. }
  9324. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  9325. });
  9326. /**
  9327. * This method is like `_.union` except that it accepts `comparator` which
  9328. * is invoked to compare elements of `arrays`. Result values are chosen from
  9329. * the first array in which the value occurs. The comparator is invoked
  9330. * with two arguments: (arrVal, othVal).
  9331. *
  9332. * @static
  9333. * @memberOf _
  9334. * @since 4.0.0
  9335. * @category Array
  9336. * @param {...Array} [arrays] The arrays to inspect.
  9337. * @param {Function} [comparator] The comparator invoked per element.
  9338. * @returns {Array} Returns the new array of combined values.
  9339. * @example
  9340. *
  9341. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  9342. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  9343. *
  9344. * _.unionWith(objects, others, _.isEqual);
  9345. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  9346. */
  9347. var unionWith = baseRest(function(arrays) {
  9348. var comparator = last(arrays);
  9349. comparator = typeof comparator == 'function' ? comparator : undefined;
  9350. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  9351. });
  9352. /**
  9353. * Creates a duplicate-free version of an array, using
  9354. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9355. * for equality comparisons, in which only the first occurrence of each element
  9356. * is kept. The order of result values is determined by the order they occur
  9357. * in the array.
  9358. *
  9359. * @static
  9360. * @memberOf _
  9361. * @since 0.1.0
  9362. * @category Array
  9363. * @param {Array} array The array to inspect.
  9364. * @returns {Array} Returns the new duplicate free array.
  9365. * @example
  9366. *
  9367. * _.uniq([2, 1, 2]);
  9368. * // => [2, 1]
  9369. */
  9370. function uniq(array) {
  9371. return (array && array.length) ? baseUniq(array) : [];
  9372. }
  9373. /**
  9374. * This method is like `_.uniq` except that it accepts `iteratee` which is
  9375. * invoked for each element in `array` to generate the criterion by which
  9376. * uniqueness is computed. The order of result values is determined by the
  9377. * order they occur in the array. The iteratee is invoked with one argument:
  9378. * (value).
  9379. *
  9380. * @static
  9381. * @memberOf _
  9382. * @since 4.0.0
  9383. * @category Array
  9384. * @param {Array} array The array to inspect.
  9385. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9386. * @returns {Array} Returns the new duplicate free array.
  9387. * @example
  9388. *
  9389. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  9390. * // => [2.1, 1.2]
  9391. *
  9392. * // The `_.property` iteratee shorthand.
  9393. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  9394. * // => [{ 'x': 1 }, { 'x': 2 }]
  9395. */
  9396. function uniqBy(array, iteratee) {
  9397. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  9398. }
  9399. /**
  9400. * This method is like `_.uniq` except that it accepts `comparator` which
  9401. * is invoked to compare elements of `array`. The order of result values is
  9402. * determined by the order they occur in the array.The comparator is invoked
  9403. * with two arguments: (arrVal, othVal).
  9404. *
  9405. * @static
  9406. * @memberOf _
  9407. * @since 4.0.0
  9408. * @category Array
  9409. * @param {Array} array The array to inspect.
  9410. * @param {Function} [comparator] The comparator invoked per element.
  9411. * @returns {Array} Returns the new duplicate free array.
  9412. * @example
  9413. *
  9414. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  9415. *
  9416. * _.uniqWith(objects, _.isEqual);
  9417. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  9418. */
  9419. function uniqWith(array, comparator) {
  9420. comparator = typeof comparator == 'function' ? comparator : undefined;
  9421. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  9422. }
  9423. /**
  9424. * This method is like `_.zip` except that it accepts an array of grouped
  9425. * elements and creates an array regrouping the elements to their pre-zip
  9426. * configuration.
  9427. *
  9428. * @static
  9429. * @memberOf _
  9430. * @since 1.2.0
  9431. * @category Array
  9432. * @param {Array} array The array of grouped elements to process.
  9433. * @returns {Array} Returns the new array of regrouped elements.
  9434. * @example
  9435. *
  9436. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  9437. * // => [['a', 1, true], ['b', 2, false]]
  9438. *
  9439. * _.unzip(zipped);
  9440. * // => [['a', 'b'], [1, 2], [true, false]]
  9441. */
  9442. function unzip(array) {
  9443. if (!(array && array.length)) {
  9444. return [];
  9445. }
  9446. var length = 0;
  9447. array = arrayFilter(array, function(group) {
  9448. if (isArrayLikeObject(group)) {
  9449. length = nativeMax(group.length, length);
  9450. return true;
  9451. }
  9452. });
  9453. return baseTimes(length, function(index) {
  9454. return arrayMap(array, baseProperty(index));
  9455. });
  9456. }
  9457. /**
  9458. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  9459. * how regrouped values should be combined. The iteratee is invoked with the
  9460. * elements of each group: (...group).
  9461. *
  9462. * @static
  9463. * @memberOf _
  9464. * @since 3.8.0
  9465. * @category Array
  9466. * @param {Array} array The array of grouped elements to process.
  9467. * @param {Function} [iteratee=_.identity] The function to combine
  9468. * regrouped values.
  9469. * @returns {Array} Returns the new array of regrouped elements.
  9470. * @example
  9471. *
  9472. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  9473. * // => [[1, 10, 100], [2, 20, 200]]
  9474. *
  9475. * _.unzipWith(zipped, _.add);
  9476. * // => [3, 30, 300]
  9477. */
  9478. function unzipWith(array, iteratee) {
  9479. if (!(array && array.length)) {
  9480. return [];
  9481. }
  9482. var result = unzip(array);
  9483. if (iteratee == null) {
  9484. return result;
  9485. }
  9486. return arrayMap(result, function(group) {
  9487. return apply(iteratee, undefined, group);
  9488. });
  9489. }
  9490. /**
  9491. * Creates an array excluding all given values using
  9492. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9493. * for equality comparisons.
  9494. *
  9495. * **Note:** Unlike `_.pull`, this method returns a new array.
  9496. *
  9497. * @static
  9498. * @memberOf _
  9499. * @since 0.1.0
  9500. * @category Array
  9501. * @param {Array} array The array to inspect.
  9502. * @param {...*} [values] The values to exclude.
  9503. * @returns {Array} Returns the new array of filtered values.
  9504. * @see _.difference, _.xor
  9505. * @example
  9506. *
  9507. * _.without([2, 1, 2, 3], 1, 2);
  9508. * // => [3]
  9509. */
  9510. var without = baseRest(function(array, values) {
  9511. return isArrayLikeObject(array)
  9512. ? baseDifference(array, values)
  9513. : [];
  9514. });
  9515. /**
  9516. * Creates an array of unique values that is the
  9517. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  9518. * of the given arrays. The order of result values is determined by the order
  9519. * they occur in the arrays.
  9520. *
  9521. * @static
  9522. * @memberOf _
  9523. * @since 2.4.0
  9524. * @category Array
  9525. * @param {...Array} [arrays] The arrays to inspect.
  9526. * @returns {Array} Returns the new array of filtered values.
  9527. * @see _.difference, _.without
  9528. * @example
  9529. *
  9530. * _.xor([2, 1], [2, 3]);
  9531. * // => [1, 3]
  9532. */
  9533. var xor = baseRest(function(arrays) {
  9534. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  9535. });
  9536. /**
  9537. * This method is like `_.xor` except that it accepts `iteratee` which is
  9538. * invoked for each element of each `arrays` to generate the criterion by
  9539. * which by which they're compared. The order of result values is determined
  9540. * by the order they occur in the arrays. The iteratee is invoked with one
  9541. * argument: (value).
  9542. *
  9543. * @static
  9544. * @memberOf _
  9545. * @since 4.0.0
  9546. * @category Array
  9547. * @param {...Array} [arrays] The arrays to inspect.
  9548. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9549. * @returns {Array} Returns the new array of filtered values.
  9550. * @example
  9551. *
  9552. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  9553. * // => [1.2, 3.4]
  9554. *
  9555. * // The `_.property` iteratee shorthand.
  9556. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  9557. * // => [{ 'x': 2 }]
  9558. */
  9559. var xorBy = baseRest(function(arrays) {
  9560. var iteratee = last(arrays);
  9561. if (isArrayLikeObject(iteratee)) {
  9562. iteratee = undefined;
  9563. }
  9564. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  9565. });
  9566. /**
  9567. * This method is like `_.xor` except that it accepts `comparator` which is
  9568. * invoked to compare elements of `arrays`. The order of result values is
  9569. * determined by the order they occur in the arrays. The comparator is invoked
  9570. * with two arguments: (arrVal, othVal).
  9571. *
  9572. * @static
  9573. * @memberOf _
  9574. * @since 4.0.0
  9575. * @category Array
  9576. * @param {...Array} [arrays] The arrays to inspect.
  9577. * @param {Function} [comparator] The comparator invoked per element.
  9578. * @returns {Array} Returns the new array of filtered values.
  9579. * @example
  9580. *
  9581. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  9582. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  9583. *
  9584. * _.xorWith(objects, others, _.isEqual);
  9585. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  9586. */
  9587. var xorWith = baseRest(function(arrays) {
  9588. var comparator = last(arrays);
  9589. comparator = typeof comparator == 'function' ? comparator : undefined;
  9590. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  9591. });
  9592. /**
  9593. * Creates an array of grouped elements, the first of which contains the
  9594. * first elements of the given arrays, the second of which contains the
  9595. * second elements of the given arrays, and so on.
  9596. *
  9597. * @static
  9598. * @memberOf _
  9599. * @since 0.1.0
  9600. * @category Array
  9601. * @param {...Array} [arrays] The arrays to process.
  9602. * @returns {Array} Returns the new array of grouped elements.
  9603. * @example
  9604. *
  9605. * _.zip(['a', 'b'], [1, 2], [true, false]);
  9606. * // => [['a', 1, true], ['b', 2, false]]
  9607. */
  9608. var zip = baseRest(unzip);
  9609. /**
  9610. * This method is like `_.fromPairs` except that it accepts two arrays,
  9611. * one of property identifiers and one of corresponding values.
  9612. *
  9613. * @static
  9614. * @memberOf _
  9615. * @since 0.4.0
  9616. * @category Array
  9617. * @param {Array} [props=[]] The property identifiers.
  9618. * @param {Array} [values=[]] The property values.
  9619. * @returns {Object} Returns the new object.
  9620. * @example
  9621. *
  9622. * _.zipObject(['a', 'b'], [1, 2]);
  9623. * // => { 'a': 1, 'b': 2 }
  9624. */
  9625. function zipObject(props, values) {
  9626. return baseZipObject(props || [], values || [], assignValue);
  9627. }
  9628. /**
  9629. * This method is like `_.zipObject` except that it supports property paths.
  9630. *
  9631. * @static
  9632. * @memberOf _
  9633. * @since 4.1.0
  9634. * @category Array
  9635. * @param {Array} [props=[]] The property identifiers.
  9636. * @param {Array} [values=[]] The property values.
  9637. * @returns {Object} Returns the new object.
  9638. * @example
  9639. *
  9640. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  9641. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  9642. */
  9643. function zipObjectDeep(props, values) {
  9644. return baseZipObject(props || [], values || [], baseSet);
  9645. }
  9646. /**
  9647. * This method is like `_.zip` except that it accepts `iteratee` to specify
  9648. * how grouped values should be combined. The iteratee is invoked with the
  9649. * elements of each group: (...group).
  9650. *
  9651. * @static
  9652. * @memberOf _
  9653. * @since 3.8.0
  9654. * @category Array
  9655. * @param {...Array} [arrays] The arrays to process.
  9656. * @param {Function} [iteratee=_.identity] The function to combine
  9657. * grouped values.
  9658. * @returns {Array} Returns the new array of grouped elements.
  9659. * @example
  9660. *
  9661. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  9662. * return a + b + c;
  9663. * });
  9664. * // => [111, 222]
  9665. */
  9666. var zipWith = baseRest(function(arrays) {
  9667. var length = arrays.length,
  9668. iteratee = length > 1 ? arrays[length - 1] : undefined;
  9669. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  9670. return unzipWith(arrays, iteratee);
  9671. });
  9672. /*------------------------------------------------------------------------*/
  9673. /**
  9674. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  9675. * chain sequences enabled. The result of such sequences must be unwrapped
  9676. * with `_#value`.
  9677. *
  9678. * @static
  9679. * @memberOf _
  9680. * @since 1.3.0
  9681. * @category Seq
  9682. * @param {*} value The value to wrap.
  9683. * @returns {Object} Returns the new `lodash` wrapper instance.
  9684. * @example
  9685. *
  9686. * var users = [
  9687. * { 'user': 'barney', 'age': 36 },
  9688. * { 'user': 'fred', 'age': 40 },
  9689. * { 'user': 'pebbles', 'age': 1 }
  9690. * ];
  9691. *
  9692. * var youngest = _
  9693. * .chain(users)
  9694. * .sortBy('age')
  9695. * .map(function(o) {
  9696. * return o.user + ' is ' + o.age;
  9697. * })
  9698. * .head()
  9699. * .value();
  9700. * // => 'pebbles is 1'
  9701. */
  9702. function chain(value) {
  9703. var result = lodash(value);
  9704. result.__chain__ = true;
  9705. return result;
  9706. }
  9707. /**
  9708. * This method invokes `interceptor` and returns `value`. The interceptor
  9709. * is invoked with one argument; (value). The purpose of this method is to
  9710. * "tap into" a method chain sequence in order to modify intermediate results.
  9711. *
  9712. * @static
  9713. * @memberOf _
  9714. * @since 0.1.0
  9715. * @category Seq
  9716. * @param {*} value The value to provide to `interceptor`.
  9717. * @param {Function} interceptor The function to invoke.
  9718. * @returns {*} Returns `value`.
  9719. * @example
  9720. *
  9721. * _([1, 2, 3])
  9722. * .tap(function(array) {
  9723. * // Mutate input array.
  9724. * array.pop();
  9725. * })
  9726. * .reverse()
  9727. * .value();
  9728. * // => [2, 1]
  9729. */
  9730. function tap(value, interceptor) {
  9731. interceptor(value);
  9732. return value;
  9733. }
  9734. /**
  9735. * This method is like `_.tap` except that it returns the result of `interceptor`.
  9736. * The purpose of this method is to "pass thru" values replacing intermediate
  9737. * results in a method chain sequence.
  9738. *
  9739. * @static
  9740. * @memberOf _
  9741. * @since 3.0.0
  9742. * @category Seq
  9743. * @param {*} value The value to provide to `interceptor`.
  9744. * @param {Function} interceptor The function to invoke.
  9745. * @returns {*} Returns the result of `interceptor`.
  9746. * @example
  9747. *
  9748. * _(' abc ')
  9749. * .chain()
  9750. * .trim()
  9751. * .thru(function(value) {
  9752. * return [value];
  9753. * })
  9754. * .value();
  9755. * // => ['abc']
  9756. */
  9757. function thru(value, interceptor) {
  9758. return interceptor(value);
  9759. }
  9760. /**
  9761. * This method is the wrapper version of `_.at`.
  9762. *
  9763. * @name at
  9764. * @memberOf _
  9765. * @since 1.0.0
  9766. * @category Seq
  9767. * @param {...(string|string[])} [paths] The property paths to pick.
  9768. * @returns {Object} Returns the new `lodash` wrapper instance.
  9769. * @example
  9770. *
  9771. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  9772. *
  9773. * _(object).at(['a[0].b.c', 'a[1]']).value();
  9774. * // => [3, 4]
  9775. */
  9776. var wrapperAt = flatRest(function(paths) {
  9777. var length = paths.length,
  9778. start = length ? paths[0] : 0,
  9779. value = this.__wrapped__,
  9780. interceptor = function(object) { return baseAt(object, paths); };
  9781. if (length > 1 || this.__actions__.length ||
  9782. !(value instanceof LazyWrapper) || !isIndex(start)) {
  9783. return this.thru(interceptor);
  9784. }
  9785. value = value.slice(start, +start + (length ? 1 : 0));
  9786. value.__actions__.push({
  9787. 'func': thru,
  9788. 'args': [interceptor],
  9789. 'thisArg': undefined
  9790. });
  9791. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  9792. if (length && !array.length) {
  9793. array.push(undefined);
  9794. }
  9795. return array;
  9796. });
  9797. });
  9798. /**
  9799. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  9800. *
  9801. * @name chain
  9802. * @memberOf _
  9803. * @since 0.1.0
  9804. * @category Seq
  9805. * @returns {Object} Returns the new `lodash` wrapper instance.
  9806. * @example
  9807. *
  9808. * var users = [
  9809. * { 'user': 'barney', 'age': 36 },
  9810. * { 'user': 'fred', 'age': 40 }
  9811. * ];
  9812. *
  9813. * // A sequence without explicit chaining.
  9814. * _(users).head();
  9815. * // => { 'user': 'barney', 'age': 36 }
  9816. *
  9817. * // A sequence with explicit chaining.
  9818. * _(users)
  9819. * .chain()
  9820. * .head()
  9821. * .pick('user')
  9822. * .value();
  9823. * // => { 'user': 'barney' }
  9824. */
  9825. function wrapperChain() {
  9826. return chain(this);
  9827. }
  9828. /**
  9829. * Executes the chain sequence and returns the wrapped result.
  9830. *
  9831. * @name commit
  9832. * @memberOf _
  9833. * @since 3.2.0
  9834. * @category Seq
  9835. * @returns {Object} Returns the new `lodash` wrapper instance.
  9836. * @example
  9837. *
  9838. * var array = [1, 2];
  9839. * var wrapped = _(array).push(3);
  9840. *
  9841. * console.log(array);
  9842. * // => [1, 2]
  9843. *
  9844. * wrapped = wrapped.commit();
  9845. * console.log(array);
  9846. * // => [1, 2, 3]
  9847. *
  9848. * wrapped.last();
  9849. * // => 3
  9850. *
  9851. * console.log(array);
  9852. * // => [1, 2, 3]
  9853. */
  9854. function wrapperCommit() {
  9855. return new LodashWrapper(this.value(), this.__chain__);
  9856. }
  9857. /**
  9858. * Gets the next value on a wrapped object following the
  9859. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  9860. *
  9861. * @name next
  9862. * @memberOf _
  9863. * @since 4.0.0
  9864. * @category Seq
  9865. * @returns {Object} Returns the next iterator value.
  9866. * @example
  9867. *
  9868. * var wrapped = _([1, 2]);
  9869. *
  9870. * wrapped.next();
  9871. * // => { 'done': false, 'value': 1 }
  9872. *
  9873. * wrapped.next();
  9874. * // => { 'done': false, 'value': 2 }
  9875. *
  9876. * wrapped.next();
  9877. * // => { 'done': true, 'value': undefined }
  9878. */
  9879. function wrapperNext() {
  9880. if (this.__values__ === undefined) {
  9881. this.__values__ = toArray(this.value());
  9882. }
  9883. var done = this.__index__ >= this.__values__.length,
  9884. value = done ? undefined : this.__values__[this.__index__++];
  9885. return { 'done': done, 'value': value };
  9886. }
  9887. /**
  9888. * Enables the wrapper to be iterable.
  9889. *
  9890. * @name Symbol.iterator
  9891. * @memberOf _
  9892. * @since 4.0.0
  9893. * @category Seq
  9894. * @returns {Object} Returns the wrapper object.
  9895. * @example
  9896. *
  9897. * var wrapped = _([1, 2]);
  9898. *
  9899. * wrapped[Symbol.iterator]() === wrapped;
  9900. * // => true
  9901. *
  9902. * Array.from(wrapped);
  9903. * // => [1, 2]
  9904. */
  9905. function wrapperToIterator() {
  9906. return this;
  9907. }
  9908. /**
  9909. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  9910. *
  9911. * @name plant
  9912. * @memberOf _
  9913. * @since 3.2.0
  9914. * @category Seq
  9915. * @param {*} value The value to plant.
  9916. * @returns {Object} Returns the new `lodash` wrapper instance.
  9917. * @example
  9918. *
  9919. * function square(n) {
  9920. * return n * n;
  9921. * }
  9922. *
  9923. * var wrapped = _([1, 2]).map(square);
  9924. * var other = wrapped.plant([3, 4]);
  9925. *
  9926. * other.value();
  9927. * // => [9, 16]
  9928. *
  9929. * wrapped.value();
  9930. * // => [1, 4]
  9931. */
  9932. function wrapperPlant(value) {
  9933. var result,
  9934. parent = this;
  9935. while (parent instanceof baseLodash) {
  9936. var clone = wrapperClone(parent);
  9937. clone.__index__ = 0;
  9938. clone.__values__ = undefined;
  9939. if (result) {
  9940. previous.__wrapped__ = clone;
  9941. } else {
  9942. result = clone;
  9943. }
  9944. var previous = clone;
  9945. parent = parent.__wrapped__;
  9946. }
  9947. previous.__wrapped__ = value;
  9948. return result;
  9949. }
  9950. /**
  9951. * This method is the wrapper version of `_.reverse`.
  9952. *
  9953. * **Note:** This method mutates the wrapped array.
  9954. *
  9955. * @name reverse
  9956. * @memberOf _
  9957. * @since 0.1.0
  9958. * @category Seq
  9959. * @returns {Object} Returns the new `lodash` wrapper instance.
  9960. * @example
  9961. *
  9962. * var array = [1, 2, 3];
  9963. *
  9964. * _(array).reverse().value()
  9965. * // => [3, 2, 1]
  9966. *
  9967. * console.log(array);
  9968. * // => [3, 2, 1]
  9969. */
  9970. function wrapperReverse() {
  9971. var value = this.__wrapped__;
  9972. if (value instanceof LazyWrapper) {
  9973. var wrapped = value;
  9974. if (this.__actions__.length) {
  9975. wrapped = new LazyWrapper(this);
  9976. }
  9977. wrapped = wrapped.reverse();
  9978. wrapped.__actions__.push({
  9979. 'func': thru,
  9980. 'args': [reverse],
  9981. 'thisArg': undefined
  9982. });
  9983. return new LodashWrapper(wrapped, this.__chain__);
  9984. }
  9985. return this.thru(reverse);
  9986. }
  9987. /**
  9988. * Executes the chain sequence to resolve the unwrapped value.
  9989. *
  9990. * @name value
  9991. * @memberOf _
  9992. * @since 0.1.0
  9993. * @alias toJSON, valueOf
  9994. * @category Seq
  9995. * @returns {*} Returns the resolved unwrapped value.
  9996. * @example
  9997. *
  9998. * _([1, 2, 3]).value();
  9999. * // => [1, 2, 3]
  10000. */
  10001. function wrapperValue() {
  10002. return baseWrapperValue(this.__wrapped__, this.__actions__);
  10003. }
  10004. /*------------------------------------------------------------------------*/
  10005. /**
  10006. * Creates an object composed of keys generated from the results of running
  10007. * each element of `collection` thru `iteratee`. The corresponding value of
  10008. * each key is the number of times the key was returned by `iteratee`. The
  10009. * iteratee is invoked with one argument: (value).
  10010. *
  10011. * @static
  10012. * @memberOf _
  10013. * @since 0.5.0
  10014. * @category Collection
  10015. * @param {Array|Object} collection The collection to iterate over.
  10016. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  10017. * @returns {Object} Returns the composed aggregate object.
  10018. * @example
  10019. *
  10020. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  10021. * // => { '4': 1, '6': 2 }
  10022. *
  10023. * // The `_.property` iteratee shorthand.
  10024. * _.countBy(['one', 'two', 'three'], 'length');
  10025. * // => { '3': 2, '5': 1 }
  10026. */
  10027. var countBy = createAggregator(function(result, value, key) {
  10028. if (hasOwnProperty.call(result, key)) {
  10029. ++result[key];
  10030. } else {
  10031. baseAssignValue(result, key, 1);
  10032. }
  10033. });
  10034. /**
  10035. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  10036. * Iteration is stopped once `predicate` returns falsey. The predicate is
  10037. * invoked with three arguments: (value, index|key, collection).
  10038. *
  10039. * **Note:** This method returns `true` for
  10040. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  10041. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  10042. * elements of empty collections.
  10043. *
  10044. * @static
  10045. * @memberOf _
  10046. * @since 0.1.0
  10047. * @category Collection
  10048. * @param {Array|Object} collection The collection to iterate over.
  10049. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10050. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10051. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  10052. * else `false`.
  10053. * @example
  10054. *
  10055. * _.every([true, 1, null, 'yes'], Boolean);
  10056. * // => false
  10057. *
  10058. * var users = [
  10059. * { 'user': 'barney', 'age': 36, 'active': false },
  10060. * { 'user': 'fred', 'age': 40, 'active': false }
  10061. * ];
  10062. *
  10063. * // The `_.matches` iteratee shorthand.
  10064. * _.every(users, { 'user': 'barney', 'active': false });
  10065. * // => false
  10066. *
  10067. * // The `_.matchesProperty` iteratee shorthand.
  10068. * _.every(users, ['active', false]);
  10069. * // => true
  10070. *
  10071. * // The `_.property` iteratee shorthand.
  10072. * _.every(users, 'active');
  10073. * // => false
  10074. */
  10075. function every(collection, predicate, guard) {
  10076. var func = isArray(collection) ? arrayEvery : baseEvery;
  10077. if (guard && isIterateeCall(collection, predicate, guard)) {
  10078. predicate = undefined;
  10079. }
  10080. return func(collection, getIteratee(predicate, 3));
  10081. }
  10082. /**
  10083. * Iterates over elements of `collection`, returning an array of all elements
  10084. * `predicate` returns truthy for. The predicate is invoked with three
  10085. * arguments: (value, index|key, collection).
  10086. *
  10087. * **Note:** Unlike `_.remove`, this method returns a new array.
  10088. *
  10089. * @static
  10090. * @memberOf _
  10091. * @since 0.1.0
  10092. * @category Collection
  10093. * @param {Array|Object} collection The collection to iterate over.
  10094. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10095. * @returns {Array} Returns the new filtered array.
  10096. * @see _.reject
  10097. * @example
  10098. *
  10099. * var users = [
  10100. * { 'user': 'barney', 'age': 36, 'active': true },
  10101. * { 'user': 'fred', 'age': 40, 'active': false }
  10102. * ];
  10103. *
  10104. * _.filter(users, function(o) { return !o.active; });
  10105. * // => objects for ['fred']
  10106. *
  10107. * // The `_.matches` iteratee shorthand.
  10108. * _.filter(users, { 'age': 36, 'active': true });
  10109. * // => objects for ['barney']
  10110. *
  10111. * // The `_.matchesProperty` iteratee shorthand.
  10112. * _.filter(users, ['active', false]);
  10113. * // => objects for ['fred']
  10114. *
  10115. * // The `_.property` iteratee shorthand.
  10116. * _.filter(users, 'active');
  10117. * // => objects for ['barney']
  10118. *
  10119. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  10120. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  10121. * // => objects for ['fred', 'barney']
  10122. */
  10123. function filter(collection, predicate) {
  10124. var func = isArray(collection) ? arrayFilter : baseFilter;
  10125. return func(collection, getIteratee(predicate, 3));
  10126. }
  10127. /**
  10128. * Iterates over elements of `collection`, returning the first element
  10129. * `predicate` returns truthy for. The predicate is invoked with three
  10130. * arguments: (value, index|key, collection).
  10131. *
  10132. * @static
  10133. * @memberOf _
  10134. * @since 0.1.0
  10135. * @category Collection
  10136. * @param {Array|Object} collection The collection to inspect.
  10137. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10138. * @param {number} [fromIndex=0] The index to search from.
  10139. * @returns {*} Returns the matched element, else `undefined`.
  10140. * @example
  10141. *
  10142. * var users = [
  10143. * { 'user': 'barney', 'age': 36, 'active': true },
  10144. * { 'user': 'fred', 'age': 40, 'active': false },
  10145. * { 'user': 'pebbles', 'age': 1, 'active': true }
  10146. * ];
  10147. *
  10148. * _.find(users, function(o) { return o.age < 40; });
  10149. * // => object for 'barney'
  10150. *
  10151. * // The `_.matches` iteratee shorthand.
  10152. * _.find(users, { 'age': 1, 'active': true });
  10153. * // => object for 'pebbles'
  10154. *
  10155. * // The `_.matchesProperty` iteratee shorthand.
  10156. * _.find(users, ['active', false]);
  10157. * // => object for 'fred'
  10158. *
  10159. * // The `_.property` iteratee shorthand.
  10160. * _.find(users, 'active');
  10161. * // => object for 'barney'
  10162. */
  10163. var find = createFind(findIndex);
  10164. /**
  10165. * This method is like `_.find` except that it iterates over elements of
  10166. * `collection` from right to left.
  10167. *
  10168. * @static
  10169. * @memberOf _
  10170. * @since 2.0.0
  10171. * @category Collection
  10172. * @param {Array|Object} collection The collection to inspect.
  10173. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10174. * @param {number} [fromIndex=collection.length-1] The index to search from.
  10175. * @returns {*} Returns the matched element, else `undefined`.
  10176. * @example
  10177. *
  10178. * _.findLast([1, 2, 3, 4], function(n) {
  10179. * return n % 2 == 1;
  10180. * });
  10181. * // => 3
  10182. */
  10183. var findLast = createFind(findLastIndex);
  10184. /**
  10185. * Creates a flattened array of values by running each element in `collection`
  10186. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  10187. * with three arguments: (value, index|key, collection).
  10188. *
  10189. * @static
  10190. * @memberOf _
  10191. * @since 4.0.0
  10192. * @category Collection
  10193. * @param {Array|Object} collection The collection to iterate over.
  10194. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10195. * @returns {Array} Returns the new flattened array.
  10196. * @example
  10197. *
  10198. * function duplicate(n) {
  10199. * return [n, n];
  10200. * }
  10201. *
  10202. * _.flatMap([1, 2], duplicate);
  10203. * // => [1, 1, 2, 2]
  10204. */
  10205. function flatMap(collection, iteratee) {
  10206. return baseFlatten(map(collection, iteratee), 1);
  10207. }
  10208. /**
  10209. * This method is like `_.flatMap` except that it recursively flattens the
  10210. * mapped results.
  10211. *
  10212. * @static
  10213. * @memberOf _
  10214. * @since 4.7.0
  10215. * @category Collection
  10216. * @param {Array|Object} collection The collection to iterate over.
  10217. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10218. * @returns {Array} Returns the new flattened array.
  10219. * @example
  10220. *
  10221. * function duplicate(n) {
  10222. * return [[[n, n]]];
  10223. * }
  10224. *
  10225. * _.flatMapDeep([1, 2], duplicate);
  10226. * // => [1, 1, 2, 2]
  10227. */
  10228. function flatMapDeep(collection, iteratee) {
  10229. return baseFlatten(map(collection, iteratee), INFINITY);
  10230. }
  10231. /**
  10232. * This method is like `_.flatMap` except that it recursively flattens the
  10233. * mapped results up to `depth` times.
  10234. *
  10235. * @static
  10236. * @memberOf _
  10237. * @since 4.7.0
  10238. * @category Collection
  10239. * @param {Array|Object} collection The collection to iterate over.
  10240. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10241. * @param {number} [depth=1] The maximum recursion depth.
  10242. * @returns {Array} Returns the new flattened array.
  10243. * @example
  10244. *
  10245. * function duplicate(n) {
  10246. * return [[[n, n]]];
  10247. * }
  10248. *
  10249. * _.flatMapDepth([1, 2], duplicate, 2);
  10250. * // => [[1, 1], [2, 2]]
  10251. */
  10252. function flatMapDepth(collection, iteratee, depth) {
  10253. depth = depth === undefined ? 1 : toInteger(depth);
  10254. return baseFlatten(map(collection, iteratee), depth);
  10255. }
  10256. /**
  10257. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  10258. * The iteratee is invoked with three arguments: (value, index|key, collection).
  10259. * Iteratee functions may exit iteration early by explicitly returning `false`.
  10260. *
  10261. * **Note:** As with other "Collections" methods, objects with a "length"
  10262. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  10263. * or `_.forOwn` for object iteration.
  10264. *
  10265. * @static
  10266. * @memberOf _
  10267. * @since 0.1.0
  10268. * @alias each
  10269. * @category Collection
  10270. * @param {Array|Object} collection The collection to iterate over.
  10271. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10272. * @returns {Array|Object} Returns `collection`.
  10273. * @see _.forEachRight
  10274. * @example
  10275. *
  10276. * _.forEach([1, 2], function(value) {
  10277. * console.log(value);
  10278. * });
  10279. * // => Logs `1` then `2`.
  10280. *
  10281. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  10282. * console.log(key);
  10283. * });
  10284. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  10285. */
  10286. function forEach(collection, iteratee) {
  10287. var func = isArray(collection) ? arrayEach : baseEach;
  10288. return func(collection, getIteratee(iteratee, 3));
  10289. }
  10290. /**
  10291. * This method is like `_.forEach` except that it iterates over elements of
  10292. * `collection` from right to left.
  10293. *
  10294. * @static
  10295. * @memberOf _
  10296. * @since 2.0.0
  10297. * @alias eachRight
  10298. * @category Collection
  10299. * @param {Array|Object} collection The collection to iterate over.
  10300. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10301. * @returns {Array|Object} Returns `collection`.
  10302. * @see _.forEach
  10303. * @example
  10304. *
  10305. * _.forEachRight([1, 2], function(value) {
  10306. * console.log(value);
  10307. * });
  10308. * // => Logs `2` then `1`.
  10309. */
  10310. function forEachRight(collection, iteratee) {
  10311. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  10312. return func(collection, getIteratee(iteratee, 3));
  10313. }
  10314. /**
  10315. * Creates an object composed of keys generated from the results of running
  10316. * each element of `collection` thru `iteratee`. The order of grouped values
  10317. * is determined by the order they occur in `collection`. The corresponding
  10318. * value of each key is an array of elements responsible for generating the
  10319. * key. The iteratee is invoked with one argument: (value).
  10320. *
  10321. * @static
  10322. * @memberOf _
  10323. * @since 0.1.0
  10324. * @category Collection
  10325. * @param {Array|Object} collection The collection to iterate over.
  10326. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  10327. * @returns {Object} Returns the composed aggregate object.
  10328. * @example
  10329. *
  10330. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  10331. * // => { '4': [4.2], '6': [6.1, 6.3] }
  10332. *
  10333. * // The `_.property` iteratee shorthand.
  10334. * _.groupBy(['one', 'two', 'three'], 'length');
  10335. * // => { '3': ['one', 'two'], '5': ['three'] }
  10336. */
  10337. var groupBy = createAggregator(function(result, value, key) {
  10338. if (hasOwnProperty.call(result, key)) {
  10339. result[key].push(value);
  10340. } else {
  10341. baseAssignValue(result, key, [value]);
  10342. }
  10343. });
  10344. /**
  10345. * Checks if `value` is in `collection`. If `collection` is a string, it's
  10346. * checked for a substring of `value`, otherwise
  10347. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10348. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  10349. * the offset from the end of `collection`.
  10350. *
  10351. * @static
  10352. * @memberOf _
  10353. * @since 0.1.0
  10354. * @category Collection
  10355. * @param {Array|Object|string} collection The collection to inspect.
  10356. * @param {*} value The value to search for.
  10357. * @param {number} [fromIndex=0] The index to search from.
  10358. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  10359. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  10360. * @example
  10361. *
  10362. * _.includes([1, 2, 3], 1);
  10363. * // => true
  10364. *
  10365. * _.includes([1, 2, 3], 1, 2);
  10366. * // => false
  10367. *
  10368. * _.includes({ 'a': 1, 'b': 2 }, 1);
  10369. * // => true
  10370. *
  10371. * _.includes('abcd', 'bc');
  10372. * // => true
  10373. */
  10374. function includes(collection, value, fromIndex, guard) {
  10375. collection = isArrayLike(collection) ? collection : values(collection);
  10376. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  10377. var length = collection.length;
  10378. if (fromIndex < 0) {
  10379. fromIndex = nativeMax(length + fromIndex, 0);
  10380. }
  10381. return isString(collection)
  10382. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  10383. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  10384. }
  10385. /**
  10386. * Invokes the method at `path` of each element in `collection`, returning
  10387. * an array of the results of each invoked method. Any additional arguments
  10388. * are provided to each invoked method. If `path` is a function, it's invoked
  10389. * for, and `this` bound to, each element in `collection`.
  10390. *
  10391. * @static
  10392. * @memberOf _
  10393. * @since 4.0.0
  10394. * @category Collection
  10395. * @param {Array|Object} collection The collection to iterate over.
  10396. * @param {Array|Function|string} path The path of the method to invoke or
  10397. * the function invoked per iteration.
  10398. * @param {...*} [args] The arguments to invoke each method with.
  10399. * @returns {Array} Returns the array of results.
  10400. * @example
  10401. *
  10402. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  10403. * // => [[1, 5, 7], [1, 2, 3]]
  10404. *
  10405. * _.invokeMap([123, 456], String.prototype.split, '');
  10406. * // => [['1', '2', '3'], ['4', '5', '6']]
  10407. */
  10408. var invokeMap = baseRest(function(collection, path, args) {
  10409. var index = -1,
  10410. isFunc = typeof path == 'function',
  10411. result = isArrayLike(collection) ? Array(collection.length) : [];
  10412. baseEach(collection, function(value) {
  10413. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  10414. });
  10415. return result;
  10416. });
  10417. /**
  10418. * Creates an object composed of keys generated from the results of running
  10419. * each element of `collection` thru `iteratee`. The corresponding value of
  10420. * each key is the last element responsible for generating the key. The
  10421. * iteratee is invoked with one argument: (value).
  10422. *
  10423. * @static
  10424. * @memberOf _
  10425. * @since 4.0.0
  10426. * @category Collection
  10427. * @param {Array|Object} collection The collection to iterate over.
  10428. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  10429. * @returns {Object} Returns the composed aggregate object.
  10430. * @example
  10431. *
  10432. * var array = [
  10433. * { 'dir': 'left', 'code': 97 },
  10434. * { 'dir': 'right', 'code': 100 }
  10435. * ];
  10436. *
  10437. * _.keyBy(array, function(o) {
  10438. * return String.fromCharCode(o.code);
  10439. * });
  10440. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  10441. *
  10442. * _.keyBy(array, 'dir');
  10443. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  10444. */
  10445. var keyBy = createAggregator(function(result, value, key) {
  10446. baseAssignValue(result, key, value);
  10447. });
  10448. /**
  10449. * Creates an array of values by running each element in `collection` thru
  10450. * `iteratee`. The iteratee is invoked with three arguments:
  10451. * (value, index|key, collection).
  10452. *
  10453. * Many lodash methods are guarded to work as iteratees for methods like
  10454. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  10455. *
  10456. * The guarded methods are:
  10457. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  10458. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  10459. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  10460. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  10461. *
  10462. * @static
  10463. * @memberOf _
  10464. * @since 0.1.0
  10465. * @category Collection
  10466. * @param {Array|Object} collection The collection to iterate over.
  10467. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10468. * @returns {Array} Returns the new mapped array.
  10469. * @example
  10470. *
  10471. * function square(n) {
  10472. * return n * n;
  10473. * }
  10474. *
  10475. * _.map([4, 8], square);
  10476. * // => [16, 64]
  10477. *
  10478. * _.map({ 'a': 4, 'b': 8 }, square);
  10479. * // => [16, 64] (iteration order is not guaranteed)
  10480. *
  10481. * var users = [
  10482. * { 'user': 'barney' },
  10483. * { 'user': 'fred' }
  10484. * ];
  10485. *
  10486. * // The `_.property` iteratee shorthand.
  10487. * _.map(users, 'user');
  10488. * // => ['barney', 'fred']
  10489. */
  10490. function map(collection, iteratee) {
  10491. var func = isArray(collection) ? arrayMap : baseMap;
  10492. return func(collection, getIteratee(iteratee, 3));
  10493. }
  10494. /**
  10495. * This method is like `_.sortBy` except that it allows specifying the sort
  10496. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  10497. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  10498. * descending or "asc" for ascending sort order of corresponding values.
  10499. *
  10500. * @static
  10501. * @memberOf _
  10502. * @since 4.0.0
  10503. * @category Collection
  10504. * @param {Array|Object} collection The collection to iterate over.
  10505. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  10506. * The iteratees to sort by.
  10507. * @param {string[]} [orders] The sort orders of `iteratees`.
  10508. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  10509. * @returns {Array} Returns the new sorted array.
  10510. * @example
  10511. *
  10512. * var users = [
  10513. * { 'user': 'fred', 'age': 48 },
  10514. * { 'user': 'barney', 'age': 34 },
  10515. * { 'user': 'fred', 'age': 40 },
  10516. * { 'user': 'barney', 'age': 36 }
  10517. * ];
  10518. *
  10519. * // Sort by `user` in ascending order and by `age` in descending order.
  10520. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  10521. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  10522. */
  10523. function orderBy(collection, iteratees, orders, guard) {
  10524. if (collection == null) {
  10525. return [];
  10526. }
  10527. if (!isArray(iteratees)) {
  10528. iteratees = iteratees == null ? [] : [iteratees];
  10529. }
  10530. orders = guard ? undefined : orders;
  10531. if (!isArray(orders)) {
  10532. orders = orders == null ? [] : [orders];
  10533. }
  10534. return baseOrderBy(collection, iteratees, orders);
  10535. }
  10536. /**
  10537. * Creates an array of elements split into two groups, the first of which
  10538. * contains elements `predicate` returns truthy for, the second of which
  10539. * contains elements `predicate` returns falsey for. The predicate is
  10540. * invoked with one argument: (value).
  10541. *
  10542. * @static
  10543. * @memberOf _
  10544. * @since 3.0.0
  10545. * @category Collection
  10546. * @param {Array|Object} collection The collection to iterate over.
  10547. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10548. * @returns {Array} Returns the array of grouped elements.
  10549. * @example
  10550. *
  10551. * var users = [
  10552. * { 'user': 'barney', 'age': 36, 'active': false },
  10553. * { 'user': 'fred', 'age': 40, 'active': true },
  10554. * { 'user': 'pebbles', 'age': 1, 'active': false }
  10555. * ];
  10556. *
  10557. * _.partition(users, function(o) { return o.active; });
  10558. * // => objects for [['fred'], ['barney', 'pebbles']]
  10559. *
  10560. * // The `_.matches` iteratee shorthand.
  10561. * _.partition(users, { 'age': 1, 'active': false });
  10562. * // => objects for [['pebbles'], ['barney', 'fred']]
  10563. *
  10564. * // The `_.matchesProperty` iteratee shorthand.
  10565. * _.partition(users, ['active', false]);
  10566. * // => objects for [['barney', 'pebbles'], ['fred']]
  10567. *
  10568. * // The `_.property` iteratee shorthand.
  10569. * _.partition(users, 'active');
  10570. * // => objects for [['fred'], ['barney', 'pebbles']]
  10571. */
  10572. var partition = createAggregator(function(result, value, key) {
  10573. result[key ? 0 : 1].push(value);
  10574. }, function() { return [[], []]; });
  10575. /**
  10576. * Reduces `collection` to a value which is the accumulated result of running
  10577. * each element in `collection` thru `iteratee`, where each successive
  10578. * invocation is supplied the return value of the previous. If `accumulator`
  10579. * is not given, the first element of `collection` is used as the initial
  10580. * value. The iteratee is invoked with four arguments:
  10581. * (accumulator, value, index|key, collection).
  10582. *
  10583. * Many lodash methods are guarded to work as iteratees for methods like
  10584. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  10585. *
  10586. * The guarded methods are:
  10587. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  10588. * and `sortBy`
  10589. *
  10590. * @static
  10591. * @memberOf _
  10592. * @since 0.1.0
  10593. * @category Collection
  10594. * @param {Array|Object} collection The collection to iterate over.
  10595. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10596. * @param {*} [accumulator] The initial value.
  10597. * @returns {*} Returns the accumulated value.
  10598. * @see _.reduceRight
  10599. * @example
  10600. *
  10601. * _.reduce([1, 2], function(sum, n) {
  10602. * return sum + n;
  10603. * }, 0);
  10604. * // => 3
  10605. *
  10606. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  10607. * (result[value] || (result[value] = [])).push(key);
  10608. * return result;
  10609. * }, {});
  10610. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  10611. */
  10612. function reduce(collection, iteratee, accumulator) {
  10613. var func = isArray(collection) ? arrayReduce : baseReduce,
  10614. initAccum = arguments.length < 3;
  10615. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  10616. }
  10617. /**
  10618. * This method is like `_.reduce` except that it iterates over elements of
  10619. * `collection` from right to left.
  10620. *
  10621. * @static
  10622. * @memberOf _
  10623. * @since 0.1.0
  10624. * @category Collection
  10625. * @param {Array|Object} collection The collection to iterate over.
  10626. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  10627. * @param {*} [accumulator] The initial value.
  10628. * @returns {*} Returns the accumulated value.
  10629. * @see _.reduce
  10630. * @example
  10631. *
  10632. * var array = [[0, 1], [2, 3], [4, 5]];
  10633. *
  10634. * _.reduceRight(array, function(flattened, other) {
  10635. * return flattened.concat(other);
  10636. * }, []);
  10637. * // => [4, 5, 2, 3, 0, 1]
  10638. */
  10639. function reduceRight(collection, iteratee, accumulator) {
  10640. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  10641. initAccum = arguments.length < 3;
  10642. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  10643. }
  10644. /**
  10645. * The opposite of `_.filter`; this method returns the elements of `collection`
  10646. * that `predicate` does **not** return truthy for.
  10647. *
  10648. * @static
  10649. * @memberOf _
  10650. * @since 0.1.0
  10651. * @category Collection
  10652. * @param {Array|Object} collection The collection to iterate over.
  10653. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10654. * @returns {Array} Returns the new filtered array.
  10655. * @see _.filter
  10656. * @example
  10657. *
  10658. * var users = [
  10659. * { 'user': 'barney', 'age': 36, 'active': false },
  10660. * { 'user': 'fred', 'age': 40, 'active': true }
  10661. * ];
  10662. *
  10663. * _.reject(users, function(o) { return !o.active; });
  10664. * // => objects for ['fred']
  10665. *
  10666. * // The `_.matches` iteratee shorthand.
  10667. * _.reject(users, { 'age': 40, 'active': true });
  10668. * // => objects for ['barney']
  10669. *
  10670. * // The `_.matchesProperty` iteratee shorthand.
  10671. * _.reject(users, ['active', false]);
  10672. * // => objects for ['fred']
  10673. *
  10674. * // The `_.property` iteratee shorthand.
  10675. * _.reject(users, 'active');
  10676. * // => objects for ['barney']
  10677. */
  10678. function reject(collection, predicate) {
  10679. var func = isArray(collection) ? arrayFilter : baseFilter;
  10680. return func(collection, negate(getIteratee(predicate, 3)));
  10681. }
  10682. /**
  10683. * Gets a random element from `collection`.
  10684. *
  10685. * @static
  10686. * @memberOf _
  10687. * @since 2.0.0
  10688. * @category Collection
  10689. * @param {Array|Object} collection The collection to sample.
  10690. * @returns {*} Returns the random element.
  10691. * @example
  10692. *
  10693. * _.sample([1, 2, 3, 4]);
  10694. * // => 2
  10695. */
  10696. function sample(collection) {
  10697. var func = isArray(collection) ? arraySample : baseSample;
  10698. return func(collection);
  10699. }
  10700. /**
  10701. * Gets `n` random elements at unique keys from `collection` up to the
  10702. * size of `collection`.
  10703. *
  10704. * @static
  10705. * @memberOf _
  10706. * @since 4.0.0
  10707. * @category Collection
  10708. * @param {Array|Object} collection The collection to sample.
  10709. * @param {number} [n=1] The number of elements to sample.
  10710. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10711. * @returns {Array} Returns the random elements.
  10712. * @example
  10713. *
  10714. * _.sampleSize([1, 2, 3], 2);
  10715. * // => [3, 1]
  10716. *
  10717. * _.sampleSize([1, 2, 3], 4);
  10718. * // => [2, 3, 1]
  10719. */
  10720. function sampleSize(collection, n, guard) {
  10721. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  10722. n = 1;
  10723. } else {
  10724. n = toInteger(n);
  10725. }
  10726. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  10727. return func(collection, n);
  10728. }
  10729. /**
  10730. * Creates an array of shuffled values, using a version of the
  10731. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  10732. *
  10733. * @static
  10734. * @memberOf _
  10735. * @since 0.1.0
  10736. * @category Collection
  10737. * @param {Array|Object} collection The collection to shuffle.
  10738. * @returns {Array} Returns the new shuffled array.
  10739. * @example
  10740. *
  10741. * _.shuffle([1, 2, 3, 4]);
  10742. * // => [4, 1, 3, 2]
  10743. */
  10744. function shuffle(collection) {
  10745. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  10746. return func(collection);
  10747. }
  10748. /**
  10749. * Gets the size of `collection` by returning its length for array-like
  10750. * values or the number of own enumerable string keyed properties for objects.
  10751. *
  10752. * @static
  10753. * @memberOf _
  10754. * @since 0.1.0
  10755. * @category Collection
  10756. * @param {Array|Object|string} collection The collection to inspect.
  10757. * @returns {number} Returns the collection size.
  10758. * @example
  10759. *
  10760. * _.size([1, 2, 3]);
  10761. * // => 3
  10762. *
  10763. * _.size({ 'a': 1, 'b': 2 });
  10764. * // => 2
  10765. *
  10766. * _.size('pebbles');
  10767. * // => 7
  10768. */
  10769. function size(collection) {
  10770. if (collection == null) {
  10771. return 0;
  10772. }
  10773. if (isArrayLike(collection)) {
  10774. return isString(collection) ? stringSize(collection) : collection.length;
  10775. }
  10776. var tag = getTag(collection);
  10777. if (tag == mapTag || tag == setTag) {
  10778. return collection.size;
  10779. }
  10780. return baseKeys(collection).length;
  10781. }
  10782. /**
  10783. * Checks if `predicate` returns truthy for **any** element of `collection`.
  10784. * Iteration is stopped once `predicate` returns truthy. The predicate is
  10785. * invoked with three arguments: (value, index|key, collection).
  10786. *
  10787. * @static
  10788. * @memberOf _
  10789. * @since 0.1.0
  10790. * @category Collection
  10791. * @param {Array|Object} collection The collection to iterate over.
  10792. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10793. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10794. * @returns {boolean} Returns `true` if any element passes the predicate check,
  10795. * else `false`.
  10796. * @example
  10797. *
  10798. * _.some([null, 0, 'yes', false], Boolean);
  10799. * // => true
  10800. *
  10801. * var users = [
  10802. * { 'user': 'barney', 'active': true },
  10803. * { 'user': 'fred', 'active': false }
  10804. * ];
  10805. *
  10806. * // The `_.matches` iteratee shorthand.
  10807. * _.some(users, { 'user': 'barney', 'active': false });
  10808. * // => false
  10809. *
  10810. * // The `_.matchesProperty` iteratee shorthand.
  10811. * _.some(users, ['active', false]);
  10812. * // => true
  10813. *
  10814. * // The `_.property` iteratee shorthand.
  10815. * _.some(users, 'active');
  10816. * // => true
  10817. */
  10818. function some(collection, predicate, guard) {
  10819. var func = isArray(collection) ? arraySome : baseSome;
  10820. if (guard && isIterateeCall(collection, predicate, guard)) {
  10821. predicate = undefined;
  10822. }
  10823. return func(collection, getIteratee(predicate, 3));
  10824. }
  10825. /**
  10826. * Creates an array of elements, sorted in ascending order by the results of
  10827. * running each element in a collection thru each iteratee. This method
  10828. * performs a stable sort, that is, it preserves the original sort order of
  10829. * equal elements. The iteratees are invoked with one argument: (value).
  10830. *
  10831. * @static
  10832. * @memberOf _
  10833. * @since 0.1.0
  10834. * @category Collection
  10835. * @param {Array|Object} collection The collection to iterate over.
  10836. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  10837. * The iteratees to sort by.
  10838. * @returns {Array} Returns the new sorted array.
  10839. * @example
  10840. *
  10841. * var users = [
  10842. * { 'user': 'fred', 'age': 48 },
  10843. * { 'user': 'barney', 'age': 36 },
  10844. * { 'user': 'fred', 'age': 30 },
  10845. * { 'user': 'barney', 'age': 34 }
  10846. * ];
  10847. *
  10848. * _.sortBy(users, [function(o) { return o.user; }]);
  10849. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  10850. *
  10851. * _.sortBy(users, ['user', 'age']);
  10852. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  10853. */
  10854. var sortBy = baseRest(function(collection, iteratees) {
  10855. if (collection == null) {
  10856. return [];
  10857. }
  10858. var length = iteratees.length;
  10859. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  10860. iteratees = [];
  10861. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  10862. iteratees = [iteratees[0]];
  10863. }
  10864. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  10865. });
  10866. /*------------------------------------------------------------------------*/
  10867. /**
  10868. * Gets the timestamp of the number of milliseconds that have elapsed since
  10869. * the Unix epoch (1 January 1970 00:00:00 UTC).
  10870. *
  10871. * @static
  10872. * @memberOf _
  10873. * @since 2.4.0
  10874. * @category Date
  10875. * @returns {number} Returns the timestamp.
  10876. * @example
  10877. *
  10878. * _.defer(function(stamp) {
  10879. * console.log(_.now() - stamp);
  10880. * }, _.now());
  10881. * // => Logs the number of milliseconds it took for the deferred invocation.
  10882. */
  10883. var now = ctxNow || function() {
  10884. return root.Date.now();
  10885. };
  10886. /*------------------------------------------------------------------------*/
  10887. /**
  10888. * The opposite of `_.before`; this method creates a function that invokes
  10889. * `func` once it's called `n` or more times.
  10890. *
  10891. * @static
  10892. * @memberOf _
  10893. * @since 0.1.0
  10894. * @category Function
  10895. * @param {number} n The number of calls before `func` is invoked.
  10896. * @param {Function} func The function to restrict.
  10897. * @returns {Function} Returns the new restricted function.
  10898. * @example
  10899. *
  10900. * var saves = ['profile', 'settings'];
  10901. *
  10902. * var done = _.after(saves.length, function() {
  10903. * console.log('done saving!');
  10904. * });
  10905. *
  10906. * _.forEach(saves, function(type) {
  10907. * asyncSave({ 'type': type, 'complete': done });
  10908. * });
  10909. * // => Logs 'done saving!' after the two async saves have completed.
  10910. */
  10911. function after(n, func) {
  10912. if (typeof func != 'function') {
  10913. throw new TypeError(FUNC_ERROR_TEXT);
  10914. }
  10915. n = toInteger(n);
  10916. return function() {
  10917. if (--n < 1) {
  10918. return func.apply(this, arguments);
  10919. }
  10920. };
  10921. }
  10922. /**
  10923. * Creates a function that invokes `func`, with up to `n` arguments,
  10924. * ignoring any additional arguments.
  10925. *
  10926. * @static
  10927. * @memberOf _
  10928. * @since 3.0.0
  10929. * @category Function
  10930. * @param {Function} func The function to cap arguments for.
  10931. * @param {number} [n=func.length] The arity cap.
  10932. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10933. * @returns {Function} Returns the new capped function.
  10934. * @example
  10935. *
  10936. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  10937. * // => [6, 8, 10]
  10938. */
  10939. function ary(func, n, guard) {
  10940. n = guard ? undefined : n;
  10941. n = (func && n == null) ? func.length : n;
  10942. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  10943. }
  10944. /**
  10945. * Creates a function that invokes `func`, with the `this` binding and arguments
  10946. * of the created function, while it's called less than `n` times. Subsequent
  10947. * calls to the created function return the result of the last `func` invocation.
  10948. *
  10949. * @static
  10950. * @memberOf _
  10951. * @since 3.0.0
  10952. * @category Function
  10953. * @param {number} n The number of calls at which `func` is no longer invoked.
  10954. * @param {Function} func The function to restrict.
  10955. * @returns {Function} Returns the new restricted function.
  10956. * @example
  10957. *
  10958. * jQuery(element).on('click', _.before(5, addContactToList));
  10959. * // => Allows adding up to 4 contacts to the list.
  10960. */
  10961. function before(n, func) {
  10962. var result;
  10963. if (typeof func != 'function') {
  10964. throw new TypeError(FUNC_ERROR_TEXT);
  10965. }
  10966. n = toInteger(n);
  10967. return function() {
  10968. if (--n > 0) {
  10969. result = func.apply(this, arguments);
  10970. }
  10971. if (n <= 1) {
  10972. func = undefined;
  10973. }
  10974. return result;
  10975. };
  10976. }
  10977. /**
  10978. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  10979. * and `partials` prepended to the arguments it receives.
  10980. *
  10981. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  10982. * may be used as a placeholder for partially applied arguments.
  10983. *
  10984. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  10985. * property of bound functions.
  10986. *
  10987. * @static
  10988. * @memberOf _
  10989. * @since 0.1.0
  10990. * @category Function
  10991. * @param {Function} func The function to bind.
  10992. * @param {*} thisArg The `this` binding of `func`.
  10993. * @param {...*} [partials] The arguments to be partially applied.
  10994. * @returns {Function} Returns the new bound function.
  10995. * @example
  10996. *
  10997. * function greet(greeting, punctuation) {
  10998. * return greeting + ' ' + this.user + punctuation;
  10999. * }
  11000. *
  11001. * var object = { 'user': 'fred' };
  11002. *
  11003. * var bound = _.bind(greet, object, 'hi');
  11004. * bound('!');
  11005. * // => 'hi fred!'
  11006. *
  11007. * // Bound with placeholders.
  11008. * var bound = _.bind(greet, object, _, '!');
  11009. * bound('hi');
  11010. * // => 'hi fred!'
  11011. */
  11012. var bind = baseRest(function(func, thisArg, partials) {
  11013. var bitmask = WRAP_BIND_FLAG;
  11014. if (partials.length) {
  11015. var holders = replaceHolders(partials, getHolder(bind));
  11016. bitmask |= WRAP_PARTIAL_FLAG;
  11017. }
  11018. return createWrap(func, bitmask, thisArg, partials, holders);
  11019. });
  11020. /**
  11021. * Creates a function that invokes the method at `object[key]` with `partials`
  11022. * prepended to the arguments it receives.
  11023. *
  11024. * This method differs from `_.bind` by allowing bound functions to reference
  11025. * methods that may be redefined or don't yet exist. See
  11026. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  11027. * for more details.
  11028. *
  11029. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  11030. * builds, may be used as a placeholder for partially applied arguments.
  11031. *
  11032. * @static
  11033. * @memberOf _
  11034. * @since 0.10.0
  11035. * @category Function
  11036. * @param {Object} object The object to invoke the method on.
  11037. * @param {string} key The key of the method.
  11038. * @param {...*} [partials] The arguments to be partially applied.
  11039. * @returns {Function} Returns the new bound function.
  11040. * @example
  11041. *
  11042. * var object = {
  11043. * 'user': 'fred',
  11044. * 'greet': function(greeting, punctuation) {
  11045. * return greeting + ' ' + this.user + punctuation;
  11046. * }
  11047. * };
  11048. *
  11049. * var bound = _.bindKey(object, 'greet', 'hi');
  11050. * bound('!');
  11051. * // => 'hi fred!'
  11052. *
  11053. * object.greet = function(greeting, punctuation) {
  11054. * return greeting + 'ya ' + this.user + punctuation;
  11055. * };
  11056. *
  11057. * bound('!');
  11058. * // => 'hiya fred!'
  11059. *
  11060. * // Bound with placeholders.
  11061. * var bound = _.bindKey(object, 'greet', _, '!');
  11062. * bound('hi');
  11063. * // => 'hiya fred!'
  11064. */
  11065. var bindKey = baseRest(function(object, key, partials) {
  11066. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  11067. if (partials.length) {
  11068. var holders = replaceHolders(partials, getHolder(bindKey));
  11069. bitmask |= WRAP_PARTIAL_FLAG;
  11070. }
  11071. return createWrap(key, bitmask, object, partials, holders);
  11072. });
  11073. /**
  11074. * Creates a function that accepts arguments of `func` and either invokes
  11075. * `func` returning its result, if at least `arity` number of arguments have
  11076. * been provided, or returns a function that accepts the remaining `func`
  11077. * arguments, and so on. The arity of `func` may be specified if `func.length`
  11078. * is not sufficient.
  11079. *
  11080. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  11081. * may be used as a placeholder for provided arguments.
  11082. *
  11083. * **Note:** This method doesn't set the "length" property of curried functions.
  11084. *
  11085. * @static
  11086. * @memberOf _
  11087. * @since 2.0.0
  11088. * @category Function
  11089. * @param {Function} func The function to curry.
  11090. * @param {number} [arity=func.length] The arity of `func`.
  11091. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  11092. * @returns {Function} Returns the new curried function.
  11093. * @example
  11094. *
  11095. * var abc = function(a, b, c) {
  11096. * return [a, b, c];
  11097. * };
  11098. *
  11099. * var curried = _.curry(abc);
  11100. *
  11101. * curried(1)(2)(3);
  11102. * // => [1, 2, 3]
  11103. *
  11104. * curried(1, 2)(3);
  11105. * // => [1, 2, 3]
  11106. *
  11107. * curried(1, 2, 3);
  11108. * // => [1, 2, 3]
  11109. *
  11110. * // Curried with placeholders.
  11111. * curried(1)(_, 3)(2);
  11112. * // => [1, 2, 3]
  11113. */
  11114. function curry(func, arity, guard) {
  11115. arity = guard ? undefined : arity;
  11116. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  11117. result.placeholder = curry.placeholder;
  11118. return result;
  11119. }
  11120. /**
  11121. * This method is like `_.curry` except that arguments are applied to `func`
  11122. * in the manner of `_.partialRight` instead of `_.partial`.
  11123. *
  11124. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  11125. * builds, may be used as a placeholder for provided arguments.
  11126. *
  11127. * **Note:** This method doesn't set the "length" property of curried functions.
  11128. *
  11129. * @static
  11130. * @memberOf _
  11131. * @since 3.0.0
  11132. * @category Function
  11133. * @param {Function} func The function to curry.
  11134. * @param {number} [arity=func.length] The arity of `func`.
  11135. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  11136. * @returns {Function} Returns the new curried function.
  11137. * @example
  11138. *
  11139. * var abc = function(a, b, c) {
  11140. * return [a, b, c];
  11141. * };
  11142. *
  11143. * var curried = _.curryRight(abc);
  11144. *
  11145. * curried(3)(2)(1);
  11146. * // => [1, 2, 3]
  11147. *
  11148. * curried(2, 3)(1);
  11149. * // => [1, 2, 3]
  11150. *
  11151. * curried(1, 2, 3);
  11152. * // => [1, 2, 3]
  11153. *
  11154. * // Curried with placeholders.
  11155. * curried(3)(1, _)(2);
  11156. * // => [1, 2, 3]
  11157. */
  11158. function curryRight(func, arity, guard) {
  11159. arity = guard ? undefined : arity;
  11160. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  11161. result.placeholder = curryRight.placeholder;
  11162. return result;
  11163. }
  11164. /**
  11165. * Creates a debounced function that delays invoking `func` until after `wait`
  11166. * milliseconds have elapsed since the last time the debounced function was
  11167. * invoked. The debounced function comes with a `cancel` method to cancel
  11168. * delayed `func` invocations and a `flush` method to immediately invoke them.
  11169. * Provide `options` to indicate whether `func` should be invoked on the
  11170. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  11171. * with the last arguments provided to the debounced function. Subsequent
  11172. * calls to the debounced function return the result of the last `func`
  11173. * invocation.
  11174. *
  11175. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  11176. * invoked on the trailing edge of the timeout only if the debounced function
  11177. * is invoked more than once during the `wait` timeout.
  11178. *
  11179. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  11180. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  11181. *
  11182. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  11183. * for details over the differences between `_.debounce` and `_.throttle`.
  11184. *
  11185. * @static
  11186. * @memberOf _
  11187. * @since 0.1.0
  11188. * @category Function
  11189. * @param {Function} func The function to debounce.
  11190. * @param {number} [wait=0] The number of milliseconds to delay.
  11191. * @param {Object} [options={}] The options object.
  11192. * @param {boolean} [options.leading=false]
  11193. * Specify invoking on the leading edge of the timeout.
  11194. * @param {number} [options.maxWait]
  11195. * The maximum time `func` is allowed to be delayed before it's invoked.
  11196. * @param {boolean} [options.trailing=true]
  11197. * Specify invoking on the trailing edge of the timeout.
  11198. * @returns {Function} Returns the new debounced function.
  11199. * @example
  11200. *
  11201. * // Avoid costly calculations while the window size is in flux.
  11202. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  11203. *
  11204. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  11205. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  11206. * 'leading': true,
  11207. * 'trailing': false
  11208. * }));
  11209. *
  11210. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  11211. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  11212. * var source = new EventSource('/stream');
  11213. * jQuery(source).on('message', debounced);
  11214. *
  11215. * // Cancel the trailing debounced invocation.
  11216. * jQuery(window).on('popstate', debounced.cancel);
  11217. */
  11218. function debounce(func, wait, options) {
  11219. var lastArgs,
  11220. lastThis,
  11221. maxWait,
  11222. result,
  11223. timerId,
  11224. lastCallTime,
  11225. lastInvokeTime = 0,
  11226. leading = false,
  11227. maxing = false,
  11228. trailing = true;
  11229. if (typeof func != 'function') {
  11230. throw new TypeError(FUNC_ERROR_TEXT);
  11231. }
  11232. wait = toNumber(wait) || 0;
  11233. if (isObject(options)) {
  11234. leading = !!options.leading;
  11235. maxing = 'maxWait' in options;
  11236. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  11237. trailing = 'trailing' in options ? !!options.trailing : trailing;
  11238. }
  11239. function invokeFunc(time) {
  11240. var args = lastArgs,
  11241. thisArg = lastThis;
  11242. lastArgs = lastThis = undefined;
  11243. lastInvokeTime = time;
  11244. result = func.apply(thisArg, args);
  11245. return result;
  11246. }
  11247. function leadingEdge(time) {
  11248. // Reset any `maxWait` timer.
  11249. lastInvokeTime = time;
  11250. // Start the timer for the trailing edge.
  11251. timerId = setTimeout(timerExpired, wait);
  11252. // Invoke the leading edge.
  11253. return leading ? invokeFunc(time) : result;
  11254. }
  11255. function remainingWait(time) {
  11256. var timeSinceLastCall = time - lastCallTime,
  11257. timeSinceLastInvoke = time - lastInvokeTime,
  11258. timeWaiting = wait - timeSinceLastCall;
  11259. return maxing
  11260. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  11261. : timeWaiting;
  11262. }
  11263. function shouldInvoke(time) {
  11264. var timeSinceLastCall = time - lastCallTime,
  11265. timeSinceLastInvoke = time - lastInvokeTime;
  11266. // Either this is the first call, activity has stopped and we're at the
  11267. // trailing edge, the system time has gone backwards and we're treating
  11268. // it as the trailing edge, or we've hit the `maxWait` limit.
  11269. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  11270. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  11271. }
  11272. function timerExpired() {
  11273. var time = now();
  11274. if (shouldInvoke(time)) {
  11275. return trailingEdge(time);
  11276. }
  11277. // Restart the timer.
  11278. timerId = setTimeout(timerExpired, remainingWait(time));
  11279. }
  11280. function trailingEdge(time) {
  11281. timerId = undefined;
  11282. // Only invoke if we have `lastArgs` which means `func` has been
  11283. // debounced at least once.
  11284. if (trailing && lastArgs) {
  11285. return invokeFunc(time);
  11286. }
  11287. lastArgs = lastThis = undefined;
  11288. return result;
  11289. }
  11290. function cancel() {
  11291. if (timerId !== undefined) {
  11292. clearTimeout(timerId);
  11293. }
  11294. lastInvokeTime = 0;
  11295. lastArgs = lastCallTime = lastThis = timerId = undefined;
  11296. }
  11297. function flush() {
  11298. return timerId === undefined ? result : trailingEdge(now());
  11299. }
  11300. function debounced() {
  11301. var time = now(),
  11302. isInvoking = shouldInvoke(time);
  11303. lastArgs = arguments;
  11304. lastThis = this;
  11305. lastCallTime = time;
  11306. if (isInvoking) {
  11307. if (timerId === undefined) {
  11308. return leadingEdge(lastCallTime);
  11309. }
  11310. if (maxing) {
  11311. // Handle invocations in a tight loop.
  11312. clearTimeout(timerId);
  11313. timerId = setTimeout(timerExpired, wait);
  11314. return invokeFunc(lastCallTime);
  11315. }
  11316. }
  11317. if (timerId === undefined) {
  11318. timerId = setTimeout(timerExpired, wait);
  11319. }
  11320. return result;
  11321. }
  11322. debounced.cancel = cancel;
  11323. debounced.flush = flush;
  11324. return debounced;
  11325. }
  11326. /**
  11327. * Defers invoking the `func` until the current call stack has cleared. Any
  11328. * additional arguments are provided to `func` when it's invoked.
  11329. *
  11330. * @static
  11331. * @memberOf _
  11332. * @since 0.1.0
  11333. * @category Function
  11334. * @param {Function} func The function to defer.
  11335. * @param {...*} [args] The arguments to invoke `func` with.
  11336. * @returns {number} Returns the timer id.
  11337. * @example
  11338. *
  11339. * _.defer(function(text) {
  11340. * console.log(text);
  11341. * }, 'deferred');
  11342. * // => Logs 'deferred' after one millisecond.
  11343. */
  11344. var defer = baseRest(function(func, args) {
  11345. return baseDelay(func, 1, args);
  11346. });
  11347. /**
  11348. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  11349. * provided to `func` when it's invoked.
  11350. *
  11351. * @static
  11352. * @memberOf _
  11353. * @since 0.1.0
  11354. * @category Function
  11355. * @param {Function} func The function to delay.
  11356. * @param {number} wait The number of milliseconds to delay invocation.
  11357. * @param {...*} [args] The arguments to invoke `func` with.
  11358. * @returns {number} Returns the timer id.
  11359. * @example
  11360. *
  11361. * _.delay(function(text) {
  11362. * console.log(text);
  11363. * }, 1000, 'later');
  11364. * // => Logs 'later' after one second.
  11365. */
  11366. var delay = baseRest(function(func, wait, args) {
  11367. return baseDelay(func, toNumber(wait) || 0, args);
  11368. });
  11369. /**
  11370. * Creates a function that invokes `func` with arguments reversed.
  11371. *
  11372. * @static
  11373. * @memberOf _
  11374. * @since 4.0.0
  11375. * @category Function
  11376. * @param {Function} func The function to flip arguments for.
  11377. * @returns {Function} Returns the new flipped function.
  11378. * @example
  11379. *
  11380. * var flipped = _.flip(function() {
  11381. * return _.toArray(arguments);
  11382. * });
  11383. *
  11384. * flipped('a', 'b', 'c', 'd');
  11385. * // => ['d', 'c', 'b', 'a']
  11386. */
  11387. function flip(func) {
  11388. return createWrap(func, WRAP_FLIP_FLAG);
  11389. }
  11390. /**
  11391. * Creates a function that memoizes the result of `func`. If `resolver` is
  11392. * provided, it determines the cache key for storing the result based on the
  11393. * arguments provided to the memoized function. By default, the first argument
  11394. * provided to the memoized function is used as the map cache key. The `func`
  11395. * is invoked with the `this` binding of the memoized function.
  11396. *
  11397. * **Note:** The cache is exposed as the `cache` property on the memoized
  11398. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  11399. * constructor with one whose instances implement the
  11400. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  11401. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  11402. *
  11403. * @static
  11404. * @memberOf _
  11405. * @since 0.1.0
  11406. * @category Function
  11407. * @param {Function} func The function to have its output memoized.
  11408. * @param {Function} [resolver] The function to resolve the cache key.
  11409. * @returns {Function} Returns the new memoized function.
  11410. * @example
  11411. *
  11412. * var object = { 'a': 1, 'b': 2 };
  11413. * var other = { 'c': 3, 'd': 4 };
  11414. *
  11415. * var values = _.memoize(_.values);
  11416. * values(object);
  11417. * // => [1, 2]
  11418. *
  11419. * values(other);
  11420. * // => [3, 4]
  11421. *
  11422. * object.a = 2;
  11423. * values(object);
  11424. * // => [1, 2]
  11425. *
  11426. * // Modify the result cache.
  11427. * values.cache.set(object, ['a', 'b']);
  11428. * values(object);
  11429. * // => ['a', 'b']
  11430. *
  11431. * // Replace `_.memoize.Cache`.
  11432. * _.memoize.Cache = WeakMap;
  11433. */
  11434. function memoize(func, resolver) {
  11435. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  11436. throw new TypeError(FUNC_ERROR_TEXT);
  11437. }
  11438. var memoized = function() {
  11439. var args = arguments,
  11440. key = resolver ? resolver.apply(this, args) : args[0],
  11441. cache = memoized.cache;
  11442. if (cache.has(key)) {
  11443. return cache.get(key);
  11444. }
  11445. var result = func.apply(this, args);
  11446. memoized.cache = cache.set(key, result) || cache;
  11447. return result;
  11448. };
  11449. memoized.cache = new (memoize.Cache || MapCache);
  11450. return memoized;
  11451. }
  11452. // Expose `MapCache`.
  11453. memoize.Cache = MapCache;
  11454. /**
  11455. * Creates a function that negates the result of the predicate `func`. The
  11456. * `func` predicate is invoked with the `this` binding and arguments of the
  11457. * created function.
  11458. *
  11459. * @static
  11460. * @memberOf _
  11461. * @since 3.0.0
  11462. * @category Function
  11463. * @param {Function} predicate The predicate to negate.
  11464. * @returns {Function} Returns the new negated function.
  11465. * @example
  11466. *
  11467. * function isEven(n) {
  11468. * return n % 2 == 0;
  11469. * }
  11470. *
  11471. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  11472. * // => [1, 3, 5]
  11473. */
  11474. function negate(predicate) {
  11475. if (typeof predicate != 'function') {
  11476. throw new TypeError(FUNC_ERROR_TEXT);
  11477. }
  11478. return function() {
  11479. var args = arguments;
  11480. switch (args.length) {
  11481. case 0: return !predicate.call(this);
  11482. case 1: return !predicate.call(this, args[0]);
  11483. case 2: return !predicate.call(this, args[0], args[1]);
  11484. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  11485. }
  11486. return !predicate.apply(this, args);
  11487. };
  11488. }
  11489. /**
  11490. * Creates a function that is restricted to invoking `func` once. Repeat calls
  11491. * to the function return the value of the first invocation. The `func` is
  11492. * invoked with the `this` binding and arguments of the created function.
  11493. *
  11494. * @static
  11495. * @memberOf _
  11496. * @since 0.1.0
  11497. * @category Function
  11498. * @param {Function} func The function to restrict.
  11499. * @returns {Function} Returns the new restricted function.
  11500. * @example
  11501. *
  11502. * var initialize = _.once(createApplication);
  11503. * initialize();
  11504. * initialize();
  11505. * // => `createApplication` is invoked once
  11506. */
  11507. function once(func) {
  11508. return before(2, func);
  11509. }
  11510. /**
  11511. * Creates a function that invokes `func` with its arguments transformed.
  11512. *
  11513. * @static
  11514. * @since 4.0.0
  11515. * @memberOf _
  11516. * @category Function
  11517. * @param {Function} func The function to wrap.
  11518. * @param {...(Function|Function[])} [transforms=[_.identity]]
  11519. * The argument transforms.
  11520. * @returns {Function} Returns the new function.
  11521. * @example
  11522. *
  11523. * function doubled(n) {
  11524. * return n * 2;
  11525. * }
  11526. *
  11527. * function square(n) {
  11528. * return n * n;
  11529. * }
  11530. *
  11531. * var func = _.overArgs(function(x, y) {
  11532. * return [x, y];
  11533. * }, [square, doubled]);
  11534. *
  11535. * func(9, 3);
  11536. * // => [81, 6]
  11537. *
  11538. * func(10, 5);
  11539. * // => [100, 10]
  11540. */
  11541. var overArgs = castRest(function(func, transforms) {
  11542. transforms = (transforms.length == 1 && isArray(transforms[0]))
  11543. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  11544. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  11545. var funcsLength = transforms.length;
  11546. return baseRest(function(args) {
  11547. var index = -1,
  11548. length = nativeMin(args.length, funcsLength);
  11549. while (++index < length) {
  11550. args[index] = transforms[index].call(this, args[index]);
  11551. }
  11552. return apply(func, this, args);
  11553. });
  11554. });
  11555. /**
  11556. * Creates a function that invokes `func` with `partials` prepended to the
  11557. * arguments it receives. This method is like `_.bind` except it does **not**
  11558. * alter the `this` binding.
  11559. *
  11560. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  11561. * builds, may be used as a placeholder for partially applied arguments.
  11562. *
  11563. * **Note:** This method doesn't set the "length" property of partially
  11564. * applied functions.
  11565. *
  11566. * @static
  11567. * @memberOf _
  11568. * @since 0.2.0
  11569. * @category Function
  11570. * @param {Function} func The function to partially apply arguments to.
  11571. * @param {...*} [partials] The arguments to be partially applied.
  11572. * @returns {Function} Returns the new partially applied function.
  11573. * @example
  11574. *
  11575. * function greet(greeting, name) {
  11576. * return greeting + ' ' + name;
  11577. * }
  11578. *
  11579. * var sayHelloTo = _.partial(greet, 'hello');
  11580. * sayHelloTo('fred');
  11581. * // => 'hello fred'
  11582. *
  11583. * // Partially applied with placeholders.
  11584. * var greetFred = _.partial(greet, _, 'fred');
  11585. * greetFred('hi');
  11586. * // => 'hi fred'
  11587. */
  11588. var partial = baseRest(function(func, partials) {
  11589. var holders = replaceHolders(partials, getHolder(partial));
  11590. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  11591. });
  11592. /**
  11593. * This method is like `_.partial` except that partially applied arguments
  11594. * are appended to the arguments it receives.
  11595. *
  11596. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  11597. * builds, may be used as a placeholder for partially applied arguments.
  11598. *
  11599. * **Note:** This method doesn't set the "length" property of partially
  11600. * applied functions.
  11601. *
  11602. * @static
  11603. * @memberOf _
  11604. * @since 1.0.0
  11605. * @category Function
  11606. * @param {Function} func The function to partially apply arguments to.
  11607. * @param {...*} [partials] The arguments to be partially applied.
  11608. * @returns {Function} Returns the new partially applied function.
  11609. * @example
  11610. *
  11611. * function greet(greeting, name) {
  11612. * return greeting + ' ' + name;
  11613. * }
  11614. *
  11615. * var greetFred = _.partialRight(greet, 'fred');
  11616. * greetFred('hi');
  11617. * // => 'hi fred'
  11618. *
  11619. * // Partially applied with placeholders.
  11620. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  11621. * sayHelloTo('fred');
  11622. * // => 'hello fred'
  11623. */
  11624. var partialRight = baseRest(function(func, partials) {
  11625. var holders = replaceHolders(partials, getHolder(partialRight));
  11626. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  11627. });
  11628. /**
  11629. * Creates a function that invokes `func` with arguments arranged according
  11630. * to the specified `indexes` where the argument value at the first index is
  11631. * provided as the first argument, the argument value at the second index is
  11632. * provided as the second argument, and so on.
  11633. *
  11634. * @static
  11635. * @memberOf _
  11636. * @since 3.0.0
  11637. * @category Function
  11638. * @param {Function} func The function to rearrange arguments for.
  11639. * @param {...(number|number[])} indexes The arranged argument indexes.
  11640. * @returns {Function} Returns the new function.
  11641. * @example
  11642. *
  11643. * var rearged = _.rearg(function(a, b, c) {
  11644. * return [a, b, c];
  11645. * }, [2, 0, 1]);
  11646. *
  11647. * rearged('b', 'c', 'a')
  11648. * // => ['a', 'b', 'c']
  11649. */
  11650. var rearg = flatRest(function(func, indexes) {
  11651. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  11652. });
  11653. /**
  11654. * Creates a function that invokes `func` with the `this` binding of the
  11655. * created function and arguments from `start` and beyond provided as
  11656. * an array.
  11657. *
  11658. * **Note:** This method is based on the
  11659. * [rest parameter](https://mdn.io/rest_parameters).
  11660. *
  11661. * @static
  11662. * @memberOf _
  11663. * @since 4.0.0
  11664. * @category Function
  11665. * @param {Function} func The function to apply a rest parameter to.
  11666. * @param {number} [start=func.length-1] The start position of the rest parameter.
  11667. * @returns {Function} Returns the new function.
  11668. * @example
  11669. *
  11670. * var say = _.rest(function(what, names) {
  11671. * return what + ' ' + _.initial(names).join(', ') +
  11672. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  11673. * });
  11674. *
  11675. * say('hello', 'fred', 'barney', 'pebbles');
  11676. * // => 'hello fred, barney, & pebbles'
  11677. */
  11678. function rest(func, start) {
  11679. if (typeof func != 'function') {
  11680. throw new TypeError(FUNC_ERROR_TEXT);
  11681. }
  11682. start = start === undefined ? start : toInteger(start);
  11683. return baseRest(func, start);
  11684. }
  11685. /**
  11686. * Creates a function that invokes `func` with the `this` binding of the
  11687. * create function and an array of arguments much like
  11688. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  11689. *
  11690. * **Note:** This method is based on the
  11691. * [spread operator](https://mdn.io/spread_operator).
  11692. *
  11693. * @static
  11694. * @memberOf _
  11695. * @since 3.2.0
  11696. * @category Function
  11697. * @param {Function} func The function to spread arguments over.
  11698. * @param {number} [start=0] The start position of the spread.
  11699. * @returns {Function} Returns the new function.
  11700. * @example
  11701. *
  11702. * var say = _.spread(function(who, what) {
  11703. * return who + ' says ' + what;
  11704. * });
  11705. *
  11706. * say(['fred', 'hello']);
  11707. * // => 'fred says hello'
  11708. *
  11709. * var numbers = Promise.all([
  11710. * Promise.resolve(40),
  11711. * Promise.resolve(36)
  11712. * ]);
  11713. *
  11714. * numbers.then(_.spread(function(x, y) {
  11715. * return x + y;
  11716. * }));
  11717. * // => a Promise of 76
  11718. */
  11719. function spread(func, start) {
  11720. if (typeof func != 'function') {
  11721. throw new TypeError(FUNC_ERROR_TEXT);
  11722. }
  11723. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  11724. return baseRest(function(args) {
  11725. var array = args[start],
  11726. otherArgs = castSlice(args, 0, start);
  11727. if (array) {
  11728. arrayPush(otherArgs, array);
  11729. }
  11730. return apply(func, this, otherArgs);
  11731. });
  11732. }
  11733. /**
  11734. * Creates a throttled function that only invokes `func` at most once per
  11735. * every `wait` milliseconds. The throttled function comes with a `cancel`
  11736. * method to cancel delayed `func` invocations and a `flush` method to
  11737. * immediately invoke them. Provide `options` to indicate whether `func`
  11738. * should be invoked on the leading and/or trailing edge of the `wait`
  11739. * timeout. The `func` is invoked with the last arguments provided to the
  11740. * throttled function. Subsequent calls to the throttled function return the
  11741. * result of the last `func` invocation.
  11742. *
  11743. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  11744. * invoked on the trailing edge of the timeout only if the throttled function
  11745. * is invoked more than once during the `wait` timeout.
  11746. *
  11747. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  11748. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  11749. *
  11750. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  11751. * for details over the differences between `_.throttle` and `_.debounce`.
  11752. *
  11753. * @static
  11754. * @memberOf _
  11755. * @since 0.1.0
  11756. * @category Function
  11757. * @param {Function} func The function to throttle.
  11758. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  11759. * @param {Object} [options={}] The options object.
  11760. * @param {boolean} [options.leading=true]
  11761. * Specify invoking on the leading edge of the timeout.
  11762. * @param {boolean} [options.trailing=true]
  11763. * Specify invoking on the trailing edge of the timeout.
  11764. * @returns {Function} Returns the new throttled function.
  11765. * @example
  11766. *
  11767. * // Avoid excessively updating the position while scrolling.
  11768. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  11769. *
  11770. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  11771. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  11772. * jQuery(element).on('click', throttled);
  11773. *
  11774. * // Cancel the trailing throttled invocation.
  11775. * jQuery(window).on('popstate', throttled.cancel);
  11776. */
  11777. function throttle(func, wait, options) {
  11778. var leading = true,
  11779. trailing = true;
  11780. if (typeof func != 'function') {
  11781. throw new TypeError(FUNC_ERROR_TEXT);
  11782. }
  11783. if (isObject(options)) {
  11784. leading = 'leading' in options ? !!options.leading : leading;
  11785. trailing = 'trailing' in options ? !!options.trailing : trailing;
  11786. }
  11787. return debounce(func, wait, {
  11788. 'leading': leading,
  11789. 'maxWait': wait,
  11790. 'trailing': trailing
  11791. });
  11792. }
  11793. /**
  11794. * Creates a function that accepts up to one argument, ignoring any
  11795. * additional arguments.
  11796. *
  11797. * @static
  11798. * @memberOf _
  11799. * @since 4.0.0
  11800. * @category Function
  11801. * @param {Function} func The function to cap arguments for.
  11802. * @returns {Function} Returns the new capped function.
  11803. * @example
  11804. *
  11805. * _.map(['6', '8', '10'], _.unary(parseInt));
  11806. * // => [6, 8, 10]
  11807. */
  11808. function unary(func) {
  11809. return ary(func, 1);
  11810. }
  11811. /**
  11812. * Creates a function that provides `value` to `wrapper` as its first
  11813. * argument. Any additional arguments provided to the function are appended
  11814. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  11815. * binding of the created function.
  11816. *
  11817. * @static
  11818. * @memberOf _
  11819. * @since 0.1.0
  11820. * @category Function
  11821. * @param {*} value The value to wrap.
  11822. * @param {Function} [wrapper=identity] The wrapper function.
  11823. * @returns {Function} Returns the new function.
  11824. * @example
  11825. *
  11826. * var p = _.wrap(_.escape, function(func, text) {
  11827. * return '<p>' + func(text) + '</p>';
  11828. * });
  11829. *
  11830. * p('fred, barney, & pebbles');
  11831. * // => '<p>fred, barney, &amp; pebbles</p>'
  11832. */
  11833. function wrap(value, wrapper) {
  11834. return partial(castFunction(wrapper), value);
  11835. }
  11836. /*------------------------------------------------------------------------*/
  11837. /**
  11838. * Casts `value` as an array if it's not one.
  11839. *
  11840. * @static
  11841. * @memberOf _
  11842. * @since 4.4.0
  11843. * @category Lang
  11844. * @param {*} value The value to inspect.
  11845. * @returns {Array} Returns the cast array.
  11846. * @example
  11847. *
  11848. * _.castArray(1);
  11849. * // => [1]
  11850. *
  11851. * _.castArray({ 'a': 1 });
  11852. * // => [{ 'a': 1 }]
  11853. *
  11854. * _.castArray('abc');
  11855. * // => ['abc']
  11856. *
  11857. * _.castArray(null);
  11858. * // => [null]
  11859. *
  11860. * _.castArray(undefined);
  11861. * // => [undefined]
  11862. *
  11863. * _.castArray();
  11864. * // => []
  11865. *
  11866. * var array = [1, 2, 3];
  11867. * console.log(_.castArray(array) === array);
  11868. * // => true
  11869. */
  11870. function castArray() {
  11871. if (!arguments.length) {
  11872. return [];
  11873. }
  11874. var value = arguments[0];
  11875. return isArray(value) ? value : [value];
  11876. }
  11877. /**
  11878. * Creates a shallow clone of `value`.
  11879. *
  11880. * **Note:** This method is loosely based on the
  11881. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  11882. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  11883. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  11884. * arrays. The own enumerable properties of `arguments` objects are cloned
  11885. * as plain objects. An empty object is returned for uncloneable values such
  11886. * as error objects, functions, DOM nodes, and WeakMaps.
  11887. *
  11888. * @static
  11889. * @memberOf _
  11890. * @since 0.1.0
  11891. * @category Lang
  11892. * @param {*} value The value to clone.
  11893. * @returns {*} Returns the cloned value.
  11894. * @see _.cloneDeep
  11895. * @example
  11896. *
  11897. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  11898. *
  11899. * var shallow = _.clone(objects);
  11900. * console.log(shallow[0] === objects[0]);
  11901. * // => true
  11902. */
  11903. function clone(value) {
  11904. return baseClone(value, CLONE_SYMBOLS_FLAG);
  11905. }
  11906. /**
  11907. * This method is like `_.clone` except that it accepts `customizer` which
  11908. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  11909. * cloning is handled by the method instead. The `customizer` is invoked with
  11910. * up to four arguments; (value [, index|key, object, stack]).
  11911. *
  11912. * @static
  11913. * @memberOf _
  11914. * @since 4.0.0
  11915. * @category Lang
  11916. * @param {*} value The value to clone.
  11917. * @param {Function} [customizer] The function to customize cloning.
  11918. * @returns {*} Returns the cloned value.
  11919. * @see _.cloneDeepWith
  11920. * @example
  11921. *
  11922. * function customizer(value) {
  11923. * if (_.isElement(value)) {
  11924. * return value.cloneNode(false);
  11925. * }
  11926. * }
  11927. *
  11928. * var el = _.cloneWith(document.body, customizer);
  11929. *
  11930. * console.log(el === document.body);
  11931. * // => false
  11932. * console.log(el.nodeName);
  11933. * // => 'BODY'
  11934. * console.log(el.childNodes.length);
  11935. * // => 0
  11936. */
  11937. function cloneWith(value, customizer) {
  11938. customizer = typeof customizer == 'function' ? customizer : undefined;
  11939. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  11940. }
  11941. /**
  11942. * This method is like `_.clone` except that it recursively clones `value`.
  11943. *
  11944. * @static
  11945. * @memberOf _
  11946. * @since 1.0.0
  11947. * @category Lang
  11948. * @param {*} value The value to recursively clone.
  11949. * @returns {*} Returns the deep cloned value.
  11950. * @see _.clone
  11951. * @example
  11952. *
  11953. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  11954. *
  11955. * var deep = _.cloneDeep(objects);
  11956. * console.log(deep[0] === objects[0]);
  11957. * // => false
  11958. */
  11959. function cloneDeep(value) {
  11960. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  11961. }
  11962. /**
  11963. * This method is like `_.cloneWith` except that it recursively clones `value`.
  11964. *
  11965. * @static
  11966. * @memberOf _
  11967. * @since 4.0.0
  11968. * @category Lang
  11969. * @param {*} value The value to recursively clone.
  11970. * @param {Function} [customizer] The function to customize cloning.
  11971. * @returns {*} Returns the deep cloned value.
  11972. * @see _.cloneWith
  11973. * @example
  11974. *
  11975. * function customizer(value) {
  11976. * if (_.isElement(value)) {
  11977. * return value.cloneNode(true);
  11978. * }
  11979. * }
  11980. *
  11981. * var el = _.cloneDeepWith(document.body, customizer);
  11982. *
  11983. * console.log(el === document.body);
  11984. * // => false
  11985. * console.log(el.nodeName);
  11986. * // => 'BODY'
  11987. * console.log(el.childNodes.length);
  11988. * // => 20
  11989. */
  11990. function cloneDeepWith(value, customizer) {
  11991. customizer = typeof customizer == 'function' ? customizer : undefined;
  11992. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  11993. }
  11994. /**
  11995. * Checks if `object` conforms to `source` by invoking the predicate
  11996. * properties of `source` with the corresponding property values of `object`.
  11997. *
  11998. * **Note:** This method is equivalent to `_.conforms` when `source` is
  11999. * partially applied.
  12000. *
  12001. * @static
  12002. * @memberOf _
  12003. * @since 4.14.0
  12004. * @category Lang
  12005. * @param {Object} object The object to inspect.
  12006. * @param {Object} source The object of property predicates to conform to.
  12007. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  12008. * @example
  12009. *
  12010. * var object = { 'a': 1, 'b': 2 };
  12011. *
  12012. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  12013. * // => true
  12014. *
  12015. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  12016. * // => false
  12017. */
  12018. function conformsTo(object, source) {
  12019. return source == null || baseConformsTo(object, source, keys(source));
  12020. }
  12021. /**
  12022. * Performs a
  12023. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  12024. * comparison between two values to determine if they are equivalent.
  12025. *
  12026. * @static
  12027. * @memberOf _
  12028. * @since 4.0.0
  12029. * @category Lang
  12030. * @param {*} value The value to compare.
  12031. * @param {*} other The other value to compare.
  12032. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  12033. * @example
  12034. *
  12035. * var object = { 'a': 1 };
  12036. * var other = { 'a': 1 };
  12037. *
  12038. * _.eq(object, object);
  12039. * // => true
  12040. *
  12041. * _.eq(object, other);
  12042. * // => false
  12043. *
  12044. * _.eq('a', 'a');
  12045. * // => true
  12046. *
  12047. * _.eq('a', Object('a'));
  12048. * // => false
  12049. *
  12050. * _.eq(NaN, NaN);
  12051. * // => true
  12052. */
  12053. function eq(value, other) {
  12054. return value === other || (value !== value && other !== other);
  12055. }
  12056. /**
  12057. * Checks if `value` is greater than `other`.
  12058. *
  12059. * @static
  12060. * @memberOf _
  12061. * @since 3.9.0
  12062. * @category Lang
  12063. * @param {*} value The value to compare.
  12064. * @param {*} other The other value to compare.
  12065. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  12066. * else `false`.
  12067. * @see _.lt
  12068. * @example
  12069. *
  12070. * _.gt(3, 1);
  12071. * // => true
  12072. *
  12073. * _.gt(3, 3);
  12074. * // => false
  12075. *
  12076. * _.gt(1, 3);
  12077. * // => false
  12078. */
  12079. var gt = createRelationalOperation(baseGt);
  12080. /**
  12081. * Checks if `value` is greater than or equal to `other`.
  12082. *
  12083. * @static
  12084. * @memberOf _
  12085. * @since 3.9.0
  12086. * @category Lang
  12087. * @param {*} value The value to compare.
  12088. * @param {*} other The other value to compare.
  12089. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  12090. * `other`, else `false`.
  12091. * @see _.lte
  12092. * @example
  12093. *
  12094. * _.gte(3, 1);
  12095. * // => true
  12096. *
  12097. * _.gte(3, 3);
  12098. * // => true
  12099. *
  12100. * _.gte(1, 3);
  12101. * // => false
  12102. */
  12103. var gte = createRelationalOperation(function(value, other) {
  12104. return value >= other;
  12105. });
  12106. /**
  12107. * Checks if `value` is likely an `arguments` object.
  12108. *
  12109. * @static
  12110. * @memberOf _
  12111. * @since 0.1.0
  12112. * @category Lang
  12113. * @param {*} value The value to check.
  12114. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  12115. * else `false`.
  12116. * @example
  12117. *
  12118. * _.isArguments(function() { return arguments; }());
  12119. * // => true
  12120. *
  12121. * _.isArguments([1, 2, 3]);
  12122. * // => false
  12123. */
  12124. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  12125. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  12126. !propertyIsEnumerable.call(value, 'callee');
  12127. };
  12128. /**
  12129. * Checks if `value` is classified as an `Array` object.
  12130. *
  12131. * @static
  12132. * @memberOf _
  12133. * @since 0.1.0
  12134. * @category Lang
  12135. * @param {*} value The value to check.
  12136. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  12137. * @example
  12138. *
  12139. * _.isArray([1, 2, 3]);
  12140. * // => true
  12141. *
  12142. * _.isArray(document.body.children);
  12143. * // => false
  12144. *
  12145. * _.isArray('abc');
  12146. * // => false
  12147. *
  12148. * _.isArray(_.noop);
  12149. * // => false
  12150. */
  12151. var isArray = Array.isArray;
  12152. /**
  12153. * Checks if `value` is classified as an `ArrayBuffer` object.
  12154. *
  12155. * @static
  12156. * @memberOf _
  12157. * @since 4.3.0
  12158. * @category Lang
  12159. * @param {*} value The value to check.
  12160. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  12161. * @example
  12162. *
  12163. * _.isArrayBuffer(new ArrayBuffer(2));
  12164. * // => true
  12165. *
  12166. * _.isArrayBuffer(new Array(2));
  12167. * // => false
  12168. */
  12169. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  12170. /**
  12171. * Checks if `value` is array-like. A value is considered array-like if it's
  12172. * not a function and has a `value.length` that's an integer greater than or
  12173. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  12174. *
  12175. * @static
  12176. * @memberOf _
  12177. * @since 4.0.0
  12178. * @category Lang
  12179. * @param {*} value The value to check.
  12180. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  12181. * @example
  12182. *
  12183. * _.isArrayLike([1, 2, 3]);
  12184. * // => true
  12185. *
  12186. * _.isArrayLike(document.body.children);
  12187. * // => true
  12188. *
  12189. * _.isArrayLike('abc');
  12190. * // => true
  12191. *
  12192. * _.isArrayLike(_.noop);
  12193. * // => false
  12194. */
  12195. function isArrayLike(value) {
  12196. return value != null && isLength(value.length) && !isFunction(value);
  12197. }
  12198. /**
  12199. * This method is like `_.isArrayLike` except that it also checks if `value`
  12200. * is an object.
  12201. *
  12202. * @static
  12203. * @memberOf _
  12204. * @since 4.0.0
  12205. * @category Lang
  12206. * @param {*} value The value to check.
  12207. * @returns {boolean} Returns `true` if `value` is an array-like object,
  12208. * else `false`.
  12209. * @example
  12210. *
  12211. * _.isArrayLikeObject([1, 2, 3]);
  12212. * // => true
  12213. *
  12214. * _.isArrayLikeObject(document.body.children);
  12215. * // => true
  12216. *
  12217. * _.isArrayLikeObject('abc');
  12218. * // => false
  12219. *
  12220. * _.isArrayLikeObject(_.noop);
  12221. * // => false
  12222. */
  12223. function isArrayLikeObject(value) {
  12224. return isObjectLike(value) && isArrayLike(value);
  12225. }
  12226. /**
  12227. * Checks if `value` is classified as a boolean primitive or object.
  12228. *
  12229. * @static
  12230. * @memberOf _
  12231. * @since 0.1.0
  12232. * @category Lang
  12233. * @param {*} value The value to check.
  12234. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  12235. * @example
  12236. *
  12237. * _.isBoolean(false);
  12238. * // => true
  12239. *
  12240. * _.isBoolean(null);
  12241. * // => false
  12242. */
  12243. function isBoolean(value) {
  12244. return value === true || value === false ||
  12245. (isObjectLike(value) && baseGetTag(value) == boolTag);
  12246. }
  12247. /**
  12248. * Checks if `value` is a buffer.
  12249. *
  12250. * @static
  12251. * @memberOf _
  12252. * @since 4.3.0
  12253. * @category Lang
  12254. * @param {*} value The value to check.
  12255. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  12256. * @example
  12257. *
  12258. * _.isBuffer(new Buffer(2));
  12259. * // => true
  12260. *
  12261. * _.isBuffer(new Uint8Array(2));
  12262. * // => false
  12263. */
  12264. var isBuffer = nativeIsBuffer || stubFalse;
  12265. /**
  12266. * Checks if `value` is classified as a `Date` object.
  12267. *
  12268. * @static
  12269. * @memberOf _
  12270. * @since 0.1.0
  12271. * @category Lang
  12272. * @param {*} value The value to check.
  12273. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  12274. * @example
  12275. *
  12276. * _.isDate(new Date);
  12277. * // => true
  12278. *
  12279. * _.isDate('Mon April 23 2012');
  12280. * // => false
  12281. */
  12282. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  12283. /**
  12284. * Checks if `value` is likely a DOM element.
  12285. *
  12286. * @static
  12287. * @memberOf _
  12288. * @since 0.1.0
  12289. * @category Lang
  12290. * @param {*} value The value to check.
  12291. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  12292. * @example
  12293. *
  12294. * _.isElement(document.body);
  12295. * // => true
  12296. *
  12297. * _.isElement('<body>');
  12298. * // => false
  12299. */
  12300. function isElement(value) {
  12301. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  12302. }
  12303. /**
  12304. * Checks if `value` is an empty object, collection, map, or set.
  12305. *
  12306. * Objects are considered empty if they have no own enumerable string keyed
  12307. * properties.
  12308. *
  12309. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  12310. * jQuery-like collections are considered empty if they have a `length` of `0`.
  12311. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  12312. *
  12313. * @static
  12314. * @memberOf _
  12315. * @since 0.1.0
  12316. * @category Lang
  12317. * @param {*} value The value to check.
  12318. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  12319. * @example
  12320. *
  12321. * _.isEmpty(null);
  12322. * // => true
  12323. *
  12324. * _.isEmpty(true);
  12325. * // => true
  12326. *
  12327. * _.isEmpty(1);
  12328. * // => true
  12329. *
  12330. * _.isEmpty([1, 2, 3]);
  12331. * // => false
  12332. *
  12333. * _.isEmpty({ 'a': 1 });
  12334. * // => false
  12335. */
  12336. function isEmpty(value) {
  12337. if (value == null) {
  12338. return true;
  12339. }
  12340. if (isArrayLike(value) &&
  12341. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  12342. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  12343. return !value.length;
  12344. }
  12345. var tag = getTag(value);
  12346. if (tag == mapTag || tag == setTag) {
  12347. return !value.size;
  12348. }
  12349. if (isPrototype(value)) {
  12350. return !baseKeys(value).length;
  12351. }
  12352. for (var key in value) {
  12353. if (hasOwnProperty.call(value, key)) {
  12354. return false;
  12355. }
  12356. }
  12357. return true;
  12358. }
  12359. /**
  12360. * Performs a deep comparison between two values to determine if they are
  12361. * equivalent.
  12362. *
  12363. * **Note:** This method supports comparing arrays, array buffers, booleans,
  12364. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  12365. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  12366. * by their own, not inherited, enumerable properties. Functions and DOM
  12367. * nodes are compared by strict equality, i.e. `===`.
  12368. *
  12369. * @static
  12370. * @memberOf _
  12371. * @since 0.1.0
  12372. * @category Lang
  12373. * @param {*} value The value to compare.
  12374. * @param {*} other The other value to compare.
  12375. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  12376. * @example
  12377. *
  12378. * var object = { 'a': 1 };
  12379. * var other = { 'a': 1 };
  12380. *
  12381. * _.isEqual(object, other);
  12382. * // => true
  12383. *
  12384. * object === other;
  12385. * // => false
  12386. */
  12387. function isEqual(value, other) {
  12388. return baseIsEqual(value, other);
  12389. }
  12390. /**
  12391. * This method is like `_.isEqual` except that it accepts `customizer` which
  12392. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  12393. * are handled by the method instead. The `customizer` is invoked with up to
  12394. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  12395. *
  12396. * @static
  12397. * @memberOf _
  12398. * @since 4.0.0
  12399. * @category Lang
  12400. * @param {*} value The value to compare.
  12401. * @param {*} other The other value to compare.
  12402. * @param {Function} [customizer] The function to customize comparisons.
  12403. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  12404. * @example
  12405. *
  12406. * function isGreeting(value) {
  12407. * return /^h(?:i|ello)$/.test(value);
  12408. * }
  12409. *
  12410. * function customizer(objValue, othValue) {
  12411. * if (isGreeting(objValue) && isGreeting(othValue)) {
  12412. * return true;
  12413. * }
  12414. * }
  12415. *
  12416. * var array = ['hello', 'goodbye'];
  12417. * var other = ['hi', 'goodbye'];
  12418. *
  12419. * _.isEqualWith(array, other, customizer);
  12420. * // => true
  12421. */
  12422. function isEqualWith(value, other, customizer) {
  12423. customizer = typeof customizer == 'function' ? customizer : undefined;
  12424. var result = customizer ? customizer(value, other) : undefined;
  12425. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  12426. }
  12427. /**
  12428. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  12429. * `SyntaxError`, `TypeError`, or `URIError` object.
  12430. *
  12431. * @static
  12432. * @memberOf _
  12433. * @since 3.0.0
  12434. * @category Lang
  12435. * @param {*} value The value to check.
  12436. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  12437. * @example
  12438. *
  12439. * _.isError(new Error);
  12440. * // => true
  12441. *
  12442. * _.isError(Error);
  12443. * // => false
  12444. */
  12445. function isError(value) {
  12446. if (!isObjectLike(value)) {
  12447. return false;
  12448. }
  12449. var tag = baseGetTag(value);
  12450. return tag == errorTag || tag == domExcTag ||
  12451. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  12452. }
  12453. /**
  12454. * Checks if `value` is a finite primitive number.
  12455. *
  12456. * **Note:** This method is based on
  12457. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  12458. *
  12459. * @static
  12460. * @memberOf _
  12461. * @since 0.1.0
  12462. * @category Lang
  12463. * @param {*} value The value to check.
  12464. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  12465. * @example
  12466. *
  12467. * _.isFinite(3);
  12468. * // => true
  12469. *
  12470. * _.isFinite(Number.MIN_VALUE);
  12471. * // => true
  12472. *
  12473. * _.isFinite(Infinity);
  12474. * // => false
  12475. *
  12476. * _.isFinite('3');
  12477. * // => false
  12478. */
  12479. function isFinite(value) {
  12480. return typeof value == 'number' && nativeIsFinite(value);
  12481. }
  12482. /**
  12483. * Checks if `value` is classified as a `Function` object.
  12484. *
  12485. * @static
  12486. * @memberOf _
  12487. * @since 0.1.0
  12488. * @category Lang
  12489. * @param {*} value The value to check.
  12490. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  12491. * @example
  12492. *
  12493. * _.isFunction(_);
  12494. * // => true
  12495. *
  12496. * _.isFunction(/abc/);
  12497. * // => false
  12498. */
  12499. function isFunction(value) {
  12500. if (!isObject(value)) {
  12501. return false;
  12502. }
  12503. // The use of `Object#toString` avoids issues with the `typeof` operator
  12504. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  12505. var tag = baseGetTag(value);
  12506. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  12507. }
  12508. /**
  12509. * Checks if `value` is an integer.
  12510. *
  12511. * **Note:** This method is based on
  12512. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  12513. *
  12514. * @static
  12515. * @memberOf _
  12516. * @since 4.0.0
  12517. * @category Lang
  12518. * @param {*} value The value to check.
  12519. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  12520. * @example
  12521. *
  12522. * _.isInteger(3);
  12523. * // => true
  12524. *
  12525. * _.isInteger(Number.MIN_VALUE);
  12526. * // => false
  12527. *
  12528. * _.isInteger(Infinity);
  12529. * // => false
  12530. *
  12531. * _.isInteger('3');
  12532. * // => false
  12533. */
  12534. function isInteger(value) {
  12535. return typeof value == 'number' && value == toInteger(value);
  12536. }
  12537. /**
  12538. * Checks if `value` is a valid array-like length.
  12539. *
  12540. * **Note:** This method is loosely based on
  12541. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  12542. *
  12543. * @static
  12544. * @memberOf _
  12545. * @since 4.0.0
  12546. * @category Lang
  12547. * @param {*} value The value to check.
  12548. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  12549. * @example
  12550. *
  12551. * _.isLength(3);
  12552. * // => true
  12553. *
  12554. * _.isLength(Number.MIN_VALUE);
  12555. * // => false
  12556. *
  12557. * _.isLength(Infinity);
  12558. * // => false
  12559. *
  12560. * _.isLength('3');
  12561. * // => false
  12562. */
  12563. function isLength(value) {
  12564. return typeof value == 'number' &&
  12565. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  12566. }
  12567. /**
  12568. * Checks if `value` is the
  12569. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  12570. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  12571. *
  12572. * @static
  12573. * @memberOf _
  12574. * @since 0.1.0
  12575. * @category Lang
  12576. * @param {*} value The value to check.
  12577. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  12578. * @example
  12579. *
  12580. * _.isObject({});
  12581. * // => true
  12582. *
  12583. * _.isObject([1, 2, 3]);
  12584. * // => true
  12585. *
  12586. * _.isObject(_.noop);
  12587. * // => true
  12588. *
  12589. * _.isObject(null);
  12590. * // => false
  12591. */
  12592. function isObject(value) {
  12593. var type = typeof value;
  12594. return value != null && (type == 'object' || type == 'function');
  12595. }
  12596. /**
  12597. * Checks if `value` is object-like. A value is object-like if it's not `null`
  12598. * and has a `typeof` result of "object".
  12599. *
  12600. * @static
  12601. * @memberOf _
  12602. * @since 4.0.0
  12603. * @category Lang
  12604. * @param {*} value The value to check.
  12605. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  12606. * @example
  12607. *
  12608. * _.isObjectLike({});
  12609. * // => true
  12610. *
  12611. * _.isObjectLike([1, 2, 3]);
  12612. * // => true
  12613. *
  12614. * _.isObjectLike(_.noop);
  12615. * // => false
  12616. *
  12617. * _.isObjectLike(null);
  12618. * // => false
  12619. */
  12620. function isObjectLike(value) {
  12621. return value != null && typeof value == 'object';
  12622. }
  12623. /**
  12624. * Checks if `value` is classified as a `Map` object.
  12625. *
  12626. * @static
  12627. * @memberOf _
  12628. * @since 4.3.0
  12629. * @category Lang
  12630. * @param {*} value The value to check.
  12631. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  12632. * @example
  12633. *
  12634. * _.isMap(new Map);
  12635. * // => true
  12636. *
  12637. * _.isMap(new WeakMap);
  12638. * // => false
  12639. */
  12640. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  12641. /**
  12642. * Performs a partial deep comparison between `object` and `source` to
  12643. * determine if `object` contains equivalent property values.
  12644. *
  12645. * **Note:** This method is equivalent to `_.matches` when `source` is
  12646. * partially applied.
  12647. *
  12648. * Partial comparisons will match empty array and empty object `source`
  12649. * values against any array or object value, respectively. See `_.isEqual`
  12650. * for a list of supported value comparisons.
  12651. *
  12652. * @static
  12653. * @memberOf _
  12654. * @since 3.0.0
  12655. * @category Lang
  12656. * @param {Object} object The object to inspect.
  12657. * @param {Object} source The object of property values to match.
  12658. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  12659. * @example
  12660. *
  12661. * var object = { 'a': 1, 'b': 2 };
  12662. *
  12663. * _.isMatch(object, { 'b': 2 });
  12664. * // => true
  12665. *
  12666. * _.isMatch(object, { 'b': 1 });
  12667. * // => false
  12668. */
  12669. function isMatch(object, source) {
  12670. return object === source || baseIsMatch(object, source, getMatchData(source));
  12671. }
  12672. /**
  12673. * This method is like `_.isMatch` except that it accepts `customizer` which
  12674. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  12675. * are handled by the method instead. The `customizer` is invoked with five
  12676. * arguments: (objValue, srcValue, index|key, object, source).
  12677. *
  12678. * @static
  12679. * @memberOf _
  12680. * @since 4.0.0
  12681. * @category Lang
  12682. * @param {Object} object The object to inspect.
  12683. * @param {Object} source The object of property values to match.
  12684. * @param {Function} [customizer] The function to customize comparisons.
  12685. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  12686. * @example
  12687. *
  12688. * function isGreeting(value) {
  12689. * return /^h(?:i|ello)$/.test(value);
  12690. * }
  12691. *
  12692. * function customizer(objValue, srcValue) {
  12693. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  12694. * return true;
  12695. * }
  12696. * }
  12697. *
  12698. * var object = { 'greeting': 'hello' };
  12699. * var source = { 'greeting': 'hi' };
  12700. *
  12701. * _.isMatchWith(object, source, customizer);
  12702. * // => true
  12703. */
  12704. function isMatchWith(object, source, customizer) {
  12705. customizer = typeof customizer == 'function' ? customizer : undefined;
  12706. return baseIsMatch(object, source, getMatchData(source), customizer);
  12707. }
  12708. /**
  12709. * Checks if `value` is `NaN`.
  12710. *
  12711. * **Note:** This method is based on
  12712. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  12713. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  12714. * `undefined` and other non-number values.
  12715. *
  12716. * @static
  12717. * @memberOf _
  12718. * @since 0.1.0
  12719. * @category Lang
  12720. * @param {*} value The value to check.
  12721. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  12722. * @example
  12723. *
  12724. * _.isNaN(NaN);
  12725. * // => true
  12726. *
  12727. * _.isNaN(new Number(NaN));
  12728. * // => true
  12729. *
  12730. * isNaN(undefined);
  12731. * // => true
  12732. *
  12733. * _.isNaN(undefined);
  12734. * // => false
  12735. */
  12736. function isNaN(value) {
  12737. // An `NaN` primitive is the only value that is not equal to itself.
  12738. // Perform the `toStringTag` check first to avoid errors with some
  12739. // ActiveX objects in IE.
  12740. return isNumber(value) && value != +value;
  12741. }
  12742. /**
  12743. * Checks if `value` is a pristine native function.
  12744. *
  12745. * **Note:** This method can't reliably detect native functions in the presence
  12746. * of the core-js package because core-js circumvents this kind of detection.
  12747. * Despite multiple requests, the core-js maintainer has made it clear: any
  12748. * attempt to fix the detection will be obstructed. As a result, we're left
  12749. * with little choice but to throw an error. Unfortunately, this also affects
  12750. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  12751. * which rely on core-js.
  12752. *
  12753. * @static
  12754. * @memberOf _
  12755. * @since 3.0.0
  12756. * @category Lang
  12757. * @param {*} value The value to check.
  12758. * @returns {boolean} Returns `true` if `value` is a native function,
  12759. * else `false`.
  12760. * @example
  12761. *
  12762. * _.isNative(Array.prototype.push);
  12763. * // => true
  12764. *
  12765. * _.isNative(_);
  12766. * // => false
  12767. */
  12768. function isNative(value) {
  12769. if (isMaskable(value)) {
  12770. throw new Error(CORE_ERROR_TEXT);
  12771. }
  12772. return baseIsNative(value);
  12773. }
  12774. /**
  12775. * Checks if `value` is `null`.
  12776. *
  12777. * @static
  12778. * @memberOf _
  12779. * @since 0.1.0
  12780. * @category Lang
  12781. * @param {*} value The value to check.
  12782. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  12783. * @example
  12784. *
  12785. * _.isNull(null);
  12786. * // => true
  12787. *
  12788. * _.isNull(void 0);
  12789. * // => false
  12790. */
  12791. function isNull(value) {
  12792. return value === null;
  12793. }
  12794. /**
  12795. * Checks if `value` is `null` or `undefined`.
  12796. *
  12797. * @static
  12798. * @memberOf _
  12799. * @since 4.0.0
  12800. * @category Lang
  12801. * @param {*} value The value to check.
  12802. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  12803. * @example
  12804. *
  12805. * _.isNil(null);
  12806. * // => true
  12807. *
  12808. * _.isNil(void 0);
  12809. * // => true
  12810. *
  12811. * _.isNil(NaN);
  12812. * // => false
  12813. */
  12814. function isNil(value) {
  12815. return value == null;
  12816. }
  12817. /**
  12818. * Checks if `value` is classified as a `Number` primitive or object.
  12819. *
  12820. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  12821. * classified as numbers, use the `_.isFinite` method.
  12822. *
  12823. * @static
  12824. * @memberOf _
  12825. * @since 0.1.0
  12826. * @category Lang
  12827. * @param {*} value The value to check.
  12828. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  12829. * @example
  12830. *
  12831. * _.isNumber(3);
  12832. * // => true
  12833. *
  12834. * _.isNumber(Number.MIN_VALUE);
  12835. * // => true
  12836. *
  12837. * _.isNumber(Infinity);
  12838. * // => true
  12839. *
  12840. * _.isNumber('3');
  12841. * // => false
  12842. */
  12843. function isNumber(value) {
  12844. return typeof value == 'number' ||
  12845. (isObjectLike(value) && baseGetTag(value) == numberTag);
  12846. }
  12847. /**
  12848. * Checks if `value` is a plain object, that is, an object created by the
  12849. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  12850. *
  12851. * @static
  12852. * @memberOf _
  12853. * @since 0.8.0
  12854. * @category Lang
  12855. * @param {*} value The value to check.
  12856. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  12857. * @example
  12858. *
  12859. * function Foo() {
  12860. * this.a = 1;
  12861. * }
  12862. *
  12863. * _.isPlainObject(new Foo);
  12864. * // => false
  12865. *
  12866. * _.isPlainObject([1, 2, 3]);
  12867. * // => false
  12868. *
  12869. * _.isPlainObject({ 'x': 0, 'y': 0 });
  12870. * // => true
  12871. *
  12872. * _.isPlainObject(Object.create(null));
  12873. * // => true
  12874. */
  12875. function isPlainObject(value) {
  12876. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  12877. return false;
  12878. }
  12879. var proto = getPrototype(value);
  12880. if (proto === null) {
  12881. return true;
  12882. }
  12883. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  12884. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  12885. funcToString.call(Ctor) == objectCtorString;
  12886. }
  12887. /**
  12888. * Checks if `value` is classified as a `RegExp` object.
  12889. *
  12890. * @static
  12891. * @memberOf _
  12892. * @since 0.1.0
  12893. * @category Lang
  12894. * @param {*} value The value to check.
  12895. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  12896. * @example
  12897. *
  12898. * _.isRegExp(/abc/);
  12899. * // => true
  12900. *
  12901. * _.isRegExp('/abc/');
  12902. * // => false
  12903. */
  12904. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  12905. /**
  12906. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  12907. * double precision number which isn't the result of a rounded unsafe integer.
  12908. *
  12909. * **Note:** This method is based on
  12910. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  12911. *
  12912. * @static
  12913. * @memberOf _
  12914. * @since 4.0.0
  12915. * @category Lang
  12916. * @param {*} value The value to check.
  12917. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  12918. * @example
  12919. *
  12920. * _.isSafeInteger(3);
  12921. * // => true
  12922. *
  12923. * _.isSafeInteger(Number.MIN_VALUE);
  12924. * // => false
  12925. *
  12926. * _.isSafeInteger(Infinity);
  12927. * // => false
  12928. *
  12929. * _.isSafeInteger('3');
  12930. * // => false
  12931. */
  12932. function isSafeInteger(value) {
  12933. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  12934. }
  12935. /**
  12936. * Checks if `value` is classified as a `Set` object.
  12937. *
  12938. * @static
  12939. * @memberOf _
  12940. * @since 4.3.0
  12941. * @category Lang
  12942. * @param {*} value The value to check.
  12943. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  12944. * @example
  12945. *
  12946. * _.isSet(new Set);
  12947. * // => true
  12948. *
  12949. * _.isSet(new WeakSet);
  12950. * // => false
  12951. */
  12952. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  12953. /**
  12954. * Checks if `value` is classified as a `String` primitive or object.
  12955. *
  12956. * @static
  12957. * @since 0.1.0
  12958. * @memberOf _
  12959. * @category Lang
  12960. * @param {*} value The value to check.
  12961. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  12962. * @example
  12963. *
  12964. * _.isString('abc');
  12965. * // => true
  12966. *
  12967. * _.isString(1);
  12968. * // => false
  12969. */
  12970. function isString(value) {
  12971. return typeof value == 'string' ||
  12972. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  12973. }
  12974. /**
  12975. * Checks if `value` is classified as a `Symbol` primitive or object.
  12976. *
  12977. * @static
  12978. * @memberOf _
  12979. * @since 4.0.0
  12980. * @category Lang
  12981. * @param {*} value The value to check.
  12982. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  12983. * @example
  12984. *
  12985. * _.isSymbol(Symbol.iterator);
  12986. * // => true
  12987. *
  12988. * _.isSymbol('abc');
  12989. * // => false
  12990. */
  12991. function isSymbol(value) {
  12992. return typeof value == 'symbol' ||
  12993. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  12994. }
  12995. /**
  12996. * Checks if `value` is classified as a typed array.
  12997. *
  12998. * @static
  12999. * @memberOf _
  13000. * @since 3.0.0
  13001. * @category Lang
  13002. * @param {*} value The value to check.
  13003. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  13004. * @example
  13005. *
  13006. * _.isTypedArray(new Uint8Array);
  13007. * // => true
  13008. *
  13009. * _.isTypedArray([]);
  13010. * // => false
  13011. */
  13012. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  13013. /**
  13014. * Checks if `value` is `undefined`.
  13015. *
  13016. * @static
  13017. * @since 0.1.0
  13018. * @memberOf _
  13019. * @category Lang
  13020. * @param {*} value The value to check.
  13021. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  13022. * @example
  13023. *
  13024. * _.isUndefined(void 0);
  13025. * // => true
  13026. *
  13027. * _.isUndefined(null);
  13028. * // => false
  13029. */
  13030. function isUndefined(value) {
  13031. return value === undefined;
  13032. }
  13033. /**
  13034. * Checks if `value` is classified as a `WeakMap` object.
  13035. *
  13036. * @static
  13037. * @memberOf _
  13038. * @since 4.3.0
  13039. * @category Lang
  13040. * @param {*} value The value to check.
  13041. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  13042. * @example
  13043. *
  13044. * _.isWeakMap(new WeakMap);
  13045. * // => true
  13046. *
  13047. * _.isWeakMap(new Map);
  13048. * // => false
  13049. */
  13050. function isWeakMap(value) {
  13051. return isObjectLike(value) && getTag(value) == weakMapTag;
  13052. }
  13053. /**
  13054. * Checks if `value` is classified as a `WeakSet` object.
  13055. *
  13056. * @static
  13057. * @memberOf _
  13058. * @since 4.3.0
  13059. * @category Lang
  13060. * @param {*} value The value to check.
  13061. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  13062. * @example
  13063. *
  13064. * _.isWeakSet(new WeakSet);
  13065. * // => true
  13066. *
  13067. * _.isWeakSet(new Set);
  13068. * // => false
  13069. */
  13070. function isWeakSet(value) {
  13071. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  13072. }
  13073. /**
  13074. * Checks if `value` is less than `other`.
  13075. *
  13076. * @static
  13077. * @memberOf _
  13078. * @since 3.9.0
  13079. * @category Lang
  13080. * @param {*} value The value to compare.
  13081. * @param {*} other The other value to compare.
  13082. * @returns {boolean} Returns `true` if `value` is less than `other`,
  13083. * else `false`.
  13084. * @see _.gt
  13085. * @example
  13086. *
  13087. * _.lt(1, 3);
  13088. * // => true
  13089. *
  13090. * _.lt(3, 3);
  13091. * // => false
  13092. *
  13093. * _.lt(3, 1);
  13094. * // => false
  13095. */
  13096. var lt = createRelationalOperation(baseLt);
  13097. /**
  13098. * Checks if `value` is less than or equal to `other`.
  13099. *
  13100. * @static
  13101. * @memberOf _
  13102. * @since 3.9.0
  13103. * @category Lang
  13104. * @param {*} value The value to compare.
  13105. * @param {*} other The other value to compare.
  13106. * @returns {boolean} Returns `true` if `value` is less than or equal to
  13107. * `other`, else `false`.
  13108. * @see _.gte
  13109. * @example
  13110. *
  13111. * _.lte(1, 3);
  13112. * // => true
  13113. *
  13114. * _.lte(3, 3);
  13115. * // => true
  13116. *
  13117. * _.lte(3, 1);
  13118. * // => false
  13119. */
  13120. var lte = createRelationalOperation(function(value, other) {
  13121. return value <= other;
  13122. });
  13123. /**
  13124. * Converts `value` to an array.
  13125. *
  13126. * @static
  13127. * @since 0.1.0
  13128. * @memberOf _
  13129. * @category Lang
  13130. * @param {*} value The value to convert.
  13131. * @returns {Array} Returns the converted array.
  13132. * @example
  13133. *
  13134. * _.toArray({ 'a': 1, 'b': 2 });
  13135. * // => [1, 2]
  13136. *
  13137. * _.toArray('abc');
  13138. * // => ['a', 'b', 'c']
  13139. *
  13140. * _.toArray(1);
  13141. * // => []
  13142. *
  13143. * _.toArray(null);
  13144. * // => []
  13145. */
  13146. function toArray(value) {
  13147. if (!value) {
  13148. return [];
  13149. }
  13150. if (isArrayLike(value)) {
  13151. return isString(value) ? stringToArray(value) : copyArray(value);
  13152. }
  13153. if (symIterator && value[symIterator]) {
  13154. return iteratorToArray(value[symIterator]());
  13155. }
  13156. var tag = getTag(value),
  13157. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  13158. return func(value);
  13159. }
  13160. /**
  13161. * Converts `value` to a finite number.
  13162. *
  13163. * @static
  13164. * @memberOf _
  13165. * @since 4.12.0
  13166. * @category Lang
  13167. * @param {*} value The value to convert.
  13168. * @returns {number} Returns the converted number.
  13169. * @example
  13170. *
  13171. * _.toFinite(3.2);
  13172. * // => 3.2
  13173. *
  13174. * _.toFinite(Number.MIN_VALUE);
  13175. * // => 5e-324
  13176. *
  13177. * _.toFinite(Infinity);
  13178. * // => 1.7976931348623157e+308
  13179. *
  13180. * _.toFinite('3.2');
  13181. * // => 3.2
  13182. */
  13183. function toFinite(value) {
  13184. if (!value) {
  13185. return value === 0 ? value : 0;
  13186. }
  13187. value = toNumber(value);
  13188. if (value === INFINITY || value === -INFINITY) {
  13189. var sign = (value < 0 ? -1 : 1);
  13190. return sign * MAX_INTEGER;
  13191. }
  13192. return value === value ? value : 0;
  13193. }
  13194. /**
  13195. * Converts `value` to an integer.
  13196. *
  13197. * **Note:** This method is loosely based on
  13198. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  13199. *
  13200. * @static
  13201. * @memberOf _
  13202. * @since 4.0.0
  13203. * @category Lang
  13204. * @param {*} value The value to convert.
  13205. * @returns {number} Returns the converted integer.
  13206. * @example
  13207. *
  13208. * _.toInteger(3.2);
  13209. * // => 3
  13210. *
  13211. * _.toInteger(Number.MIN_VALUE);
  13212. * // => 0
  13213. *
  13214. * _.toInteger(Infinity);
  13215. * // => 1.7976931348623157e+308
  13216. *
  13217. * _.toInteger('3.2');
  13218. * // => 3
  13219. */
  13220. function toInteger(value) {
  13221. var result = toFinite(value),
  13222. remainder = result % 1;
  13223. return result === result ? (remainder ? result - remainder : result) : 0;
  13224. }
  13225. /**
  13226. * Converts `value` to an integer suitable for use as the length of an
  13227. * array-like object.
  13228. *
  13229. * **Note:** This method is based on
  13230. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  13231. *
  13232. * @static
  13233. * @memberOf _
  13234. * @since 4.0.0
  13235. * @category Lang
  13236. * @param {*} value The value to convert.
  13237. * @returns {number} Returns the converted integer.
  13238. * @example
  13239. *
  13240. * _.toLength(3.2);
  13241. * // => 3
  13242. *
  13243. * _.toLength(Number.MIN_VALUE);
  13244. * // => 0
  13245. *
  13246. * _.toLength(Infinity);
  13247. * // => 4294967295
  13248. *
  13249. * _.toLength('3.2');
  13250. * // => 3
  13251. */
  13252. function toLength(value) {
  13253. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  13254. }
  13255. /**
  13256. * Converts `value` to a number.
  13257. *
  13258. * @static
  13259. * @memberOf _
  13260. * @since 4.0.0
  13261. * @category Lang
  13262. * @param {*} value The value to process.
  13263. * @returns {number} Returns the number.
  13264. * @example
  13265. *
  13266. * _.toNumber(3.2);
  13267. * // => 3.2
  13268. *
  13269. * _.toNumber(Number.MIN_VALUE);
  13270. * // => 5e-324
  13271. *
  13272. * _.toNumber(Infinity);
  13273. * // => Infinity
  13274. *
  13275. * _.toNumber('3.2');
  13276. * // => 3.2
  13277. */
  13278. function toNumber(value) {
  13279. if (typeof value == 'number') {
  13280. return value;
  13281. }
  13282. if (isSymbol(value)) {
  13283. return NAN;
  13284. }
  13285. if (isObject(value)) {
  13286. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  13287. value = isObject(other) ? (other + '') : other;
  13288. }
  13289. if (typeof value != 'string') {
  13290. return value === 0 ? value : +value;
  13291. }
  13292. value = baseTrim(value);
  13293. var isBinary = reIsBinary.test(value);
  13294. return (isBinary || reIsOctal.test(value))
  13295. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  13296. : (reIsBadHex.test(value) ? NAN : +value);
  13297. }
  13298. /**
  13299. * Converts `value` to a plain object flattening inherited enumerable string
  13300. * keyed properties of `value` to own properties of the plain object.
  13301. *
  13302. * @static
  13303. * @memberOf _
  13304. * @since 3.0.0
  13305. * @category Lang
  13306. * @param {*} value The value to convert.
  13307. * @returns {Object} Returns the converted plain object.
  13308. * @example
  13309. *
  13310. * function Foo() {
  13311. * this.b = 2;
  13312. * }
  13313. *
  13314. * Foo.prototype.c = 3;
  13315. *
  13316. * _.assign({ 'a': 1 }, new Foo);
  13317. * // => { 'a': 1, 'b': 2 }
  13318. *
  13319. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  13320. * // => { 'a': 1, 'b': 2, 'c': 3 }
  13321. */
  13322. function toPlainObject(value) {
  13323. return copyObject(value, keysIn(value));
  13324. }
  13325. /**
  13326. * Converts `value` to a safe integer. A safe integer can be compared and
  13327. * represented correctly.
  13328. *
  13329. * @static
  13330. * @memberOf _
  13331. * @since 4.0.0
  13332. * @category Lang
  13333. * @param {*} value The value to convert.
  13334. * @returns {number} Returns the converted integer.
  13335. * @example
  13336. *
  13337. * _.toSafeInteger(3.2);
  13338. * // => 3
  13339. *
  13340. * _.toSafeInteger(Number.MIN_VALUE);
  13341. * // => 0
  13342. *
  13343. * _.toSafeInteger(Infinity);
  13344. * // => 9007199254740991
  13345. *
  13346. * _.toSafeInteger('3.2');
  13347. * // => 3
  13348. */
  13349. function toSafeInteger(value) {
  13350. return value
  13351. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  13352. : (value === 0 ? value : 0);
  13353. }
  13354. /**
  13355. * Converts `value` to a string. An empty string is returned for `null`
  13356. * and `undefined` values. The sign of `-0` is preserved.
  13357. *
  13358. * @static
  13359. * @memberOf _
  13360. * @since 4.0.0
  13361. * @category Lang
  13362. * @param {*} value The value to convert.
  13363. * @returns {string} Returns the converted string.
  13364. * @example
  13365. *
  13366. * _.toString(null);
  13367. * // => ''
  13368. *
  13369. * _.toString(-0);
  13370. * // => '-0'
  13371. *
  13372. * _.toString([1, 2, 3]);
  13373. * // => '1,2,3'
  13374. */
  13375. function toString(value) {
  13376. return value == null ? '' : baseToString(value);
  13377. }
  13378. /*------------------------------------------------------------------------*/
  13379. /**
  13380. * Assigns own enumerable string keyed properties of source objects to the
  13381. * destination object. Source objects are applied from left to right.
  13382. * Subsequent sources overwrite property assignments of previous sources.
  13383. *
  13384. * **Note:** This method mutates `object` and is loosely based on
  13385. * [`Object.assign`](https://mdn.io/Object/assign).
  13386. *
  13387. * @static
  13388. * @memberOf _
  13389. * @since 0.10.0
  13390. * @category Object
  13391. * @param {Object} object The destination object.
  13392. * @param {...Object} [sources] The source objects.
  13393. * @returns {Object} Returns `object`.
  13394. * @see _.assignIn
  13395. * @example
  13396. *
  13397. * function Foo() {
  13398. * this.a = 1;
  13399. * }
  13400. *
  13401. * function Bar() {
  13402. * this.c = 3;
  13403. * }
  13404. *
  13405. * Foo.prototype.b = 2;
  13406. * Bar.prototype.d = 4;
  13407. *
  13408. * _.assign({ 'a': 0 }, new Foo, new Bar);
  13409. * // => { 'a': 1, 'c': 3 }
  13410. */
  13411. var assign = createAssigner(function(object, source) {
  13412. if (isPrototype(source) || isArrayLike(source)) {
  13413. copyObject(source, keys(source), object);
  13414. return;
  13415. }
  13416. for (var key in source) {
  13417. if (hasOwnProperty.call(source, key)) {
  13418. assignValue(object, key, source[key]);
  13419. }
  13420. }
  13421. });
  13422. /**
  13423. * This method is like `_.assign` except that it iterates over own and
  13424. * inherited source properties.
  13425. *
  13426. * **Note:** This method mutates `object`.
  13427. *
  13428. * @static
  13429. * @memberOf _
  13430. * @since 4.0.0
  13431. * @alias extend
  13432. * @category Object
  13433. * @param {Object} object The destination object.
  13434. * @param {...Object} [sources] The source objects.
  13435. * @returns {Object} Returns `object`.
  13436. * @see _.assign
  13437. * @example
  13438. *
  13439. * function Foo() {
  13440. * this.a = 1;
  13441. * }
  13442. *
  13443. * function Bar() {
  13444. * this.c = 3;
  13445. * }
  13446. *
  13447. * Foo.prototype.b = 2;
  13448. * Bar.prototype.d = 4;
  13449. *
  13450. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  13451. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  13452. */
  13453. var assignIn = createAssigner(function(object, source) {
  13454. copyObject(source, keysIn(source), object);
  13455. });
  13456. /**
  13457. * This method is like `_.assignIn` except that it accepts `customizer`
  13458. * which is invoked to produce the assigned values. If `customizer` returns
  13459. * `undefined`, assignment is handled by the method instead. The `customizer`
  13460. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  13461. *
  13462. * **Note:** This method mutates `object`.
  13463. *
  13464. * @static
  13465. * @memberOf _
  13466. * @since 4.0.0
  13467. * @alias extendWith
  13468. * @category Object
  13469. * @param {Object} object The destination object.
  13470. * @param {...Object} sources The source objects.
  13471. * @param {Function} [customizer] The function to customize assigned values.
  13472. * @returns {Object} Returns `object`.
  13473. * @see _.assignWith
  13474. * @example
  13475. *
  13476. * function customizer(objValue, srcValue) {
  13477. * return _.isUndefined(objValue) ? srcValue : objValue;
  13478. * }
  13479. *
  13480. * var defaults = _.partialRight(_.assignInWith, customizer);
  13481. *
  13482. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  13483. * // => { 'a': 1, 'b': 2 }
  13484. */
  13485. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  13486. copyObject(source, keysIn(source), object, customizer);
  13487. });
  13488. /**
  13489. * This method is like `_.assign` except that it accepts `customizer`
  13490. * which is invoked to produce the assigned values. If `customizer` returns
  13491. * `undefined`, assignment is handled by the method instead. The `customizer`
  13492. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  13493. *
  13494. * **Note:** This method mutates `object`.
  13495. *
  13496. * @static
  13497. * @memberOf _
  13498. * @since 4.0.0
  13499. * @category Object
  13500. * @param {Object} object The destination object.
  13501. * @param {...Object} sources The source objects.
  13502. * @param {Function} [customizer] The function to customize assigned values.
  13503. * @returns {Object} Returns `object`.
  13504. * @see _.assignInWith
  13505. * @example
  13506. *
  13507. * function customizer(objValue, srcValue) {
  13508. * return _.isUndefined(objValue) ? srcValue : objValue;
  13509. * }
  13510. *
  13511. * var defaults = _.partialRight(_.assignWith, customizer);
  13512. *
  13513. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  13514. * // => { 'a': 1, 'b': 2 }
  13515. */
  13516. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  13517. copyObject(source, keys(source), object, customizer);
  13518. });
  13519. /**
  13520. * Creates an array of values corresponding to `paths` of `object`.
  13521. *
  13522. * @static
  13523. * @memberOf _
  13524. * @since 1.0.0
  13525. * @category Object
  13526. * @param {Object} object The object to iterate over.
  13527. * @param {...(string|string[])} [paths] The property paths to pick.
  13528. * @returns {Array} Returns the picked values.
  13529. * @example
  13530. *
  13531. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  13532. *
  13533. * _.at(object, ['a[0].b.c', 'a[1]']);
  13534. * // => [3, 4]
  13535. */
  13536. var at = flatRest(baseAt);
  13537. /**
  13538. * Creates an object that inherits from the `prototype` object. If a
  13539. * `properties` object is given, its own enumerable string keyed properties
  13540. * are assigned to the created object.
  13541. *
  13542. * @static
  13543. * @memberOf _
  13544. * @since 2.3.0
  13545. * @category Object
  13546. * @param {Object} prototype The object to inherit from.
  13547. * @param {Object} [properties] The properties to assign to the object.
  13548. * @returns {Object} Returns the new object.
  13549. * @example
  13550. *
  13551. * function Shape() {
  13552. * this.x = 0;
  13553. * this.y = 0;
  13554. * }
  13555. *
  13556. * function Circle() {
  13557. * Shape.call(this);
  13558. * }
  13559. *
  13560. * Circle.prototype = _.create(Shape.prototype, {
  13561. * 'constructor': Circle
  13562. * });
  13563. *
  13564. * var circle = new Circle;
  13565. * circle instanceof Circle;
  13566. * // => true
  13567. *
  13568. * circle instanceof Shape;
  13569. * // => true
  13570. */
  13571. function create(prototype, properties) {
  13572. var result = baseCreate(prototype);
  13573. return properties == null ? result : baseAssign(result, properties);
  13574. }
  13575. /**
  13576. * Assigns own and inherited enumerable string keyed properties of source
  13577. * objects to the destination object for all destination properties that
  13578. * resolve to `undefined`. Source objects are applied from left to right.
  13579. * Once a property is set, additional values of the same property are ignored.
  13580. *
  13581. * **Note:** This method mutates `object`.
  13582. *
  13583. * @static
  13584. * @since 0.1.0
  13585. * @memberOf _
  13586. * @category Object
  13587. * @param {Object} object The destination object.
  13588. * @param {...Object} [sources] The source objects.
  13589. * @returns {Object} Returns `object`.
  13590. * @see _.defaultsDeep
  13591. * @example
  13592. *
  13593. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  13594. * // => { 'a': 1, 'b': 2 }
  13595. */
  13596. var defaults = baseRest(function(object, sources) {
  13597. object = Object(object);
  13598. var index = -1;
  13599. var length = sources.length;
  13600. var guard = length > 2 ? sources[2] : undefined;
  13601. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  13602. length = 1;
  13603. }
  13604. while (++index < length) {
  13605. var source = sources[index];
  13606. var props = keysIn(source);
  13607. var propsIndex = -1;
  13608. var propsLength = props.length;
  13609. while (++propsIndex < propsLength) {
  13610. var key = props[propsIndex];
  13611. var value = object[key];
  13612. if (value === undefined ||
  13613. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  13614. object[key] = source[key];
  13615. }
  13616. }
  13617. }
  13618. return object;
  13619. });
  13620. /**
  13621. * This method is like `_.defaults` except that it recursively assigns
  13622. * default properties.
  13623. *
  13624. * **Note:** This method mutates `object`.
  13625. *
  13626. * @static
  13627. * @memberOf _
  13628. * @since 3.10.0
  13629. * @category Object
  13630. * @param {Object} object The destination object.
  13631. * @param {...Object} [sources] The source objects.
  13632. * @returns {Object} Returns `object`.
  13633. * @see _.defaults
  13634. * @example
  13635. *
  13636. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  13637. * // => { 'a': { 'b': 2, 'c': 3 } }
  13638. */
  13639. var defaultsDeep = baseRest(function(args) {
  13640. args.push(undefined, customDefaultsMerge);
  13641. return apply(mergeWith, undefined, args);
  13642. });
  13643. /**
  13644. * This method is like `_.find` except that it returns the key of the first
  13645. * element `predicate` returns truthy for instead of the element itself.
  13646. *
  13647. * @static
  13648. * @memberOf _
  13649. * @since 1.1.0
  13650. * @category Object
  13651. * @param {Object} object The object to inspect.
  13652. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  13653. * @returns {string|undefined} Returns the key of the matched element,
  13654. * else `undefined`.
  13655. * @example
  13656. *
  13657. * var users = {
  13658. * 'barney': { 'age': 36, 'active': true },
  13659. * 'fred': { 'age': 40, 'active': false },
  13660. * 'pebbles': { 'age': 1, 'active': true }
  13661. * };
  13662. *
  13663. * _.findKey(users, function(o) { return o.age < 40; });
  13664. * // => 'barney' (iteration order is not guaranteed)
  13665. *
  13666. * // The `_.matches` iteratee shorthand.
  13667. * _.findKey(users, { 'age': 1, 'active': true });
  13668. * // => 'pebbles'
  13669. *
  13670. * // The `_.matchesProperty` iteratee shorthand.
  13671. * _.findKey(users, ['active', false]);
  13672. * // => 'fred'
  13673. *
  13674. * // The `_.property` iteratee shorthand.
  13675. * _.findKey(users, 'active');
  13676. * // => 'barney'
  13677. */
  13678. function findKey(object, predicate) {
  13679. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  13680. }
  13681. /**
  13682. * This method is like `_.findKey` except that it iterates over elements of
  13683. * a collection in the opposite order.
  13684. *
  13685. * @static
  13686. * @memberOf _
  13687. * @since 2.0.0
  13688. * @category Object
  13689. * @param {Object} object The object to inspect.
  13690. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  13691. * @returns {string|undefined} Returns the key of the matched element,
  13692. * else `undefined`.
  13693. * @example
  13694. *
  13695. * var users = {
  13696. * 'barney': { 'age': 36, 'active': true },
  13697. * 'fred': { 'age': 40, 'active': false },
  13698. * 'pebbles': { 'age': 1, 'active': true }
  13699. * };
  13700. *
  13701. * _.findLastKey(users, function(o) { return o.age < 40; });
  13702. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  13703. *
  13704. * // The `_.matches` iteratee shorthand.
  13705. * _.findLastKey(users, { 'age': 36, 'active': true });
  13706. * // => 'barney'
  13707. *
  13708. * // The `_.matchesProperty` iteratee shorthand.
  13709. * _.findLastKey(users, ['active', false]);
  13710. * // => 'fred'
  13711. *
  13712. * // The `_.property` iteratee shorthand.
  13713. * _.findLastKey(users, 'active');
  13714. * // => 'pebbles'
  13715. */
  13716. function findLastKey(object, predicate) {
  13717. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  13718. }
  13719. /**
  13720. * Iterates over own and inherited enumerable string keyed properties of an
  13721. * object and invokes `iteratee` for each property. The iteratee is invoked
  13722. * with three arguments: (value, key, object). Iteratee functions may exit
  13723. * iteration early by explicitly returning `false`.
  13724. *
  13725. * @static
  13726. * @memberOf _
  13727. * @since 0.3.0
  13728. * @category Object
  13729. * @param {Object} object The object to iterate over.
  13730. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13731. * @returns {Object} Returns `object`.
  13732. * @see _.forInRight
  13733. * @example
  13734. *
  13735. * function Foo() {
  13736. * this.a = 1;
  13737. * this.b = 2;
  13738. * }
  13739. *
  13740. * Foo.prototype.c = 3;
  13741. *
  13742. * _.forIn(new Foo, function(value, key) {
  13743. * console.log(key);
  13744. * });
  13745. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  13746. */
  13747. function forIn(object, iteratee) {
  13748. return object == null
  13749. ? object
  13750. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  13751. }
  13752. /**
  13753. * This method is like `_.forIn` except that it iterates over properties of
  13754. * `object` in the opposite order.
  13755. *
  13756. * @static
  13757. * @memberOf _
  13758. * @since 2.0.0
  13759. * @category Object
  13760. * @param {Object} object The object to iterate over.
  13761. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13762. * @returns {Object} Returns `object`.
  13763. * @see _.forIn
  13764. * @example
  13765. *
  13766. * function Foo() {
  13767. * this.a = 1;
  13768. * this.b = 2;
  13769. * }
  13770. *
  13771. * Foo.prototype.c = 3;
  13772. *
  13773. * _.forInRight(new Foo, function(value, key) {
  13774. * console.log(key);
  13775. * });
  13776. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  13777. */
  13778. function forInRight(object, iteratee) {
  13779. return object == null
  13780. ? object
  13781. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  13782. }
  13783. /**
  13784. * Iterates over own enumerable string keyed properties of an object and
  13785. * invokes `iteratee` for each property. The iteratee is invoked with three
  13786. * arguments: (value, key, object). Iteratee functions may exit iteration
  13787. * early by explicitly returning `false`.
  13788. *
  13789. * @static
  13790. * @memberOf _
  13791. * @since 0.3.0
  13792. * @category Object
  13793. * @param {Object} object The object to iterate over.
  13794. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13795. * @returns {Object} Returns `object`.
  13796. * @see _.forOwnRight
  13797. * @example
  13798. *
  13799. * function Foo() {
  13800. * this.a = 1;
  13801. * this.b = 2;
  13802. * }
  13803. *
  13804. * Foo.prototype.c = 3;
  13805. *
  13806. * _.forOwn(new Foo, function(value, key) {
  13807. * console.log(key);
  13808. * });
  13809. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  13810. */
  13811. function forOwn(object, iteratee) {
  13812. return object && baseForOwn(object, getIteratee(iteratee, 3));
  13813. }
  13814. /**
  13815. * This method is like `_.forOwn` except that it iterates over properties of
  13816. * `object` in the opposite order.
  13817. *
  13818. * @static
  13819. * @memberOf _
  13820. * @since 2.0.0
  13821. * @category Object
  13822. * @param {Object} object The object to iterate over.
  13823. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  13824. * @returns {Object} Returns `object`.
  13825. * @see _.forOwn
  13826. * @example
  13827. *
  13828. * function Foo() {
  13829. * this.a = 1;
  13830. * this.b = 2;
  13831. * }
  13832. *
  13833. * Foo.prototype.c = 3;
  13834. *
  13835. * _.forOwnRight(new Foo, function(value, key) {
  13836. * console.log(key);
  13837. * });
  13838. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  13839. */
  13840. function forOwnRight(object, iteratee) {
  13841. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  13842. }
  13843. /**
  13844. * Creates an array of function property names from own enumerable properties
  13845. * of `object`.
  13846. *
  13847. * @static
  13848. * @since 0.1.0
  13849. * @memberOf _
  13850. * @category Object
  13851. * @param {Object} object The object to inspect.
  13852. * @returns {Array} Returns the function names.
  13853. * @see _.functionsIn
  13854. * @example
  13855. *
  13856. * function Foo() {
  13857. * this.a = _.constant('a');
  13858. * this.b = _.constant('b');
  13859. * }
  13860. *
  13861. * Foo.prototype.c = _.constant('c');
  13862. *
  13863. * _.functions(new Foo);
  13864. * // => ['a', 'b']
  13865. */
  13866. function functions(object) {
  13867. return object == null ? [] : baseFunctions(object, keys(object));
  13868. }
  13869. /**
  13870. * Creates an array of function property names from own and inherited
  13871. * enumerable properties of `object`.
  13872. *
  13873. * @static
  13874. * @memberOf _
  13875. * @since 4.0.0
  13876. * @category Object
  13877. * @param {Object} object The object to inspect.
  13878. * @returns {Array} Returns the function names.
  13879. * @see _.functions
  13880. * @example
  13881. *
  13882. * function Foo() {
  13883. * this.a = _.constant('a');
  13884. * this.b = _.constant('b');
  13885. * }
  13886. *
  13887. * Foo.prototype.c = _.constant('c');
  13888. *
  13889. * _.functionsIn(new Foo);
  13890. * // => ['a', 'b', 'c']
  13891. */
  13892. function functionsIn(object) {
  13893. return object == null ? [] : baseFunctions(object, keysIn(object));
  13894. }
  13895. /**
  13896. * Gets the value at `path` of `object`. If the resolved value is
  13897. * `undefined`, the `defaultValue` is returned in its place.
  13898. *
  13899. * @static
  13900. * @memberOf _
  13901. * @since 3.7.0
  13902. * @category Object
  13903. * @param {Object} object The object to query.
  13904. * @param {Array|string} path The path of the property to get.
  13905. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  13906. * @returns {*} Returns the resolved value.
  13907. * @example
  13908. *
  13909. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13910. *
  13911. * _.get(object, 'a[0].b.c');
  13912. * // => 3
  13913. *
  13914. * _.get(object, ['a', '0', 'b', 'c']);
  13915. * // => 3
  13916. *
  13917. * _.get(object, 'a.b.c', 'default');
  13918. * // => 'default'
  13919. */
  13920. function get(object, path, defaultValue) {
  13921. var result = object == null ? undefined : baseGet(object, path);
  13922. return result === undefined ? defaultValue : result;
  13923. }
  13924. /**
  13925. * Checks if `path` is a direct property of `object`.
  13926. *
  13927. * @static
  13928. * @since 0.1.0
  13929. * @memberOf _
  13930. * @category Object
  13931. * @param {Object} object The object to query.
  13932. * @param {Array|string} path The path to check.
  13933. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13934. * @example
  13935. *
  13936. * var object = { 'a': { 'b': 2 } };
  13937. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  13938. *
  13939. * _.has(object, 'a');
  13940. * // => true
  13941. *
  13942. * _.has(object, 'a.b');
  13943. * // => true
  13944. *
  13945. * _.has(object, ['a', 'b']);
  13946. * // => true
  13947. *
  13948. * _.has(other, 'a');
  13949. * // => false
  13950. */
  13951. function has(object, path) {
  13952. return object != null && hasPath(object, path, baseHas);
  13953. }
  13954. /**
  13955. * Checks if `path` is a direct or inherited property of `object`.
  13956. *
  13957. * @static
  13958. * @memberOf _
  13959. * @since 4.0.0
  13960. * @category Object
  13961. * @param {Object} object The object to query.
  13962. * @param {Array|string} path The path to check.
  13963. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13964. * @example
  13965. *
  13966. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  13967. *
  13968. * _.hasIn(object, 'a');
  13969. * // => true
  13970. *
  13971. * _.hasIn(object, 'a.b');
  13972. * // => true
  13973. *
  13974. * _.hasIn(object, ['a', 'b']);
  13975. * // => true
  13976. *
  13977. * _.hasIn(object, 'b');
  13978. * // => false
  13979. */
  13980. function hasIn(object, path) {
  13981. return object != null && hasPath(object, path, baseHasIn);
  13982. }
  13983. /**
  13984. * Creates an object composed of the inverted keys and values of `object`.
  13985. * If `object` contains duplicate values, subsequent values overwrite
  13986. * property assignments of previous values.
  13987. *
  13988. * @static
  13989. * @memberOf _
  13990. * @since 0.7.0
  13991. * @category Object
  13992. * @param {Object} object The object to invert.
  13993. * @returns {Object} Returns the new inverted object.
  13994. * @example
  13995. *
  13996. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  13997. *
  13998. * _.invert(object);
  13999. * // => { '1': 'c', '2': 'b' }
  14000. */
  14001. var invert = createInverter(function(result, value, key) {
  14002. if (value != null &&
  14003. typeof value.toString != 'function') {
  14004. value = nativeObjectToString.call(value);
  14005. }
  14006. result[value] = key;
  14007. }, constant(identity));
  14008. /**
  14009. * This method is like `_.invert` except that the inverted object is generated
  14010. * from the results of running each element of `object` thru `iteratee`. The
  14011. * corresponding inverted value of each inverted key is an array of keys
  14012. * responsible for generating the inverted value. The iteratee is invoked
  14013. * with one argument: (value).
  14014. *
  14015. * @static
  14016. * @memberOf _
  14017. * @since 4.1.0
  14018. * @category Object
  14019. * @param {Object} object The object to invert.
  14020. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  14021. * @returns {Object} Returns the new inverted object.
  14022. * @example
  14023. *
  14024. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  14025. *
  14026. * _.invertBy(object);
  14027. * // => { '1': ['a', 'c'], '2': ['b'] }
  14028. *
  14029. * _.invertBy(object, function(value) {
  14030. * return 'group' + value;
  14031. * });
  14032. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  14033. */
  14034. var invertBy = createInverter(function(result, value, key) {
  14035. if (value != null &&
  14036. typeof value.toString != 'function') {
  14037. value = nativeObjectToString.call(value);
  14038. }
  14039. if (hasOwnProperty.call(result, value)) {
  14040. result[value].push(key);
  14041. } else {
  14042. result[value] = [key];
  14043. }
  14044. }, getIteratee);
  14045. /**
  14046. * Invokes the method at `path` of `object`.
  14047. *
  14048. * @static
  14049. * @memberOf _
  14050. * @since 4.0.0
  14051. * @category Object
  14052. * @param {Object} object The object to query.
  14053. * @param {Array|string} path The path of the method to invoke.
  14054. * @param {...*} [args] The arguments to invoke the method with.
  14055. * @returns {*} Returns the result of the invoked method.
  14056. * @example
  14057. *
  14058. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  14059. *
  14060. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  14061. * // => [2, 3]
  14062. */
  14063. var invoke = baseRest(baseInvoke);
  14064. /**
  14065. * Creates an array of the own enumerable property names of `object`.
  14066. *
  14067. * **Note:** Non-object values are coerced to objects. See the
  14068. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  14069. * for more details.
  14070. *
  14071. * @static
  14072. * @since 0.1.0
  14073. * @memberOf _
  14074. * @category Object
  14075. * @param {Object} object The object to query.
  14076. * @returns {Array} Returns the array of property names.
  14077. * @example
  14078. *
  14079. * function Foo() {
  14080. * this.a = 1;
  14081. * this.b = 2;
  14082. * }
  14083. *
  14084. * Foo.prototype.c = 3;
  14085. *
  14086. * _.keys(new Foo);
  14087. * // => ['a', 'b'] (iteration order is not guaranteed)
  14088. *
  14089. * _.keys('hi');
  14090. * // => ['0', '1']
  14091. */
  14092. function keys(object) {
  14093. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  14094. }
  14095. /**
  14096. * Creates an array of the own and inherited enumerable property names of `object`.
  14097. *
  14098. * **Note:** Non-object values are coerced to objects.
  14099. *
  14100. * @static
  14101. * @memberOf _
  14102. * @since 3.0.0
  14103. * @category Object
  14104. * @param {Object} object The object to query.
  14105. * @returns {Array} Returns the array of property names.
  14106. * @example
  14107. *
  14108. * function Foo() {
  14109. * this.a = 1;
  14110. * this.b = 2;
  14111. * }
  14112. *
  14113. * Foo.prototype.c = 3;
  14114. *
  14115. * _.keysIn(new Foo);
  14116. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  14117. */
  14118. function keysIn(object) {
  14119. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  14120. }
  14121. /**
  14122. * The opposite of `_.mapValues`; this method creates an object with the
  14123. * same values as `object` and keys generated by running each own enumerable
  14124. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  14125. * with three arguments: (value, key, object).
  14126. *
  14127. * @static
  14128. * @memberOf _
  14129. * @since 3.8.0
  14130. * @category Object
  14131. * @param {Object} object The object to iterate over.
  14132. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14133. * @returns {Object} Returns the new mapped object.
  14134. * @see _.mapValues
  14135. * @example
  14136. *
  14137. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  14138. * return key + value;
  14139. * });
  14140. * // => { 'a1': 1, 'b2': 2 }
  14141. */
  14142. function mapKeys(object, iteratee) {
  14143. var result = {};
  14144. iteratee = getIteratee(iteratee, 3);
  14145. baseForOwn(object, function(value, key, object) {
  14146. baseAssignValue(result, iteratee(value, key, object), value);
  14147. });
  14148. return result;
  14149. }
  14150. /**
  14151. * Creates an object with the same keys as `object` and values generated
  14152. * by running each own enumerable string keyed property of `object` thru
  14153. * `iteratee`. The iteratee is invoked with three arguments:
  14154. * (value, key, object).
  14155. *
  14156. * @static
  14157. * @memberOf _
  14158. * @since 2.4.0
  14159. * @category Object
  14160. * @param {Object} object The object to iterate over.
  14161. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14162. * @returns {Object} Returns the new mapped object.
  14163. * @see _.mapKeys
  14164. * @example
  14165. *
  14166. * var users = {
  14167. * 'fred': { 'user': 'fred', 'age': 40 },
  14168. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  14169. * };
  14170. *
  14171. * _.mapValues(users, function(o) { return o.age; });
  14172. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  14173. *
  14174. * // The `_.property` iteratee shorthand.
  14175. * _.mapValues(users, 'age');
  14176. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  14177. */
  14178. function mapValues(object, iteratee) {
  14179. var result = {};
  14180. iteratee = getIteratee(iteratee, 3);
  14181. baseForOwn(object, function(value, key, object) {
  14182. baseAssignValue(result, key, iteratee(value, key, object));
  14183. });
  14184. return result;
  14185. }
  14186. /**
  14187. * This method is like `_.assign` except that it recursively merges own and
  14188. * inherited enumerable string keyed properties of source objects into the
  14189. * destination object. Source properties that resolve to `undefined` are
  14190. * skipped if a destination value exists. Array and plain object properties
  14191. * are merged recursively. Other objects and value types are overridden by
  14192. * assignment. Source objects are applied from left to right. Subsequent
  14193. * sources overwrite property assignments of previous sources.
  14194. *
  14195. * **Note:** This method mutates `object`.
  14196. *
  14197. * @static
  14198. * @memberOf _
  14199. * @since 0.5.0
  14200. * @category Object
  14201. * @param {Object} object The destination object.
  14202. * @param {...Object} [sources] The source objects.
  14203. * @returns {Object} Returns `object`.
  14204. * @example
  14205. *
  14206. * var object = {
  14207. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  14208. * };
  14209. *
  14210. * var other = {
  14211. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  14212. * };
  14213. *
  14214. * _.merge(object, other);
  14215. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  14216. */
  14217. var merge = createAssigner(function(object, source, srcIndex) {
  14218. baseMerge(object, source, srcIndex);
  14219. });
  14220. /**
  14221. * This method is like `_.merge` except that it accepts `customizer` which
  14222. * is invoked to produce the merged values of the destination and source
  14223. * properties. If `customizer` returns `undefined`, merging is handled by the
  14224. * method instead. The `customizer` is invoked with six arguments:
  14225. * (objValue, srcValue, key, object, source, stack).
  14226. *
  14227. * **Note:** This method mutates `object`.
  14228. *
  14229. * @static
  14230. * @memberOf _
  14231. * @since 4.0.0
  14232. * @category Object
  14233. * @param {Object} object The destination object.
  14234. * @param {...Object} sources The source objects.
  14235. * @param {Function} customizer The function to customize assigned values.
  14236. * @returns {Object} Returns `object`.
  14237. * @example
  14238. *
  14239. * function customizer(objValue, srcValue) {
  14240. * if (_.isArray(objValue)) {
  14241. * return objValue.concat(srcValue);
  14242. * }
  14243. * }
  14244. *
  14245. * var object = { 'a': [1], 'b': [2] };
  14246. * var other = { 'a': [3], 'b': [4] };
  14247. *
  14248. * _.mergeWith(object, other, customizer);
  14249. * // => { 'a': [1, 3], 'b': [2, 4] }
  14250. */
  14251. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  14252. baseMerge(object, source, srcIndex, customizer);
  14253. });
  14254. /**
  14255. * The opposite of `_.pick`; this method creates an object composed of the
  14256. * own and inherited enumerable property paths of `object` that are not omitted.
  14257. *
  14258. * **Note:** This method is considerably slower than `_.pick`.
  14259. *
  14260. * @static
  14261. * @since 0.1.0
  14262. * @memberOf _
  14263. * @category Object
  14264. * @param {Object} object The source object.
  14265. * @param {...(string|string[])} [paths] The property paths to omit.
  14266. * @returns {Object} Returns the new object.
  14267. * @example
  14268. *
  14269. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  14270. *
  14271. * _.omit(object, ['a', 'c']);
  14272. * // => { 'b': '2' }
  14273. */
  14274. var omit = flatRest(function(object, paths) {
  14275. var result = {};
  14276. if (object == null) {
  14277. return result;
  14278. }
  14279. var isDeep = false;
  14280. paths = arrayMap(paths, function(path) {
  14281. path = castPath(path, object);
  14282. isDeep || (isDeep = path.length > 1);
  14283. return path;
  14284. });
  14285. copyObject(object, getAllKeysIn(object), result);
  14286. if (isDeep) {
  14287. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  14288. }
  14289. var length = paths.length;
  14290. while (length--) {
  14291. baseUnset(result, paths[length]);
  14292. }
  14293. return result;
  14294. });
  14295. /**
  14296. * The opposite of `_.pickBy`; this method creates an object composed of
  14297. * the own and inherited enumerable string keyed properties of `object` that
  14298. * `predicate` doesn't return truthy for. The predicate is invoked with two
  14299. * arguments: (value, key).
  14300. *
  14301. * @static
  14302. * @memberOf _
  14303. * @since 4.0.0
  14304. * @category Object
  14305. * @param {Object} object The source object.
  14306. * @param {Function} [predicate=_.identity] The function invoked per property.
  14307. * @returns {Object} Returns the new object.
  14308. * @example
  14309. *
  14310. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  14311. *
  14312. * _.omitBy(object, _.isNumber);
  14313. * // => { 'b': '2' }
  14314. */
  14315. function omitBy(object, predicate) {
  14316. return pickBy(object, negate(getIteratee(predicate)));
  14317. }
  14318. /**
  14319. * Creates an object composed of the picked `object` properties.
  14320. *
  14321. * @static
  14322. * @since 0.1.0
  14323. * @memberOf _
  14324. * @category Object
  14325. * @param {Object} object The source object.
  14326. * @param {...(string|string[])} [paths] The property paths to pick.
  14327. * @returns {Object} Returns the new object.
  14328. * @example
  14329. *
  14330. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  14331. *
  14332. * _.pick(object, ['a', 'c']);
  14333. * // => { 'a': 1, 'c': 3 }
  14334. */
  14335. var pick = flatRest(function(object, paths) {
  14336. return object == null ? {} : basePick(object, paths);
  14337. });
  14338. /**
  14339. * Creates an object composed of the `object` properties `predicate` returns
  14340. * truthy for. The predicate is invoked with two arguments: (value, key).
  14341. *
  14342. * @static
  14343. * @memberOf _
  14344. * @since 4.0.0
  14345. * @category Object
  14346. * @param {Object} object The source object.
  14347. * @param {Function} [predicate=_.identity] The function invoked per property.
  14348. * @returns {Object} Returns the new object.
  14349. * @example
  14350. *
  14351. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  14352. *
  14353. * _.pickBy(object, _.isNumber);
  14354. * // => { 'a': 1, 'c': 3 }
  14355. */
  14356. function pickBy(object, predicate) {
  14357. if (object == null) {
  14358. return {};
  14359. }
  14360. var props = arrayMap(getAllKeysIn(object), function(prop) {
  14361. return [prop];
  14362. });
  14363. predicate = getIteratee(predicate);
  14364. return basePickBy(object, props, function(value, path) {
  14365. return predicate(value, path[0]);
  14366. });
  14367. }
  14368. /**
  14369. * This method is like `_.get` except that if the resolved value is a
  14370. * function it's invoked with the `this` binding of its parent object and
  14371. * its result is returned.
  14372. *
  14373. * @static
  14374. * @since 0.1.0
  14375. * @memberOf _
  14376. * @category Object
  14377. * @param {Object} object The object to query.
  14378. * @param {Array|string} path The path of the property to resolve.
  14379. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  14380. * @returns {*} Returns the resolved value.
  14381. * @example
  14382. *
  14383. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  14384. *
  14385. * _.result(object, 'a[0].b.c1');
  14386. * // => 3
  14387. *
  14388. * _.result(object, 'a[0].b.c2');
  14389. * // => 4
  14390. *
  14391. * _.result(object, 'a[0].b.c3', 'default');
  14392. * // => 'default'
  14393. *
  14394. * _.result(object, 'a[0].b.c3', _.constant('default'));
  14395. * // => 'default'
  14396. */
  14397. function result(object, path, defaultValue) {
  14398. path = castPath(path, object);
  14399. var index = -1,
  14400. length = path.length;
  14401. // Ensure the loop is entered when path is empty.
  14402. if (!length) {
  14403. length = 1;
  14404. object = undefined;
  14405. }
  14406. while (++index < length) {
  14407. var value = object == null ? undefined : object[toKey(path[index])];
  14408. if (value === undefined) {
  14409. index = length;
  14410. value = defaultValue;
  14411. }
  14412. object = isFunction(value) ? value.call(object) : value;
  14413. }
  14414. return object;
  14415. }
  14416. /**
  14417. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  14418. * it's created. Arrays are created for missing index properties while objects
  14419. * are created for all other missing properties. Use `_.setWith` to customize
  14420. * `path` creation.
  14421. *
  14422. * **Note:** This method mutates `object`.
  14423. *
  14424. * @static
  14425. * @memberOf _
  14426. * @since 3.7.0
  14427. * @category Object
  14428. * @param {Object} object The object to modify.
  14429. * @param {Array|string} path The path of the property to set.
  14430. * @param {*} value The value to set.
  14431. * @returns {Object} Returns `object`.
  14432. * @example
  14433. *
  14434. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  14435. *
  14436. * _.set(object, 'a[0].b.c', 4);
  14437. * console.log(object.a[0].b.c);
  14438. * // => 4
  14439. *
  14440. * _.set(object, ['x', '0', 'y', 'z'], 5);
  14441. * console.log(object.x[0].y.z);
  14442. * // => 5
  14443. */
  14444. function set(object, path, value) {
  14445. return object == null ? object : baseSet(object, path, value);
  14446. }
  14447. /**
  14448. * This method is like `_.set` except that it accepts `customizer` which is
  14449. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  14450. * path creation is handled by the method instead. The `customizer` is invoked
  14451. * with three arguments: (nsValue, key, nsObject).
  14452. *
  14453. * **Note:** This method mutates `object`.
  14454. *
  14455. * @static
  14456. * @memberOf _
  14457. * @since 4.0.0
  14458. * @category Object
  14459. * @param {Object} object The object to modify.
  14460. * @param {Array|string} path The path of the property to set.
  14461. * @param {*} value The value to set.
  14462. * @param {Function} [customizer] The function to customize assigned values.
  14463. * @returns {Object} Returns `object`.
  14464. * @example
  14465. *
  14466. * var object = {};
  14467. *
  14468. * _.setWith(object, '[0][1]', 'a', Object);
  14469. * // => { '0': { '1': 'a' } }
  14470. */
  14471. function setWith(object, path, value, customizer) {
  14472. customizer = typeof customizer == 'function' ? customizer : undefined;
  14473. return object == null ? object : baseSet(object, path, value, customizer);
  14474. }
  14475. /**
  14476. * Creates an array of own enumerable string keyed-value pairs for `object`
  14477. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  14478. * entries are returned.
  14479. *
  14480. * @static
  14481. * @memberOf _
  14482. * @since 4.0.0
  14483. * @alias entries
  14484. * @category Object
  14485. * @param {Object} object The object to query.
  14486. * @returns {Array} Returns the key-value pairs.
  14487. * @example
  14488. *
  14489. * function Foo() {
  14490. * this.a = 1;
  14491. * this.b = 2;
  14492. * }
  14493. *
  14494. * Foo.prototype.c = 3;
  14495. *
  14496. * _.toPairs(new Foo);
  14497. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  14498. */
  14499. var toPairs = createToPairs(keys);
  14500. /**
  14501. * Creates an array of own and inherited enumerable string keyed-value pairs
  14502. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  14503. * or set, its entries are returned.
  14504. *
  14505. * @static
  14506. * @memberOf _
  14507. * @since 4.0.0
  14508. * @alias entriesIn
  14509. * @category Object
  14510. * @param {Object} object The object to query.
  14511. * @returns {Array} Returns the key-value pairs.
  14512. * @example
  14513. *
  14514. * function Foo() {
  14515. * this.a = 1;
  14516. * this.b = 2;
  14517. * }
  14518. *
  14519. * Foo.prototype.c = 3;
  14520. *
  14521. * _.toPairsIn(new Foo);
  14522. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  14523. */
  14524. var toPairsIn = createToPairs(keysIn);
  14525. /**
  14526. * An alternative to `_.reduce`; this method transforms `object` to a new
  14527. * `accumulator` object which is the result of running each of its own
  14528. * enumerable string keyed properties thru `iteratee`, with each invocation
  14529. * potentially mutating the `accumulator` object. If `accumulator` is not
  14530. * provided, a new object with the same `[[Prototype]]` will be used. The
  14531. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  14532. * Iteratee functions may exit iteration early by explicitly returning `false`.
  14533. *
  14534. * @static
  14535. * @memberOf _
  14536. * @since 1.3.0
  14537. * @category Object
  14538. * @param {Object} object The object to iterate over.
  14539. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14540. * @param {*} [accumulator] The custom accumulator value.
  14541. * @returns {*} Returns the accumulated value.
  14542. * @example
  14543. *
  14544. * _.transform([2, 3, 4], function(result, n) {
  14545. * result.push(n *= n);
  14546. * return n % 2 == 0;
  14547. * }, []);
  14548. * // => [4, 9]
  14549. *
  14550. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  14551. * (result[value] || (result[value] = [])).push(key);
  14552. * }, {});
  14553. * // => { '1': ['a', 'c'], '2': ['b'] }
  14554. */
  14555. function transform(object, iteratee, accumulator) {
  14556. var isArr = isArray(object),
  14557. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  14558. iteratee = getIteratee(iteratee, 4);
  14559. if (accumulator == null) {
  14560. var Ctor = object && object.constructor;
  14561. if (isArrLike) {
  14562. accumulator = isArr ? new Ctor : [];
  14563. }
  14564. else if (isObject(object)) {
  14565. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  14566. }
  14567. else {
  14568. accumulator = {};
  14569. }
  14570. }
  14571. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  14572. return iteratee(accumulator, value, index, object);
  14573. });
  14574. return accumulator;
  14575. }
  14576. /**
  14577. * Removes the property at `path` of `object`.
  14578. *
  14579. * **Note:** This method mutates `object`.
  14580. *
  14581. * @static
  14582. * @memberOf _
  14583. * @since 4.0.0
  14584. * @category Object
  14585. * @param {Object} object The object to modify.
  14586. * @param {Array|string} path The path of the property to unset.
  14587. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  14588. * @example
  14589. *
  14590. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  14591. * _.unset(object, 'a[0].b.c');
  14592. * // => true
  14593. *
  14594. * console.log(object);
  14595. * // => { 'a': [{ 'b': {} }] };
  14596. *
  14597. * _.unset(object, ['a', '0', 'b', 'c']);
  14598. * // => true
  14599. *
  14600. * console.log(object);
  14601. * // => { 'a': [{ 'b': {} }] };
  14602. */
  14603. function unset(object, path) {
  14604. return object == null ? true : baseUnset(object, path);
  14605. }
  14606. /**
  14607. * This method is like `_.set` except that accepts `updater` to produce the
  14608. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  14609. * is invoked with one argument: (value).
  14610. *
  14611. * **Note:** This method mutates `object`.
  14612. *
  14613. * @static
  14614. * @memberOf _
  14615. * @since 4.6.0
  14616. * @category Object
  14617. * @param {Object} object The object to modify.
  14618. * @param {Array|string} path The path of the property to set.
  14619. * @param {Function} updater The function to produce the updated value.
  14620. * @returns {Object} Returns `object`.
  14621. * @example
  14622. *
  14623. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  14624. *
  14625. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  14626. * console.log(object.a[0].b.c);
  14627. * // => 9
  14628. *
  14629. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  14630. * console.log(object.x[0].y.z);
  14631. * // => 0
  14632. */
  14633. function update(object, path, updater) {
  14634. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  14635. }
  14636. /**
  14637. * This method is like `_.update` except that it accepts `customizer` which is
  14638. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  14639. * path creation is handled by the method instead. The `customizer` is invoked
  14640. * with three arguments: (nsValue, key, nsObject).
  14641. *
  14642. * **Note:** This method mutates `object`.
  14643. *
  14644. * @static
  14645. * @memberOf _
  14646. * @since 4.6.0
  14647. * @category Object
  14648. * @param {Object} object The object to modify.
  14649. * @param {Array|string} path The path of the property to set.
  14650. * @param {Function} updater The function to produce the updated value.
  14651. * @param {Function} [customizer] The function to customize assigned values.
  14652. * @returns {Object} Returns `object`.
  14653. * @example
  14654. *
  14655. * var object = {};
  14656. *
  14657. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  14658. * // => { '0': { '1': 'a' } }
  14659. */
  14660. function updateWith(object, path, updater, customizer) {
  14661. customizer = typeof customizer == 'function' ? customizer : undefined;
  14662. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  14663. }
  14664. /**
  14665. * Creates an array of the own enumerable string keyed property values of `object`.
  14666. *
  14667. * **Note:** Non-object values are coerced to objects.
  14668. *
  14669. * @static
  14670. * @since 0.1.0
  14671. * @memberOf _
  14672. * @category Object
  14673. * @param {Object} object The object to query.
  14674. * @returns {Array} Returns the array of property values.
  14675. * @example
  14676. *
  14677. * function Foo() {
  14678. * this.a = 1;
  14679. * this.b = 2;
  14680. * }
  14681. *
  14682. * Foo.prototype.c = 3;
  14683. *
  14684. * _.values(new Foo);
  14685. * // => [1, 2] (iteration order is not guaranteed)
  14686. *
  14687. * _.values('hi');
  14688. * // => ['h', 'i']
  14689. */
  14690. function values(object) {
  14691. return object == null ? [] : baseValues(object, keys(object));
  14692. }
  14693. /**
  14694. * Creates an array of the own and inherited enumerable string keyed property
  14695. * values of `object`.
  14696. *
  14697. * **Note:** Non-object values are coerced to objects.
  14698. *
  14699. * @static
  14700. * @memberOf _
  14701. * @since 3.0.0
  14702. * @category Object
  14703. * @param {Object} object The object to query.
  14704. * @returns {Array} Returns the array of property values.
  14705. * @example
  14706. *
  14707. * function Foo() {
  14708. * this.a = 1;
  14709. * this.b = 2;
  14710. * }
  14711. *
  14712. * Foo.prototype.c = 3;
  14713. *
  14714. * _.valuesIn(new Foo);
  14715. * // => [1, 2, 3] (iteration order is not guaranteed)
  14716. */
  14717. function valuesIn(object) {
  14718. return object == null ? [] : baseValues(object, keysIn(object));
  14719. }
  14720. /*------------------------------------------------------------------------*/
  14721. /**
  14722. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  14723. *
  14724. * @static
  14725. * @memberOf _
  14726. * @since 4.0.0
  14727. * @category Number
  14728. * @param {number} number The number to clamp.
  14729. * @param {number} [lower] The lower bound.
  14730. * @param {number} upper The upper bound.
  14731. * @returns {number} Returns the clamped number.
  14732. * @example
  14733. *
  14734. * _.clamp(-10, -5, 5);
  14735. * // => -5
  14736. *
  14737. * _.clamp(10, -5, 5);
  14738. * // => 5
  14739. */
  14740. function clamp(number, lower, upper) {
  14741. if (upper === undefined) {
  14742. upper = lower;
  14743. lower = undefined;
  14744. }
  14745. if (upper !== undefined) {
  14746. upper = toNumber(upper);
  14747. upper = upper === upper ? upper : 0;
  14748. }
  14749. if (lower !== undefined) {
  14750. lower = toNumber(lower);
  14751. lower = lower === lower ? lower : 0;
  14752. }
  14753. return baseClamp(toNumber(number), lower, upper);
  14754. }
  14755. /**
  14756. * Checks if `n` is between `start` and up to, but not including, `end`. If
  14757. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  14758. * If `start` is greater than `end` the params are swapped to support
  14759. * negative ranges.
  14760. *
  14761. * @static
  14762. * @memberOf _
  14763. * @since 3.3.0
  14764. * @category Number
  14765. * @param {number} number The number to check.
  14766. * @param {number} [start=0] The start of the range.
  14767. * @param {number} end The end of the range.
  14768. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  14769. * @see _.range, _.rangeRight
  14770. * @example
  14771. *
  14772. * _.inRange(3, 2, 4);
  14773. * // => true
  14774. *
  14775. * _.inRange(4, 8);
  14776. * // => true
  14777. *
  14778. * _.inRange(4, 2);
  14779. * // => false
  14780. *
  14781. * _.inRange(2, 2);
  14782. * // => false
  14783. *
  14784. * _.inRange(1.2, 2);
  14785. * // => true
  14786. *
  14787. * _.inRange(5.2, 4);
  14788. * // => false
  14789. *
  14790. * _.inRange(-3, -2, -6);
  14791. * // => true
  14792. */
  14793. function inRange(number, start, end) {
  14794. start = toFinite(start);
  14795. if (end === undefined) {
  14796. end = start;
  14797. start = 0;
  14798. } else {
  14799. end = toFinite(end);
  14800. }
  14801. number = toNumber(number);
  14802. return baseInRange(number, start, end);
  14803. }
  14804. /**
  14805. * Produces a random number between the inclusive `lower` and `upper` bounds.
  14806. * If only one argument is provided a number between `0` and the given number
  14807. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  14808. * floats, a floating-point number is returned instead of an integer.
  14809. *
  14810. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14811. * floating-point values which can produce unexpected results.
  14812. *
  14813. * @static
  14814. * @memberOf _
  14815. * @since 0.7.0
  14816. * @category Number
  14817. * @param {number} [lower=0] The lower bound.
  14818. * @param {number} [upper=1] The upper bound.
  14819. * @param {boolean} [floating] Specify returning a floating-point number.
  14820. * @returns {number} Returns the random number.
  14821. * @example
  14822. *
  14823. * _.random(0, 5);
  14824. * // => an integer between 0 and 5
  14825. *
  14826. * _.random(5);
  14827. * // => also an integer between 0 and 5
  14828. *
  14829. * _.random(5, true);
  14830. * // => a floating-point number between 0 and 5
  14831. *
  14832. * _.random(1.2, 5.2);
  14833. * // => a floating-point number between 1.2 and 5.2
  14834. */
  14835. function random(lower, upper, floating) {
  14836. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  14837. upper = floating = undefined;
  14838. }
  14839. if (floating === undefined) {
  14840. if (typeof upper == 'boolean') {
  14841. floating = upper;
  14842. upper = undefined;
  14843. }
  14844. else if (typeof lower == 'boolean') {
  14845. floating = lower;
  14846. lower = undefined;
  14847. }
  14848. }
  14849. if (lower === undefined && upper === undefined) {
  14850. lower = 0;
  14851. upper = 1;
  14852. }
  14853. else {
  14854. lower = toFinite(lower);
  14855. if (upper === undefined) {
  14856. upper = lower;
  14857. lower = 0;
  14858. } else {
  14859. upper = toFinite(upper);
  14860. }
  14861. }
  14862. if (lower > upper) {
  14863. var temp = lower;
  14864. lower = upper;
  14865. upper = temp;
  14866. }
  14867. if (floating || lower % 1 || upper % 1) {
  14868. var rand = nativeRandom();
  14869. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  14870. }
  14871. return baseRandom(lower, upper);
  14872. }
  14873. /*------------------------------------------------------------------------*/
  14874. /**
  14875. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  14876. *
  14877. * @static
  14878. * @memberOf _
  14879. * @since 3.0.0
  14880. * @category String
  14881. * @param {string} [string=''] The string to convert.
  14882. * @returns {string} Returns the camel cased string.
  14883. * @example
  14884. *
  14885. * _.camelCase('Foo Bar');
  14886. * // => 'fooBar'
  14887. *
  14888. * _.camelCase('--foo-bar--');
  14889. * // => 'fooBar'
  14890. *
  14891. * _.camelCase('__FOO_BAR__');
  14892. * // => 'fooBar'
  14893. */
  14894. var camelCase = createCompounder(function(result, word, index) {
  14895. word = word.toLowerCase();
  14896. return result + (index ? capitalize(word) : word);
  14897. });
  14898. /**
  14899. * Converts the first character of `string` to upper case and the remaining
  14900. * to lower case.
  14901. *
  14902. * @static
  14903. * @memberOf _
  14904. * @since 3.0.0
  14905. * @category String
  14906. * @param {string} [string=''] The string to capitalize.
  14907. * @returns {string} Returns the capitalized string.
  14908. * @example
  14909. *
  14910. * _.capitalize('FRED');
  14911. * // => 'Fred'
  14912. */
  14913. function capitalize(string) {
  14914. return upperFirst(toString(string).toLowerCase());
  14915. }
  14916. /**
  14917. * Deburrs `string` by converting
  14918. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  14919. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  14920. * letters to basic Latin letters and removing
  14921. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  14922. *
  14923. * @static
  14924. * @memberOf _
  14925. * @since 3.0.0
  14926. * @category String
  14927. * @param {string} [string=''] The string to deburr.
  14928. * @returns {string} Returns the deburred string.
  14929. * @example
  14930. *
  14931. * _.deburr('déjà vu');
  14932. * // => 'deja vu'
  14933. */
  14934. function deburr(string) {
  14935. string = toString(string);
  14936. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  14937. }
  14938. /**
  14939. * Checks if `string` ends with the given target string.
  14940. *
  14941. * @static
  14942. * @memberOf _
  14943. * @since 3.0.0
  14944. * @category String
  14945. * @param {string} [string=''] The string to inspect.
  14946. * @param {string} [target] The string to search for.
  14947. * @param {number} [position=string.length] The position to search up to.
  14948. * @returns {boolean} Returns `true` if `string` ends with `target`,
  14949. * else `false`.
  14950. * @example
  14951. *
  14952. * _.endsWith('abc', 'c');
  14953. * // => true
  14954. *
  14955. * _.endsWith('abc', 'b');
  14956. * // => false
  14957. *
  14958. * _.endsWith('abc', 'b', 2);
  14959. * // => true
  14960. */
  14961. function endsWith(string, target, position) {
  14962. string = toString(string);
  14963. target = baseToString(target);
  14964. var length = string.length;
  14965. position = position === undefined
  14966. ? length
  14967. : baseClamp(toInteger(position), 0, length);
  14968. var end = position;
  14969. position -= target.length;
  14970. return position >= 0 && string.slice(position, end) == target;
  14971. }
  14972. /**
  14973. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  14974. * corresponding HTML entities.
  14975. *
  14976. * **Note:** No other characters are escaped. To escape additional
  14977. * characters use a third-party library like [_he_](https://mths.be/he).
  14978. *
  14979. * Though the ">" character is escaped for symmetry, characters like
  14980. * ">" and "/" don't need escaping in HTML and have no special meaning
  14981. * unless they're part of a tag or unquoted attribute value. See
  14982. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  14983. * (under "semi-related fun fact") for more details.
  14984. *
  14985. * When working with HTML you should always
  14986. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  14987. * XSS vectors.
  14988. *
  14989. * @static
  14990. * @since 0.1.0
  14991. * @memberOf _
  14992. * @category String
  14993. * @param {string} [string=''] The string to escape.
  14994. * @returns {string} Returns the escaped string.
  14995. * @example
  14996. *
  14997. * _.escape('fred, barney, & pebbles');
  14998. * // => 'fred, barney, &amp; pebbles'
  14999. */
  15000. function escape(string) {
  15001. string = toString(string);
  15002. return (string && reHasUnescapedHtml.test(string))
  15003. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  15004. : string;
  15005. }
  15006. /**
  15007. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  15008. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  15009. *
  15010. * @static
  15011. * @memberOf _
  15012. * @since 3.0.0
  15013. * @category String
  15014. * @param {string} [string=''] The string to escape.
  15015. * @returns {string} Returns the escaped string.
  15016. * @example
  15017. *
  15018. * _.escapeRegExp('[lodash](https://lodash.com/)');
  15019. * // => '\[lodash\]\(https://lodash\.com/\)'
  15020. */
  15021. function escapeRegExp(string) {
  15022. string = toString(string);
  15023. return (string && reHasRegExpChar.test(string))
  15024. ? string.replace(reRegExpChar, '\\$&')
  15025. : string;
  15026. }
  15027. /**
  15028. * Converts `string` to
  15029. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  15030. *
  15031. * @static
  15032. * @memberOf _
  15033. * @since 3.0.0
  15034. * @category String
  15035. * @param {string} [string=''] The string to convert.
  15036. * @returns {string} Returns the kebab cased string.
  15037. * @example
  15038. *
  15039. * _.kebabCase('Foo Bar');
  15040. * // => 'foo-bar'
  15041. *
  15042. * _.kebabCase('fooBar');
  15043. * // => 'foo-bar'
  15044. *
  15045. * _.kebabCase('__FOO_BAR__');
  15046. * // => 'foo-bar'
  15047. */
  15048. var kebabCase = createCompounder(function(result, word, index) {
  15049. return result + (index ? '-' : '') + word.toLowerCase();
  15050. });
  15051. /**
  15052. * Converts `string`, as space separated words, to lower case.
  15053. *
  15054. * @static
  15055. * @memberOf _
  15056. * @since 4.0.0
  15057. * @category String
  15058. * @param {string} [string=''] The string to convert.
  15059. * @returns {string} Returns the lower cased string.
  15060. * @example
  15061. *
  15062. * _.lowerCase('--Foo-Bar--');
  15063. * // => 'foo bar'
  15064. *
  15065. * _.lowerCase('fooBar');
  15066. * // => 'foo bar'
  15067. *
  15068. * _.lowerCase('__FOO_BAR__');
  15069. * // => 'foo bar'
  15070. */
  15071. var lowerCase = createCompounder(function(result, word, index) {
  15072. return result + (index ? ' ' : '') + word.toLowerCase();
  15073. });
  15074. /**
  15075. * Converts the first character of `string` to lower case.
  15076. *
  15077. * @static
  15078. * @memberOf _
  15079. * @since 4.0.0
  15080. * @category String
  15081. * @param {string} [string=''] The string to convert.
  15082. * @returns {string} Returns the converted string.
  15083. * @example
  15084. *
  15085. * _.lowerFirst('Fred');
  15086. * // => 'fred'
  15087. *
  15088. * _.lowerFirst('FRED');
  15089. * // => 'fRED'
  15090. */
  15091. var lowerFirst = createCaseFirst('toLowerCase');
  15092. /**
  15093. * Pads `string` on the left and right sides if it's shorter than `length`.
  15094. * Padding characters are truncated if they can't be evenly divided by `length`.
  15095. *
  15096. * @static
  15097. * @memberOf _
  15098. * @since 3.0.0
  15099. * @category String
  15100. * @param {string} [string=''] The string to pad.
  15101. * @param {number} [length=0] The padding length.
  15102. * @param {string} [chars=' '] The string used as padding.
  15103. * @returns {string} Returns the padded string.
  15104. * @example
  15105. *
  15106. * _.pad('abc', 8);
  15107. * // => ' abc '
  15108. *
  15109. * _.pad('abc', 8, '_-');
  15110. * // => '_-abc_-_'
  15111. *
  15112. * _.pad('abc', 3);
  15113. * // => 'abc'
  15114. */
  15115. function pad(string, length, chars) {
  15116. string = toString(string);
  15117. length = toInteger(length);
  15118. var strLength = length ? stringSize(string) : 0;
  15119. if (!length || strLength >= length) {
  15120. return string;
  15121. }
  15122. var mid = (length - strLength) / 2;
  15123. return (
  15124. createPadding(nativeFloor(mid), chars) +
  15125. string +
  15126. createPadding(nativeCeil(mid), chars)
  15127. );
  15128. }
  15129. /**
  15130. * Pads `string` on the right side if it's shorter than `length`. Padding
  15131. * characters are truncated if they exceed `length`.
  15132. *
  15133. * @static
  15134. * @memberOf _
  15135. * @since 4.0.0
  15136. * @category String
  15137. * @param {string} [string=''] The string to pad.
  15138. * @param {number} [length=0] The padding length.
  15139. * @param {string} [chars=' '] The string used as padding.
  15140. * @returns {string} Returns the padded string.
  15141. * @example
  15142. *
  15143. * _.padEnd('abc', 6);
  15144. * // => 'abc '
  15145. *
  15146. * _.padEnd('abc', 6, '_-');
  15147. * // => 'abc_-_'
  15148. *
  15149. * _.padEnd('abc', 3);
  15150. * // => 'abc'
  15151. */
  15152. function padEnd(string, length, chars) {
  15153. string = toString(string);
  15154. length = toInteger(length);
  15155. var strLength = length ? stringSize(string) : 0;
  15156. return (length && strLength < length)
  15157. ? (string + createPadding(length - strLength, chars))
  15158. : string;
  15159. }
  15160. /**
  15161. * Pads `string` on the left side if it's shorter than `length`. Padding
  15162. * characters are truncated if they exceed `length`.
  15163. *
  15164. * @static
  15165. * @memberOf _
  15166. * @since 4.0.0
  15167. * @category String
  15168. * @param {string} [string=''] The string to pad.
  15169. * @param {number} [length=0] The padding length.
  15170. * @param {string} [chars=' '] The string used as padding.
  15171. * @returns {string} Returns the padded string.
  15172. * @example
  15173. *
  15174. * _.padStart('abc', 6);
  15175. * // => ' abc'
  15176. *
  15177. * _.padStart('abc', 6, '_-');
  15178. * // => '_-_abc'
  15179. *
  15180. * _.padStart('abc', 3);
  15181. * // => 'abc'
  15182. */
  15183. function padStart(string, length, chars) {
  15184. string = toString(string);
  15185. length = toInteger(length);
  15186. var strLength = length ? stringSize(string) : 0;
  15187. return (length && strLength < length)
  15188. ? (createPadding(length - strLength, chars) + string)
  15189. : string;
  15190. }
  15191. /**
  15192. * Converts `string` to an integer of the specified radix. If `radix` is
  15193. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  15194. * hexadecimal, in which case a `radix` of `16` is used.
  15195. *
  15196. * **Note:** This method aligns with the
  15197. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  15198. *
  15199. * @static
  15200. * @memberOf _
  15201. * @since 1.1.0
  15202. * @category String
  15203. * @param {string} string The string to convert.
  15204. * @param {number} [radix=10] The radix to interpret `value` by.
  15205. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15206. * @returns {number} Returns the converted integer.
  15207. * @example
  15208. *
  15209. * _.parseInt('08');
  15210. * // => 8
  15211. *
  15212. * _.map(['6', '08', '10'], _.parseInt);
  15213. * // => [6, 8, 10]
  15214. */
  15215. function parseInt(string, radix, guard) {
  15216. if (guard || radix == null) {
  15217. radix = 0;
  15218. } else if (radix) {
  15219. radix = +radix;
  15220. }
  15221. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  15222. }
  15223. /**
  15224. * Repeats the given string `n` times.
  15225. *
  15226. * @static
  15227. * @memberOf _
  15228. * @since 3.0.0
  15229. * @category String
  15230. * @param {string} [string=''] The string to repeat.
  15231. * @param {number} [n=1] The number of times to repeat the string.
  15232. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15233. * @returns {string} Returns the repeated string.
  15234. * @example
  15235. *
  15236. * _.repeat('*', 3);
  15237. * // => '***'
  15238. *
  15239. * _.repeat('abc', 2);
  15240. * // => 'abcabc'
  15241. *
  15242. * _.repeat('abc', 0);
  15243. * // => ''
  15244. */
  15245. function repeat(string, n, guard) {
  15246. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  15247. n = 1;
  15248. } else {
  15249. n = toInteger(n);
  15250. }
  15251. return baseRepeat(toString(string), n);
  15252. }
  15253. /**
  15254. * Replaces matches for `pattern` in `string` with `replacement`.
  15255. *
  15256. * **Note:** This method is based on
  15257. * [`String#replace`](https://mdn.io/String/replace).
  15258. *
  15259. * @static
  15260. * @memberOf _
  15261. * @since 4.0.0
  15262. * @category String
  15263. * @param {string} [string=''] The string to modify.
  15264. * @param {RegExp|string} pattern The pattern to replace.
  15265. * @param {Function|string} replacement The match replacement.
  15266. * @returns {string} Returns the modified string.
  15267. * @example
  15268. *
  15269. * _.replace('Hi Fred', 'Fred', 'Barney');
  15270. * // => 'Hi Barney'
  15271. */
  15272. function replace() {
  15273. var args = arguments,
  15274. string = toString(args[0]);
  15275. return args.length < 3 ? string : string.replace(args[1], args[2]);
  15276. }
  15277. /**
  15278. * Converts `string` to
  15279. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  15280. *
  15281. * @static
  15282. * @memberOf _
  15283. * @since 3.0.0
  15284. * @category String
  15285. * @param {string} [string=''] The string to convert.
  15286. * @returns {string} Returns the snake cased string.
  15287. * @example
  15288. *
  15289. * _.snakeCase('Foo Bar');
  15290. * // => 'foo_bar'
  15291. *
  15292. * _.snakeCase('fooBar');
  15293. * // => 'foo_bar'
  15294. *
  15295. * _.snakeCase('--FOO-BAR--');
  15296. * // => 'foo_bar'
  15297. */
  15298. var snakeCase = createCompounder(function(result, word, index) {
  15299. return result + (index ? '_' : '') + word.toLowerCase();
  15300. });
  15301. /**
  15302. * Splits `string` by `separator`.
  15303. *
  15304. * **Note:** This method is based on
  15305. * [`String#split`](https://mdn.io/String/split).
  15306. *
  15307. * @static
  15308. * @memberOf _
  15309. * @since 4.0.0
  15310. * @category String
  15311. * @param {string} [string=''] The string to split.
  15312. * @param {RegExp|string} separator The separator pattern to split by.
  15313. * @param {number} [limit] The length to truncate results to.
  15314. * @returns {Array} Returns the string segments.
  15315. * @example
  15316. *
  15317. * _.split('a-b-c', '-', 2);
  15318. * // => ['a', 'b']
  15319. */
  15320. function split(string, separator, limit) {
  15321. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  15322. separator = limit = undefined;
  15323. }
  15324. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  15325. if (!limit) {
  15326. return [];
  15327. }
  15328. string = toString(string);
  15329. if (string && (
  15330. typeof separator == 'string' ||
  15331. (separator != null && !isRegExp(separator))
  15332. )) {
  15333. separator = baseToString(separator);
  15334. if (!separator && hasUnicode(string)) {
  15335. return castSlice(stringToArray(string), 0, limit);
  15336. }
  15337. }
  15338. return string.split(separator, limit);
  15339. }
  15340. /**
  15341. * Converts `string` to
  15342. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  15343. *
  15344. * @static
  15345. * @memberOf _
  15346. * @since 3.1.0
  15347. * @category String
  15348. * @param {string} [string=''] The string to convert.
  15349. * @returns {string} Returns the start cased string.
  15350. * @example
  15351. *
  15352. * _.startCase('--foo-bar--');
  15353. * // => 'Foo Bar'
  15354. *
  15355. * _.startCase('fooBar');
  15356. * // => 'Foo Bar'
  15357. *
  15358. * _.startCase('__FOO_BAR__');
  15359. * // => 'FOO BAR'
  15360. */
  15361. var startCase = createCompounder(function(result, word, index) {
  15362. return result + (index ? ' ' : '') + upperFirst(word);
  15363. });
  15364. /**
  15365. * Checks if `string` starts with the given target string.
  15366. *
  15367. * @static
  15368. * @memberOf _
  15369. * @since 3.0.0
  15370. * @category String
  15371. * @param {string} [string=''] The string to inspect.
  15372. * @param {string} [target] The string to search for.
  15373. * @param {number} [position=0] The position to search from.
  15374. * @returns {boolean} Returns `true` if `string` starts with `target`,
  15375. * else `false`.
  15376. * @example
  15377. *
  15378. * _.startsWith('abc', 'a');
  15379. * // => true
  15380. *
  15381. * _.startsWith('abc', 'b');
  15382. * // => false
  15383. *
  15384. * _.startsWith('abc', 'b', 1);
  15385. * // => true
  15386. */
  15387. function startsWith(string, target, position) {
  15388. string = toString(string);
  15389. position = position == null
  15390. ? 0
  15391. : baseClamp(toInteger(position), 0, string.length);
  15392. target = baseToString(target);
  15393. return string.slice(position, position + target.length) == target;
  15394. }
  15395. /**
  15396. * Creates a compiled template function that can interpolate data properties
  15397. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  15398. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  15399. * properties may be accessed as free variables in the template. If a setting
  15400. * object is given, it takes precedence over `_.templateSettings` values.
  15401. *
  15402. * **Note:** In the development build `_.template` utilizes
  15403. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  15404. * for easier debugging.
  15405. *
  15406. * For more information on precompiling templates see
  15407. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  15408. *
  15409. * For more information on Chrome extension sandboxes see
  15410. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  15411. *
  15412. * @static
  15413. * @since 0.1.0
  15414. * @memberOf _
  15415. * @category String
  15416. * @param {string} [string=''] The template string.
  15417. * @param {Object} [options={}] The options object.
  15418. * @param {RegExp} [options.escape=_.templateSettings.escape]
  15419. * The HTML "escape" delimiter.
  15420. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  15421. * The "evaluate" delimiter.
  15422. * @param {Object} [options.imports=_.templateSettings.imports]
  15423. * An object to import into the template as free variables.
  15424. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  15425. * The "interpolate" delimiter.
  15426. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  15427. * The sourceURL of the compiled template.
  15428. * @param {string} [options.variable='obj']
  15429. * The data object variable name.
  15430. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15431. * @returns {Function} Returns the compiled template function.
  15432. * @example
  15433. *
  15434. * // Use the "interpolate" delimiter to create a compiled template.
  15435. * var compiled = _.template('hello <%= user %>!');
  15436. * compiled({ 'user': 'fred' });
  15437. * // => 'hello fred!'
  15438. *
  15439. * // Use the HTML "escape" delimiter to escape data property values.
  15440. * var compiled = _.template('<b><%- value %></b>');
  15441. * compiled({ 'value': '<script>' });
  15442. * // => '<b>&lt;script&gt;</b>'
  15443. *
  15444. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  15445. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  15446. * compiled({ 'users': ['fred', 'barney'] });
  15447. * // => '<li>fred</li><li>barney</li>'
  15448. *
  15449. * // Use the internal `print` function in "evaluate" delimiters.
  15450. * var compiled = _.template('<% print("hello " + user); %>!');
  15451. * compiled({ 'user': 'barney' });
  15452. * // => 'hello barney!'
  15453. *
  15454. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  15455. * // Disable support by replacing the "interpolate" delimiter.
  15456. * var compiled = _.template('hello ${ user }!');
  15457. * compiled({ 'user': 'pebbles' });
  15458. * // => 'hello pebbles!'
  15459. *
  15460. * // Use backslashes to treat delimiters as plain text.
  15461. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  15462. * compiled({ 'value': 'ignored' });
  15463. * // => '<%- value %>'
  15464. *
  15465. * // Use the `imports` option to import `jQuery` as `jq`.
  15466. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  15467. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  15468. * compiled({ 'users': ['fred', 'barney'] });
  15469. * // => '<li>fred</li><li>barney</li>'
  15470. *
  15471. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  15472. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  15473. * compiled(data);
  15474. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  15475. *
  15476. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  15477. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  15478. * compiled.source;
  15479. * // => function(data) {
  15480. * // var __t, __p = '';
  15481. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  15482. * // return __p;
  15483. * // }
  15484. *
  15485. * // Use custom template delimiters.
  15486. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  15487. * var compiled = _.template('hello {{ user }}!');
  15488. * compiled({ 'user': 'mustache' });
  15489. * // => 'hello mustache!'
  15490. *
  15491. * // Use the `source` property to inline compiled templates for meaningful
  15492. * // line numbers in error messages and stack traces.
  15493. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  15494. * var JST = {\
  15495. * "main": ' + _.template(mainText).source + '\
  15496. * };\
  15497. * ');
  15498. */
  15499. function template(string, options, guard) {
  15500. // Based on John Resig's `tmpl` implementation
  15501. // (http://ejohn.org/blog/javascript-micro-templating/)
  15502. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  15503. var settings = lodash.templateSettings;
  15504. if (guard && isIterateeCall(string, options, guard)) {
  15505. options = undefined;
  15506. }
  15507. string = toString(string);
  15508. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  15509. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  15510. importsKeys = keys(imports),
  15511. importsValues = baseValues(imports, importsKeys);
  15512. var isEscaping,
  15513. isEvaluating,
  15514. index = 0,
  15515. interpolate = options.interpolate || reNoMatch,
  15516. source = "__p += '";
  15517. // Compile the regexp to match each delimiter.
  15518. var reDelimiters = RegExp(
  15519. (options.escape || reNoMatch).source + '|' +
  15520. interpolate.source + '|' +
  15521. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  15522. (options.evaluate || reNoMatch).source + '|$'
  15523. , 'g');
  15524. // Use a sourceURL for easier debugging.
  15525. // The sourceURL gets injected into the source that's eval-ed, so be careful
  15526. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  15527. // and escape the comment, thus injecting code that gets evaled.
  15528. var sourceURL = '//# sourceURL=' +
  15529. (hasOwnProperty.call(options, 'sourceURL')
  15530. ? (options.sourceURL + '').replace(/\s/g, ' ')
  15531. : ('lodash.templateSources[' + (++templateCounter) + ']')
  15532. ) + '\n';
  15533. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  15534. interpolateValue || (interpolateValue = esTemplateValue);
  15535. // Escape characters that can't be included in string literals.
  15536. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  15537. // Replace delimiters with snippets.
  15538. if (escapeValue) {
  15539. isEscaping = true;
  15540. source += "' +\n__e(" + escapeValue + ") +\n'";
  15541. }
  15542. if (evaluateValue) {
  15543. isEvaluating = true;
  15544. source += "';\n" + evaluateValue + ";\n__p += '";
  15545. }
  15546. if (interpolateValue) {
  15547. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  15548. }
  15549. index = offset + match.length;
  15550. // The JS engine embedded in Adobe products needs `match` returned in
  15551. // order to produce the correct `offset` value.
  15552. return match;
  15553. });
  15554. source += "';\n";
  15555. // If `variable` is not specified wrap a with-statement around the generated
  15556. // code to add the data object to the top of the scope chain.
  15557. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  15558. if (!variable) {
  15559. source = 'with (obj) {\n' + source + '\n}\n';
  15560. }
  15561. // Throw an error if a forbidden character was found in `variable`, to prevent
  15562. // potential command injection attacks.
  15563. else if (reForbiddenIdentifierChars.test(variable)) {
  15564. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  15565. }
  15566. // Cleanup code by stripping empty strings.
  15567. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  15568. .replace(reEmptyStringMiddle, '$1')
  15569. .replace(reEmptyStringTrailing, '$1;');
  15570. // Frame code as the function body.
  15571. source = 'function(' + (variable || 'obj') + ') {\n' +
  15572. (variable
  15573. ? ''
  15574. : 'obj || (obj = {});\n'
  15575. ) +
  15576. "var __t, __p = ''" +
  15577. (isEscaping
  15578. ? ', __e = _.escape'
  15579. : ''
  15580. ) +
  15581. (isEvaluating
  15582. ? ', __j = Array.prototype.join;\n' +
  15583. "function print() { __p += __j.call(arguments, '') }\n"
  15584. : ';\n'
  15585. ) +
  15586. source +
  15587. 'return __p\n}';
  15588. var result = attempt(function() {
  15589. return Function(importsKeys, sourceURL + 'return ' + source)
  15590. .apply(undefined, importsValues);
  15591. });
  15592. // Provide the compiled function's source by its `toString` method or
  15593. // the `source` property as a convenience for inlining compiled templates.
  15594. result.source = source;
  15595. if (isError(result)) {
  15596. throw result;
  15597. }
  15598. return result;
  15599. }
  15600. /**
  15601. * Converts `string`, as a whole, to lower case just like
  15602. * [String#toLowerCase](https://mdn.io/toLowerCase).
  15603. *
  15604. * @static
  15605. * @memberOf _
  15606. * @since 4.0.0
  15607. * @category String
  15608. * @param {string} [string=''] The string to convert.
  15609. * @returns {string} Returns the lower cased string.
  15610. * @example
  15611. *
  15612. * _.toLower('--Foo-Bar--');
  15613. * // => '--foo-bar--'
  15614. *
  15615. * _.toLower('fooBar');
  15616. * // => 'foobar'
  15617. *
  15618. * _.toLower('__FOO_BAR__');
  15619. * // => '__foo_bar__'
  15620. */
  15621. function toLower(value) {
  15622. return toString(value).toLowerCase();
  15623. }
  15624. /**
  15625. * Converts `string`, as a whole, to upper case just like
  15626. * [String#toUpperCase](https://mdn.io/toUpperCase).
  15627. *
  15628. * @static
  15629. * @memberOf _
  15630. * @since 4.0.0
  15631. * @category String
  15632. * @param {string} [string=''] The string to convert.
  15633. * @returns {string} Returns the upper cased string.
  15634. * @example
  15635. *
  15636. * _.toUpper('--foo-bar--');
  15637. * // => '--FOO-BAR--'
  15638. *
  15639. * _.toUpper('fooBar');
  15640. * // => 'FOOBAR'
  15641. *
  15642. * _.toUpper('__foo_bar__');
  15643. * // => '__FOO_BAR__'
  15644. */
  15645. function toUpper(value) {
  15646. return toString(value).toUpperCase();
  15647. }
  15648. /**
  15649. * Removes leading and trailing whitespace or specified characters from `string`.
  15650. *
  15651. * @static
  15652. * @memberOf _
  15653. * @since 3.0.0
  15654. * @category String
  15655. * @param {string} [string=''] The string to trim.
  15656. * @param {string} [chars=whitespace] The characters to trim.
  15657. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15658. * @returns {string} Returns the trimmed string.
  15659. * @example
  15660. *
  15661. * _.trim(' abc ');
  15662. * // => 'abc'
  15663. *
  15664. * _.trim('-_-abc-_-', '_-');
  15665. * // => 'abc'
  15666. *
  15667. * _.map([' foo ', ' bar '], _.trim);
  15668. * // => ['foo', 'bar']
  15669. */
  15670. function trim(string, chars, guard) {
  15671. string = toString(string);
  15672. if (string && (guard || chars === undefined)) {
  15673. return baseTrim(string);
  15674. }
  15675. if (!string || !(chars = baseToString(chars))) {
  15676. return string;
  15677. }
  15678. var strSymbols = stringToArray(string),
  15679. chrSymbols = stringToArray(chars),
  15680. start = charsStartIndex(strSymbols, chrSymbols),
  15681. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  15682. return castSlice(strSymbols, start, end).join('');
  15683. }
  15684. /**
  15685. * Removes trailing whitespace or specified characters from `string`.
  15686. *
  15687. * @static
  15688. * @memberOf _
  15689. * @since 4.0.0
  15690. * @category String
  15691. * @param {string} [string=''] The string to trim.
  15692. * @param {string} [chars=whitespace] The characters to trim.
  15693. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15694. * @returns {string} Returns the trimmed string.
  15695. * @example
  15696. *
  15697. * _.trimEnd(' abc ');
  15698. * // => ' abc'
  15699. *
  15700. * _.trimEnd('-_-abc-_-', '_-');
  15701. * // => '-_-abc'
  15702. */
  15703. function trimEnd(string, chars, guard) {
  15704. string = toString(string);
  15705. if (string && (guard || chars === undefined)) {
  15706. return string.slice(0, trimmedEndIndex(string) + 1);
  15707. }
  15708. if (!string || !(chars = baseToString(chars))) {
  15709. return string;
  15710. }
  15711. var strSymbols = stringToArray(string),
  15712. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  15713. return castSlice(strSymbols, 0, end).join('');
  15714. }
  15715. /**
  15716. * Removes leading whitespace or specified characters from `string`.
  15717. *
  15718. * @static
  15719. * @memberOf _
  15720. * @since 4.0.0
  15721. * @category String
  15722. * @param {string} [string=''] The string to trim.
  15723. * @param {string} [chars=whitespace] The characters to trim.
  15724. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15725. * @returns {string} Returns the trimmed string.
  15726. * @example
  15727. *
  15728. * _.trimStart(' abc ');
  15729. * // => 'abc '
  15730. *
  15731. * _.trimStart('-_-abc-_-', '_-');
  15732. * // => 'abc-_-'
  15733. */
  15734. function trimStart(string, chars, guard) {
  15735. string = toString(string);
  15736. if (string && (guard || chars === undefined)) {
  15737. return string.replace(reTrimStart, '');
  15738. }
  15739. if (!string || !(chars = baseToString(chars))) {
  15740. return string;
  15741. }
  15742. var strSymbols = stringToArray(string),
  15743. start = charsStartIndex(strSymbols, stringToArray(chars));
  15744. return castSlice(strSymbols, start).join('');
  15745. }
  15746. /**
  15747. * Truncates `string` if it's longer than the given maximum string length.
  15748. * The last characters of the truncated string are replaced with the omission
  15749. * string which defaults to "...".
  15750. *
  15751. * @static
  15752. * @memberOf _
  15753. * @since 4.0.0
  15754. * @category String
  15755. * @param {string} [string=''] The string to truncate.
  15756. * @param {Object} [options={}] The options object.
  15757. * @param {number} [options.length=30] The maximum string length.
  15758. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  15759. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  15760. * @returns {string} Returns the truncated string.
  15761. * @example
  15762. *
  15763. * _.truncate('hi-diddly-ho there, neighborino');
  15764. * // => 'hi-diddly-ho there, neighbo...'
  15765. *
  15766. * _.truncate('hi-diddly-ho there, neighborino', {
  15767. * 'length': 24,
  15768. * 'separator': ' '
  15769. * });
  15770. * // => 'hi-diddly-ho there,...'
  15771. *
  15772. * _.truncate('hi-diddly-ho there, neighborino', {
  15773. * 'length': 24,
  15774. * 'separator': /,? +/
  15775. * });
  15776. * // => 'hi-diddly-ho there...'
  15777. *
  15778. * _.truncate('hi-diddly-ho there, neighborino', {
  15779. * 'omission': ' [...]'
  15780. * });
  15781. * // => 'hi-diddly-ho there, neig [...]'
  15782. */
  15783. function truncate(string, options) {
  15784. var length = DEFAULT_TRUNC_LENGTH,
  15785. omission = DEFAULT_TRUNC_OMISSION;
  15786. if (isObject(options)) {
  15787. var separator = 'separator' in options ? options.separator : separator;
  15788. length = 'length' in options ? toInteger(options.length) : length;
  15789. omission = 'omission' in options ? baseToString(options.omission) : omission;
  15790. }
  15791. string = toString(string);
  15792. var strLength = string.length;
  15793. if (hasUnicode(string)) {
  15794. var strSymbols = stringToArray(string);
  15795. strLength = strSymbols.length;
  15796. }
  15797. if (length >= strLength) {
  15798. return string;
  15799. }
  15800. var end = length - stringSize(omission);
  15801. if (end < 1) {
  15802. return omission;
  15803. }
  15804. var result = strSymbols
  15805. ? castSlice(strSymbols, 0, end).join('')
  15806. : string.slice(0, end);
  15807. if (separator === undefined) {
  15808. return result + omission;
  15809. }
  15810. if (strSymbols) {
  15811. end += (result.length - end);
  15812. }
  15813. if (isRegExp(separator)) {
  15814. if (string.slice(end).search(separator)) {
  15815. var match,
  15816. substring = result;
  15817. if (!separator.global) {
  15818. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  15819. }
  15820. separator.lastIndex = 0;
  15821. while ((match = separator.exec(substring))) {
  15822. var newEnd = match.index;
  15823. }
  15824. result = result.slice(0, newEnd === undefined ? end : newEnd);
  15825. }
  15826. } else if (string.indexOf(baseToString(separator), end) != end) {
  15827. var index = result.lastIndexOf(separator);
  15828. if (index > -1) {
  15829. result = result.slice(0, index);
  15830. }
  15831. }
  15832. return result + omission;
  15833. }
  15834. /**
  15835. * The inverse of `_.escape`; this method converts the HTML entities
  15836. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  15837. * their corresponding characters.
  15838. *
  15839. * **Note:** No other HTML entities are unescaped. To unescape additional
  15840. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  15841. *
  15842. * @static
  15843. * @memberOf _
  15844. * @since 0.6.0
  15845. * @category String
  15846. * @param {string} [string=''] The string to unescape.
  15847. * @returns {string} Returns the unescaped string.
  15848. * @example
  15849. *
  15850. * _.unescape('fred, barney, &amp; pebbles');
  15851. * // => 'fred, barney, & pebbles'
  15852. */
  15853. function unescape(string) {
  15854. string = toString(string);
  15855. return (string && reHasEscapedHtml.test(string))
  15856. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  15857. : string;
  15858. }
  15859. /**
  15860. * Converts `string`, as space separated words, to upper case.
  15861. *
  15862. * @static
  15863. * @memberOf _
  15864. * @since 4.0.0
  15865. * @category String
  15866. * @param {string} [string=''] The string to convert.
  15867. * @returns {string} Returns the upper cased string.
  15868. * @example
  15869. *
  15870. * _.upperCase('--foo-bar');
  15871. * // => 'FOO BAR'
  15872. *
  15873. * _.upperCase('fooBar');
  15874. * // => 'FOO BAR'
  15875. *
  15876. * _.upperCase('__foo_bar__');
  15877. * // => 'FOO BAR'
  15878. */
  15879. var upperCase = createCompounder(function(result, word, index) {
  15880. return result + (index ? ' ' : '') + word.toUpperCase();
  15881. });
  15882. /**
  15883. * Converts the first character of `string` to upper case.
  15884. *
  15885. * @static
  15886. * @memberOf _
  15887. * @since 4.0.0
  15888. * @category String
  15889. * @param {string} [string=''] The string to convert.
  15890. * @returns {string} Returns the converted string.
  15891. * @example
  15892. *
  15893. * _.upperFirst('fred');
  15894. * // => 'Fred'
  15895. *
  15896. * _.upperFirst('FRED');
  15897. * // => 'FRED'
  15898. */
  15899. var upperFirst = createCaseFirst('toUpperCase');
  15900. /**
  15901. * Splits `string` into an array of its words.
  15902. *
  15903. * @static
  15904. * @memberOf _
  15905. * @since 3.0.0
  15906. * @category String
  15907. * @param {string} [string=''] The string to inspect.
  15908. * @param {RegExp|string} [pattern] The pattern to match words.
  15909. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  15910. * @returns {Array} Returns the words of `string`.
  15911. * @example
  15912. *
  15913. * _.words('fred, barney, & pebbles');
  15914. * // => ['fred', 'barney', 'pebbles']
  15915. *
  15916. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  15917. * // => ['fred', 'barney', '&', 'pebbles']
  15918. */
  15919. function words(string, pattern, guard) {
  15920. string = toString(string);
  15921. pattern = guard ? undefined : pattern;
  15922. if (pattern === undefined) {
  15923. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  15924. }
  15925. return string.match(pattern) || [];
  15926. }
  15927. /*------------------------------------------------------------------------*/
  15928. /**
  15929. * Attempts to invoke `func`, returning either the result or the caught error
  15930. * object. Any additional arguments are provided to `func` when it's invoked.
  15931. *
  15932. * @static
  15933. * @memberOf _
  15934. * @since 3.0.0
  15935. * @category Util
  15936. * @param {Function} func The function to attempt.
  15937. * @param {...*} [args] The arguments to invoke `func` with.
  15938. * @returns {*} Returns the `func` result or error object.
  15939. * @example
  15940. *
  15941. * // Avoid throwing errors for invalid selectors.
  15942. * var elements = _.attempt(function(selector) {
  15943. * return document.querySelectorAll(selector);
  15944. * }, '>_>');
  15945. *
  15946. * if (_.isError(elements)) {
  15947. * elements = [];
  15948. * }
  15949. */
  15950. var attempt = baseRest(function(func, args) {
  15951. try {
  15952. return apply(func, undefined, args);
  15953. } catch (e) {
  15954. return isError(e) ? e : new Error(e);
  15955. }
  15956. });
  15957. /**
  15958. * Binds methods of an object to the object itself, overwriting the existing
  15959. * method.
  15960. *
  15961. * **Note:** This method doesn't set the "length" property of bound functions.
  15962. *
  15963. * @static
  15964. * @since 0.1.0
  15965. * @memberOf _
  15966. * @category Util
  15967. * @param {Object} object The object to bind and assign the bound methods to.
  15968. * @param {...(string|string[])} methodNames The object method names to bind.
  15969. * @returns {Object} Returns `object`.
  15970. * @example
  15971. *
  15972. * var view = {
  15973. * 'label': 'docs',
  15974. * 'click': function() {
  15975. * console.log('clicked ' + this.label);
  15976. * }
  15977. * };
  15978. *
  15979. * _.bindAll(view, ['click']);
  15980. * jQuery(element).on('click', view.click);
  15981. * // => Logs 'clicked docs' when clicked.
  15982. */
  15983. var bindAll = flatRest(function(object, methodNames) {
  15984. arrayEach(methodNames, function(key) {
  15985. key = toKey(key);
  15986. baseAssignValue(object, key, bind(object[key], object));
  15987. });
  15988. return object;
  15989. });
  15990. /**
  15991. * Creates a function that iterates over `pairs` and invokes the corresponding
  15992. * function of the first predicate to return truthy. The predicate-function
  15993. * pairs are invoked with the `this` binding and arguments of the created
  15994. * function.
  15995. *
  15996. * @static
  15997. * @memberOf _
  15998. * @since 4.0.0
  15999. * @category Util
  16000. * @param {Array} pairs The predicate-function pairs.
  16001. * @returns {Function} Returns the new composite function.
  16002. * @example
  16003. *
  16004. * var func = _.cond([
  16005. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  16006. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  16007. * [_.stubTrue, _.constant('no match')]
  16008. * ]);
  16009. *
  16010. * func({ 'a': 1, 'b': 2 });
  16011. * // => 'matches A'
  16012. *
  16013. * func({ 'a': 0, 'b': 1 });
  16014. * // => 'matches B'
  16015. *
  16016. * func({ 'a': '1', 'b': '2' });
  16017. * // => 'no match'
  16018. */
  16019. function cond(pairs) {
  16020. var length = pairs == null ? 0 : pairs.length,
  16021. toIteratee = getIteratee();
  16022. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  16023. if (typeof pair[1] != 'function') {
  16024. throw new TypeError(FUNC_ERROR_TEXT);
  16025. }
  16026. return [toIteratee(pair[0]), pair[1]];
  16027. });
  16028. return baseRest(function(args) {
  16029. var index = -1;
  16030. while (++index < length) {
  16031. var pair = pairs[index];
  16032. if (apply(pair[0], this, args)) {
  16033. return apply(pair[1], this, args);
  16034. }
  16035. }
  16036. });
  16037. }
  16038. /**
  16039. * Creates a function that invokes the predicate properties of `source` with
  16040. * the corresponding property values of a given object, returning `true` if
  16041. * all predicates return truthy, else `false`.
  16042. *
  16043. * **Note:** The created function is equivalent to `_.conformsTo` with
  16044. * `source` partially applied.
  16045. *
  16046. * @static
  16047. * @memberOf _
  16048. * @since 4.0.0
  16049. * @category Util
  16050. * @param {Object} source The object of property predicates to conform to.
  16051. * @returns {Function} Returns the new spec function.
  16052. * @example
  16053. *
  16054. * var objects = [
  16055. * { 'a': 2, 'b': 1 },
  16056. * { 'a': 1, 'b': 2 }
  16057. * ];
  16058. *
  16059. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  16060. * // => [{ 'a': 1, 'b': 2 }]
  16061. */
  16062. function conforms(source) {
  16063. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  16064. }
  16065. /**
  16066. * Creates a function that returns `value`.
  16067. *
  16068. * @static
  16069. * @memberOf _
  16070. * @since 2.4.0
  16071. * @category Util
  16072. * @param {*} value The value to return from the new function.
  16073. * @returns {Function} Returns the new constant function.
  16074. * @example
  16075. *
  16076. * var objects = _.times(2, _.constant({ 'a': 1 }));
  16077. *
  16078. * console.log(objects);
  16079. * // => [{ 'a': 1 }, { 'a': 1 }]
  16080. *
  16081. * console.log(objects[0] === objects[1]);
  16082. * // => true
  16083. */
  16084. function constant(value) {
  16085. return function() {
  16086. return value;
  16087. };
  16088. }
  16089. /**
  16090. * Checks `value` to determine whether a default value should be returned in
  16091. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  16092. * or `undefined`.
  16093. *
  16094. * @static
  16095. * @memberOf _
  16096. * @since 4.14.0
  16097. * @category Util
  16098. * @param {*} value The value to check.
  16099. * @param {*} defaultValue The default value.
  16100. * @returns {*} Returns the resolved value.
  16101. * @example
  16102. *
  16103. * _.defaultTo(1, 10);
  16104. * // => 1
  16105. *
  16106. * _.defaultTo(undefined, 10);
  16107. * // => 10
  16108. */
  16109. function defaultTo(value, defaultValue) {
  16110. return (value == null || value !== value) ? defaultValue : value;
  16111. }
  16112. /**
  16113. * Creates a function that returns the result of invoking the given functions
  16114. * with the `this` binding of the created function, where each successive
  16115. * invocation is supplied the return value of the previous.
  16116. *
  16117. * @static
  16118. * @memberOf _
  16119. * @since 3.0.0
  16120. * @category Util
  16121. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  16122. * @returns {Function} Returns the new composite function.
  16123. * @see _.flowRight
  16124. * @example
  16125. *
  16126. * function square(n) {
  16127. * return n * n;
  16128. * }
  16129. *
  16130. * var addSquare = _.flow([_.add, square]);
  16131. * addSquare(1, 2);
  16132. * // => 9
  16133. */
  16134. var flow = createFlow();
  16135. /**
  16136. * This method is like `_.flow` except that it creates a function that
  16137. * invokes the given functions from right to left.
  16138. *
  16139. * @static
  16140. * @since 3.0.0
  16141. * @memberOf _
  16142. * @category Util
  16143. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  16144. * @returns {Function} Returns the new composite function.
  16145. * @see _.flow
  16146. * @example
  16147. *
  16148. * function square(n) {
  16149. * return n * n;
  16150. * }
  16151. *
  16152. * var addSquare = _.flowRight([square, _.add]);
  16153. * addSquare(1, 2);
  16154. * // => 9
  16155. */
  16156. var flowRight = createFlow(true);
  16157. /**
  16158. * This method returns the first argument it receives.
  16159. *
  16160. * @static
  16161. * @since 0.1.0
  16162. * @memberOf _
  16163. * @category Util
  16164. * @param {*} value Any value.
  16165. * @returns {*} Returns `value`.
  16166. * @example
  16167. *
  16168. * var object = { 'a': 1 };
  16169. *
  16170. * console.log(_.identity(object) === object);
  16171. * // => true
  16172. */
  16173. function identity(value) {
  16174. return value;
  16175. }
  16176. /**
  16177. * Creates a function that invokes `func` with the arguments of the created
  16178. * function. If `func` is a property name, the created function returns the
  16179. * property value for a given element. If `func` is an array or object, the
  16180. * created function returns `true` for elements that contain the equivalent
  16181. * source properties, otherwise it returns `false`.
  16182. *
  16183. * @static
  16184. * @since 4.0.0
  16185. * @memberOf _
  16186. * @category Util
  16187. * @param {*} [func=_.identity] The value to convert to a callback.
  16188. * @returns {Function} Returns the callback.
  16189. * @example
  16190. *
  16191. * var users = [
  16192. * { 'user': 'barney', 'age': 36, 'active': true },
  16193. * { 'user': 'fred', 'age': 40, 'active': false }
  16194. * ];
  16195. *
  16196. * // The `_.matches` iteratee shorthand.
  16197. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  16198. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  16199. *
  16200. * // The `_.matchesProperty` iteratee shorthand.
  16201. * _.filter(users, _.iteratee(['user', 'fred']));
  16202. * // => [{ 'user': 'fred', 'age': 40 }]
  16203. *
  16204. * // The `_.property` iteratee shorthand.
  16205. * _.map(users, _.iteratee('user'));
  16206. * // => ['barney', 'fred']
  16207. *
  16208. * // Create custom iteratee shorthands.
  16209. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  16210. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  16211. * return func.test(string);
  16212. * };
  16213. * });
  16214. *
  16215. * _.filter(['abc', 'def'], /ef/);
  16216. * // => ['def']
  16217. */
  16218. function iteratee(func) {
  16219. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  16220. }
  16221. /**
  16222. * Creates a function that performs a partial deep comparison between a given
  16223. * object and `source`, returning `true` if the given object has equivalent
  16224. * property values, else `false`.
  16225. *
  16226. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  16227. * partially applied.
  16228. *
  16229. * Partial comparisons will match empty array and empty object `source`
  16230. * values against any array or object value, respectively. See `_.isEqual`
  16231. * for a list of supported value comparisons.
  16232. *
  16233. * **Note:** Multiple values can be checked by combining several matchers
  16234. * using `_.overSome`
  16235. *
  16236. * @static
  16237. * @memberOf _
  16238. * @since 3.0.0
  16239. * @category Util
  16240. * @param {Object} source The object of property values to match.
  16241. * @returns {Function} Returns the new spec function.
  16242. * @example
  16243. *
  16244. * var objects = [
  16245. * { 'a': 1, 'b': 2, 'c': 3 },
  16246. * { 'a': 4, 'b': 5, 'c': 6 }
  16247. * ];
  16248. *
  16249. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  16250. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  16251. *
  16252. * // Checking for several possible values
  16253. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  16254. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  16255. */
  16256. function matches(source) {
  16257. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  16258. }
  16259. /**
  16260. * Creates a function that performs a partial deep comparison between the
  16261. * value at `path` of a given object to `srcValue`, returning `true` if the
  16262. * object value is equivalent, else `false`.
  16263. *
  16264. * **Note:** Partial comparisons will match empty array and empty object
  16265. * `srcValue` values against any array or object value, respectively. See
  16266. * `_.isEqual` for a list of supported value comparisons.
  16267. *
  16268. * **Note:** Multiple values can be checked by combining several matchers
  16269. * using `_.overSome`
  16270. *
  16271. * @static
  16272. * @memberOf _
  16273. * @since 3.2.0
  16274. * @category Util
  16275. * @param {Array|string} path The path of the property to get.
  16276. * @param {*} srcValue The value to match.
  16277. * @returns {Function} Returns the new spec function.
  16278. * @example
  16279. *
  16280. * var objects = [
  16281. * { 'a': 1, 'b': 2, 'c': 3 },
  16282. * { 'a': 4, 'b': 5, 'c': 6 }
  16283. * ];
  16284. *
  16285. * _.find(objects, _.matchesProperty('a', 4));
  16286. * // => { 'a': 4, 'b': 5, 'c': 6 }
  16287. *
  16288. * // Checking for several possible values
  16289. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  16290. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  16291. */
  16292. function matchesProperty(path, srcValue) {
  16293. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  16294. }
  16295. /**
  16296. * Creates a function that invokes the method at `path` of a given object.
  16297. * Any additional arguments are provided to the invoked method.
  16298. *
  16299. * @static
  16300. * @memberOf _
  16301. * @since 3.7.0
  16302. * @category Util
  16303. * @param {Array|string} path The path of the method to invoke.
  16304. * @param {...*} [args] The arguments to invoke the method with.
  16305. * @returns {Function} Returns the new invoker function.
  16306. * @example
  16307. *
  16308. * var objects = [
  16309. * { 'a': { 'b': _.constant(2) } },
  16310. * { 'a': { 'b': _.constant(1) } }
  16311. * ];
  16312. *
  16313. * _.map(objects, _.method('a.b'));
  16314. * // => [2, 1]
  16315. *
  16316. * _.map(objects, _.method(['a', 'b']));
  16317. * // => [2, 1]
  16318. */
  16319. var method = baseRest(function(path, args) {
  16320. return function(object) {
  16321. return baseInvoke(object, path, args);
  16322. };
  16323. });
  16324. /**
  16325. * The opposite of `_.method`; this method creates a function that invokes
  16326. * the method at a given path of `object`. Any additional arguments are
  16327. * provided to the invoked method.
  16328. *
  16329. * @static
  16330. * @memberOf _
  16331. * @since 3.7.0
  16332. * @category Util
  16333. * @param {Object} object The object to query.
  16334. * @param {...*} [args] The arguments to invoke the method with.
  16335. * @returns {Function} Returns the new invoker function.
  16336. * @example
  16337. *
  16338. * var array = _.times(3, _.constant),
  16339. * object = { 'a': array, 'b': array, 'c': array };
  16340. *
  16341. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  16342. * // => [2, 0]
  16343. *
  16344. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  16345. * // => [2, 0]
  16346. */
  16347. var methodOf = baseRest(function(object, args) {
  16348. return function(path) {
  16349. return baseInvoke(object, path, args);
  16350. };
  16351. });
  16352. /**
  16353. * Adds all own enumerable string keyed function properties of a source
  16354. * object to the destination object. If `object` is a function, then methods
  16355. * are added to its prototype as well.
  16356. *
  16357. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  16358. * avoid conflicts caused by modifying the original.
  16359. *
  16360. * @static
  16361. * @since 0.1.0
  16362. * @memberOf _
  16363. * @category Util
  16364. * @param {Function|Object} [object=lodash] The destination object.
  16365. * @param {Object} source The object of functions to add.
  16366. * @param {Object} [options={}] The options object.
  16367. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  16368. * @returns {Function|Object} Returns `object`.
  16369. * @example
  16370. *
  16371. * function vowels(string) {
  16372. * return _.filter(string, function(v) {
  16373. * return /[aeiou]/i.test(v);
  16374. * });
  16375. * }
  16376. *
  16377. * _.mixin({ 'vowels': vowels });
  16378. * _.vowels('fred');
  16379. * // => ['e']
  16380. *
  16381. * _('fred').vowels().value();
  16382. * // => ['e']
  16383. *
  16384. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  16385. * _('fred').vowels();
  16386. * // => ['e']
  16387. */
  16388. function mixin(object, source, options) {
  16389. var props = keys(source),
  16390. methodNames = baseFunctions(source, props);
  16391. if (options == null &&
  16392. !(isObject(source) && (methodNames.length || !props.length))) {
  16393. options = source;
  16394. source = object;
  16395. object = this;
  16396. methodNames = baseFunctions(source, keys(source));
  16397. }
  16398. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  16399. isFunc = isFunction(object);
  16400. arrayEach(methodNames, function(methodName) {
  16401. var func = source[methodName];
  16402. object[methodName] = func;
  16403. if (isFunc) {
  16404. object.prototype[methodName] = function() {
  16405. var chainAll = this.__chain__;
  16406. if (chain || chainAll) {
  16407. var result = object(this.__wrapped__),
  16408. actions = result.__actions__ = copyArray(this.__actions__);
  16409. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  16410. result.__chain__ = chainAll;
  16411. return result;
  16412. }
  16413. return func.apply(object, arrayPush([this.value()], arguments));
  16414. };
  16415. }
  16416. });
  16417. return object;
  16418. }
  16419. /**
  16420. * Reverts the `_` variable to its previous value and returns a reference to
  16421. * the `lodash` function.
  16422. *
  16423. * @static
  16424. * @since 0.1.0
  16425. * @memberOf _
  16426. * @category Util
  16427. * @returns {Function} Returns the `lodash` function.
  16428. * @example
  16429. *
  16430. * var lodash = _.noConflict();
  16431. */
  16432. function noConflict() {
  16433. if (root._ === this) {
  16434. root._ = oldDash;
  16435. }
  16436. return this;
  16437. }
  16438. /**
  16439. * This method returns `undefined`.
  16440. *
  16441. * @static
  16442. * @memberOf _
  16443. * @since 2.3.0
  16444. * @category Util
  16445. * @example
  16446. *
  16447. * _.times(2, _.noop);
  16448. * // => [undefined, undefined]
  16449. */
  16450. function noop() {
  16451. // No operation performed.
  16452. }
  16453. /**
  16454. * Creates a function that gets the argument at index `n`. If `n` is negative,
  16455. * the nth argument from the end is returned.
  16456. *
  16457. * @static
  16458. * @memberOf _
  16459. * @since 4.0.0
  16460. * @category Util
  16461. * @param {number} [n=0] The index of the argument to return.
  16462. * @returns {Function} Returns the new pass-thru function.
  16463. * @example
  16464. *
  16465. * var func = _.nthArg(1);
  16466. * func('a', 'b', 'c', 'd');
  16467. * // => 'b'
  16468. *
  16469. * var func = _.nthArg(-2);
  16470. * func('a', 'b', 'c', 'd');
  16471. * // => 'c'
  16472. */
  16473. function nthArg(n) {
  16474. n = toInteger(n);
  16475. return baseRest(function(args) {
  16476. return baseNth(args, n);
  16477. });
  16478. }
  16479. /**
  16480. * Creates a function that invokes `iteratees` with the arguments it receives
  16481. * and returns their results.
  16482. *
  16483. * @static
  16484. * @memberOf _
  16485. * @since 4.0.0
  16486. * @category Util
  16487. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  16488. * The iteratees to invoke.
  16489. * @returns {Function} Returns the new function.
  16490. * @example
  16491. *
  16492. * var func = _.over([Math.max, Math.min]);
  16493. *
  16494. * func(1, 2, 3, 4);
  16495. * // => [4, 1]
  16496. */
  16497. var over = createOver(arrayMap);
  16498. /**
  16499. * Creates a function that checks if **all** of the `predicates` return
  16500. * truthy when invoked with the arguments it receives.
  16501. *
  16502. * Following shorthands are possible for providing predicates.
  16503. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  16504. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  16505. *
  16506. * @static
  16507. * @memberOf _
  16508. * @since 4.0.0
  16509. * @category Util
  16510. * @param {...(Function|Function[])} [predicates=[_.identity]]
  16511. * The predicates to check.
  16512. * @returns {Function} Returns the new function.
  16513. * @example
  16514. *
  16515. * var func = _.overEvery([Boolean, isFinite]);
  16516. *
  16517. * func('1');
  16518. * // => true
  16519. *
  16520. * func(null);
  16521. * // => false
  16522. *
  16523. * func(NaN);
  16524. * // => false
  16525. */
  16526. var overEvery = createOver(arrayEvery);
  16527. /**
  16528. * Creates a function that checks if **any** of the `predicates` return
  16529. * truthy when invoked with the arguments it receives.
  16530. *
  16531. * Following shorthands are possible for providing predicates.
  16532. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  16533. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  16534. *
  16535. * @static
  16536. * @memberOf _
  16537. * @since 4.0.0
  16538. * @category Util
  16539. * @param {...(Function|Function[])} [predicates=[_.identity]]
  16540. * The predicates to check.
  16541. * @returns {Function} Returns the new function.
  16542. * @example
  16543. *
  16544. * var func = _.overSome([Boolean, isFinite]);
  16545. *
  16546. * func('1');
  16547. * // => true
  16548. *
  16549. * func(null);
  16550. * // => true
  16551. *
  16552. * func(NaN);
  16553. * // => false
  16554. *
  16555. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  16556. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  16557. */
  16558. var overSome = createOver(arraySome);
  16559. /**
  16560. * Creates a function that returns the value at `path` of a given object.
  16561. *
  16562. * @static
  16563. * @memberOf _
  16564. * @since 2.4.0
  16565. * @category Util
  16566. * @param {Array|string} path The path of the property to get.
  16567. * @returns {Function} Returns the new accessor function.
  16568. * @example
  16569. *
  16570. * var objects = [
  16571. * { 'a': { 'b': 2 } },
  16572. * { 'a': { 'b': 1 } }
  16573. * ];
  16574. *
  16575. * _.map(objects, _.property('a.b'));
  16576. * // => [2, 1]
  16577. *
  16578. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  16579. * // => [1, 2]
  16580. */
  16581. function property(path) {
  16582. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  16583. }
  16584. /**
  16585. * The opposite of `_.property`; this method creates a function that returns
  16586. * the value at a given path of `object`.
  16587. *
  16588. * @static
  16589. * @memberOf _
  16590. * @since 3.0.0
  16591. * @category Util
  16592. * @param {Object} object The object to query.
  16593. * @returns {Function} Returns the new accessor function.
  16594. * @example
  16595. *
  16596. * var array = [0, 1, 2],
  16597. * object = { 'a': array, 'b': array, 'c': array };
  16598. *
  16599. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  16600. * // => [2, 0]
  16601. *
  16602. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  16603. * // => [2, 0]
  16604. */
  16605. function propertyOf(object) {
  16606. return function(path) {
  16607. return object == null ? undefined : baseGet(object, path);
  16608. };
  16609. }
  16610. /**
  16611. * Creates an array of numbers (positive and/or negative) progressing from
  16612. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  16613. * `start` is specified without an `end` or `step`. If `end` is not specified,
  16614. * it's set to `start` with `start` then set to `0`.
  16615. *
  16616. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  16617. * floating-point values which can produce unexpected results.
  16618. *
  16619. * @static
  16620. * @since 0.1.0
  16621. * @memberOf _
  16622. * @category Util
  16623. * @param {number} [start=0] The start of the range.
  16624. * @param {number} end The end of the range.
  16625. * @param {number} [step=1] The value to increment or decrement by.
  16626. * @returns {Array} Returns the range of numbers.
  16627. * @see _.inRange, _.rangeRight
  16628. * @example
  16629. *
  16630. * _.range(4);
  16631. * // => [0, 1, 2, 3]
  16632. *
  16633. * _.range(-4);
  16634. * // => [0, -1, -2, -3]
  16635. *
  16636. * _.range(1, 5);
  16637. * // => [1, 2, 3, 4]
  16638. *
  16639. * _.range(0, 20, 5);
  16640. * // => [0, 5, 10, 15]
  16641. *
  16642. * _.range(0, -4, -1);
  16643. * // => [0, -1, -2, -3]
  16644. *
  16645. * _.range(1, 4, 0);
  16646. * // => [1, 1, 1]
  16647. *
  16648. * _.range(0);
  16649. * // => []
  16650. */
  16651. var range = createRange();
  16652. /**
  16653. * This method is like `_.range` except that it populates values in
  16654. * descending order.
  16655. *
  16656. * @static
  16657. * @memberOf _
  16658. * @since 4.0.0
  16659. * @category Util
  16660. * @param {number} [start=0] The start of the range.
  16661. * @param {number} end The end of the range.
  16662. * @param {number} [step=1] The value to increment or decrement by.
  16663. * @returns {Array} Returns the range of numbers.
  16664. * @see _.inRange, _.range
  16665. * @example
  16666. *
  16667. * _.rangeRight(4);
  16668. * // => [3, 2, 1, 0]
  16669. *
  16670. * _.rangeRight(-4);
  16671. * // => [-3, -2, -1, 0]
  16672. *
  16673. * _.rangeRight(1, 5);
  16674. * // => [4, 3, 2, 1]
  16675. *
  16676. * _.rangeRight(0, 20, 5);
  16677. * // => [15, 10, 5, 0]
  16678. *
  16679. * _.rangeRight(0, -4, -1);
  16680. * // => [-3, -2, -1, 0]
  16681. *
  16682. * _.rangeRight(1, 4, 0);
  16683. * // => [1, 1, 1]
  16684. *
  16685. * _.rangeRight(0);
  16686. * // => []
  16687. */
  16688. var rangeRight = createRange(true);
  16689. /**
  16690. * This method returns a new empty array.
  16691. *
  16692. * @static
  16693. * @memberOf _
  16694. * @since 4.13.0
  16695. * @category Util
  16696. * @returns {Array} Returns the new empty array.
  16697. * @example
  16698. *
  16699. * var arrays = _.times(2, _.stubArray);
  16700. *
  16701. * console.log(arrays);
  16702. * // => [[], []]
  16703. *
  16704. * console.log(arrays[0] === arrays[1]);
  16705. * // => false
  16706. */
  16707. function stubArray() {
  16708. return [];
  16709. }
  16710. /**
  16711. * This method returns `false`.
  16712. *
  16713. * @static
  16714. * @memberOf _
  16715. * @since 4.13.0
  16716. * @category Util
  16717. * @returns {boolean} Returns `false`.
  16718. * @example
  16719. *
  16720. * _.times(2, _.stubFalse);
  16721. * // => [false, false]
  16722. */
  16723. function stubFalse() {
  16724. return false;
  16725. }
  16726. /**
  16727. * This method returns a new empty object.
  16728. *
  16729. * @static
  16730. * @memberOf _
  16731. * @since 4.13.0
  16732. * @category Util
  16733. * @returns {Object} Returns the new empty object.
  16734. * @example
  16735. *
  16736. * var objects = _.times(2, _.stubObject);
  16737. *
  16738. * console.log(objects);
  16739. * // => [{}, {}]
  16740. *
  16741. * console.log(objects[0] === objects[1]);
  16742. * // => false
  16743. */
  16744. function stubObject() {
  16745. return {};
  16746. }
  16747. /**
  16748. * This method returns an empty string.
  16749. *
  16750. * @static
  16751. * @memberOf _
  16752. * @since 4.13.0
  16753. * @category Util
  16754. * @returns {string} Returns the empty string.
  16755. * @example
  16756. *
  16757. * _.times(2, _.stubString);
  16758. * // => ['', '']
  16759. */
  16760. function stubString() {
  16761. return '';
  16762. }
  16763. /**
  16764. * This method returns `true`.
  16765. *
  16766. * @static
  16767. * @memberOf _
  16768. * @since 4.13.0
  16769. * @category Util
  16770. * @returns {boolean} Returns `true`.
  16771. * @example
  16772. *
  16773. * _.times(2, _.stubTrue);
  16774. * // => [true, true]
  16775. */
  16776. function stubTrue() {
  16777. return true;
  16778. }
  16779. /**
  16780. * Invokes the iteratee `n` times, returning an array of the results of
  16781. * each invocation. The iteratee is invoked with one argument; (index).
  16782. *
  16783. * @static
  16784. * @since 0.1.0
  16785. * @memberOf _
  16786. * @category Util
  16787. * @param {number} n The number of times to invoke `iteratee`.
  16788. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  16789. * @returns {Array} Returns the array of results.
  16790. * @example
  16791. *
  16792. * _.times(3, String);
  16793. * // => ['0', '1', '2']
  16794. *
  16795. * _.times(4, _.constant(0));
  16796. * // => [0, 0, 0, 0]
  16797. */
  16798. function times(n, iteratee) {
  16799. n = toInteger(n);
  16800. if (n < 1 || n > MAX_SAFE_INTEGER) {
  16801. return [];
  16802. }
  16803. var index = MAX_ARRAY_LENGTH,
  16804. length = nativeMin(n, MAX_ARRAY_LENGTH);
  16805. iteratee = getIteratee(iteratee);
  16806. n -= MAX_ARRAY_LENGTH;
  16807. var result = baseTimes(length, iteratee);
  16808. while (++index < n) {
  16809. iteratee(index);
  16810. }
  16811. return result;
  16812. }
  16813. /**
  16814. * Converts `value` to a property path array.
  16815. *
  16816. * @static
  16817. * @memberOf _
  16818. * @since 4.0.0
  16819. * @category Util
  16820. * @param {*} value The value to convert.
  16821. * @returns {Array} Returns the new property path array.
  16822. * @example
  16823. *
  16824. * _.toPath('a.b.c');
  16825. * // => ['a', 'b', 'c']
  16826. *
  16827. * _.toPath('a[0].b.c');
  16828. * // => ['a', '0', 'b', 'c']
  16829. */
  16830. function toPath(value) {
  16831. if (isArray(value)) {
  16832. return arrayMap(value, toKey);
  16833. }
  16834. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  16835. }
  16836. /**
  16837. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  16838. *
  16839. * @static
  16840. * @since 0.1.0
  16841. * @memberOf _
  16842. * @category Util
  16843. * @param {string} [prefix=''] The value to prefix the ID with.
  16844. * @returns {string} Returns the unique ID.
  16845. * @example
  16846. *
  16847. * _.uniqueId('contact_');
  16848. * // => 'contact_104'
  16849. *
  16850. * _.uniqueId();
  16851. * // => '105'
  16852. */
  16853. function uniqueId(prefix) {
  16854. var id = ++idCounter;
  16855. return toString(prefix) + id;
  16856. }
  16857. /*------------------------------------------------------------------------*/
  16858. /**
  16859. * Adds two numbers.
  16860. *
  16861. * @static
  16862. * @memberOf _
  16863. * @since 3.4.0
  16864. * @category Math
  16865. * @param {number} augend The first number in an addition.
  16866. * @param {number} addend The second number in an addition.
  16867. * @returns {number} Returns the total.
  16868. * @example
  16869. *
  16870. * _.add(6, 4);
  16871. * // => 10
  16872. */
  16873. var add = createMathOperation(function(augend, addend) {
  16874. return augend + addend;
  16875. }, 0);
  16876. /**
  16877. * Computes `number` rounded up to `precision`.
  16878. *
  16879. * @static
  16880. * @memberOf _
  16881. * @since 3.10.0
  16882. * @category Math
  16883. * @param {number} number The number to round up.
  16884. * @param {number} [precision=0] The precision to round up to.
  16885. * @returns {number} Returns the rounded up number.
  16886. * @example
  16887. *
  16888. * _.ceil(4.006);
  16889. * // => 5
  16890. *
  16891. * _.ceil(6.004, 2);
  16892. * // => 6.01
  16893. *
  16894. * _.ceil(6040, -2);
  16895. * // => 6100
  16896. */
  16897. var ceil = createRound('ceil');
  16898. /**
  16899. * Divide two numbers.
  16900. *
  16901. * @static
  16902. * @memberOf _
  16903. * @since 4.7.0
  16904. * @category Math
  16905. * @param {number} dividend The first number in a division.
  16906. * @param {number} divisor The second number in a division.
  16907. * @returns {number} Returns the quotient.
  16908. * @example
  16909. *
  16910. * _.divide(6, 4);
  16911. * // => 1.5
  16912. */
  16913. var divide = createMathOperation(function(dividend, divisor) {
  16914. return dividend / divisor;
  16915. }, 1);
  16916. /**
  16917. * Computes `number` rounded down to `precision`.
  16918. *
  16919. * @static
  16920. * @memberOf _
  16921. * @since 3.10.0
  16922. * @category Math
  16923. * @param {number} number The number to round down.
  16924. * @param {number} [precision=0] The precision to round down to.
  16925. * @returns {number} Returns the rounded down number.
  16926. * @example
  16927. *
  16928. * _.floor(4.006);
  16929. * // => 4
  16930. *
  16931. * _.floor(0.046, 2);
  16932. * // => 0.04
  16933. *
  16934. * _.floor(4060, -2);
  16935. * // => 4000
  16936. */
  16937. var floor = createRound('floor');
  16938. /**
  16939. * Computes the maximum value of `array`. If `array` is empty or falsey,
  16940. * `undefined` is returned.
  16941. *
  16942. * @static
  16943. * @since 0.1.0
  16944. * @memberOf _
  16945. * @category Math
  16946. * @param {Array} array The array to iterate over.
  16947. * @returns {*} Returns the maximum value.
  16948. * @example
  16949. *
  16950. * _.max([4, 2, 8, 6]);
  16951. * // => 8
  16952. *
  16953. * _.max([]);
  16954. * // => undefined
  16955. */
  16956. function max(array) {
  16957. return (array && array.length)
  16958. ? baseExtremum(array, identity, baseGt)
  16959. : undefined;
  16960. }
  16961. /**
  16962. * This method is like `_.max` except that it accepts `iteratee` which is
  16963. * invoked for each element in `array` to generate the criterion by which
  16964. * the value is ranked. The iteratee is invoked with one argument: (value).
  16965. *
  16966. * @static
  16967. * @memberOf _
  16968. * @since 4.0.0
  16969. * @category Math
  16970. * @param {Array} array The array to iterate over.
  16971. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  16972. * @returns {*} Returns the maximum value.
  16973. * @example
  16974. *
  16975. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  16976. *
  16977. * _.maxBy(objects, function(o) { return o.n; });
  16978. * // => { 'n': 2 }
  16979. *
  16980. * // The `_.property` iteratee shorthand.
  16981. * _.maxBy(objects, 'n');
  16982. * // => { 'n': 2 }
  16983. */
  16984. function maxBy(array, iteratee) {
  16985. return (array && array.length)
  16986. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  16987. : undefined;
  16988. }
  16989. /**
  16990. * Computes the mean of the values in `array`.
  16991. *
  16992. * @static
  16993. * @memberOf _
  16994. * @since 4.0.0
  16995. * @category Math
  16996. * @param {Array} array The array to iterate over.
  16997. * @returns {number} Returns the mean.
  16998. * @example
  16999. *
  17000. * _.mean([4, 2, 8, 6]);
  17001. * // => 5
  17002. */
  17003. function mean(array) {
  17004. return baseMean(array, identity);
  17005. }
  17006. /**
  17007. * This method is like `_.mean` except that it accepts `iteratee` which is
  17008. * invoked for each element in `array` to generate the value to be averaged.
  17009. * The iteratee is invoked with one argument: (value).
  17010. *
  17011. * @static
  17012. * @memberOf _
  17013. * @since 4.7.0
  17014. * @category Math
  17015. * @param {Array} array The array to iterate over.
  17016. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  17017. * @returns {number} Returns the mean.
  17018. * @example
  17019. *
  17020. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  17021. *
  17022. * _.meanBy(objects, function(o) { return o.n; });
  17023. * // => 5
  17024. *
  17025. * // The `_.property` iteratee shorthand.
  17026. * _.meanBy(objects, 'n');
  17027. * // => 5
  17028. */
  17029. function meanBy(array, iteratee) {
  17030. return baseMean(array, getIteratee(iteratee, 2));
  17031. }
  17032. /**
  17033. * Computes the minimum value of `array`. If `array` is empty or falsey,
  17034. * `undefined` is returned.
  17035. *
  17036. * @static
  17037. * @since 0.1.0
  17038. * @memberOf _
  17039. * @category Math
  17040. * @param {Array} array The array to iterate over.
  17041. * @returns {*} Returns the minimum value.
  17042. * @example
  17043. *
  17044. * _.min([4, 2, 8, 6]);
  17045. * // => 2
  17046. *
  17047. * _.min([]);
  17048. * // => undefined
  17049. */
  17050. function min(array) {
  17051. return (array && array.length)
  17052. ? baseExtremum(array, identity, baseLt)
  17053. : undefined;
  17054. }
  17055. /**
  17056. * This method is like `_.min` except that it accepts `iteratee` which is
  17057. * invoked for each element in `array` to generate the criterion by which
  17058. * the value is ranked. The iteratee is invoked with one argument: (value).
  17059. *
  17060. * @static
  17061. * @memberOf _
  17062. * @since 4.0.0
  17063. * @category Math
  17064. * @param {Array} array The array to iterate over.
  17065. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  17066. * @returns {*} Returns the minimum value.
  17067. * @example
  17068. *
  17069. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  17070. *
  17071. * _.minBy(objects, function(o) { return o.n; });
  17072. * // => { 'n': 1 }
  17073. *
  17074. * // The `_.property` iteratee shorthand.
  17075. * _.minBy(objects, 'n');
  17076. * // => { 'n': 1 }
  17077. */
  17078. function minBy(array, iteratee) {
  17079. return (array && array.length)
  17080. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  17081. : undefined;
  17082. }
  17083. /**
  17084. * Multiply two numbers.
  17085. *
  17086. * @static
  17087. * @memberOf _
  17088. * @since 4.7.0
  17089. * @category Math
  17090. * @param {number} multiplier The first number in a multiplication.
  17091. * @param {number} multiplicand The second number in a multiplication.
  17092. * @returns {number} Returns the product.
  17093. * @example
  17094. *
  17095. * _.multiply(6, 4);
  17096. * // => 24
  17097. */
  17098. var multiply = createMathOperation(function(multiplier, multiplicand) {
  17099. return multiplier * multiplicand;
  17100. }, 1);
  17101. /**
  17102. * Computes `number` rounded to `precision`.
  17103. *
  17104. * @static
  17105. * @memberOf _
  17106. * @since 3.10.0
  17107. * @category Math
  17108. * @param {number} number The number to round.
  17109. * @param {number} [precision=0] The precision to round to.
  17110. * @returns {number} Returns the rounded number.
  17111. * @example
  17112. *
  17113. * _.round(4.006);
  17114. * // => 4
  17115. *
  17116. * _.round(4.006, 2);
  17117. * // => 4.01
  17118. *
  17119. * _.round(4060, -2);
  17120. * // => 4100
  17121. */
  17122. var round = createRound('round');
  17123. /**
  17124. * Subtract two numbers.
  17125. *
  17126. * @static
  17127. * @memberOf _
  17128. * @since 4.0.0
  17129. * @category Math
  17130. * @param {number} minuend The first number in a subtraction.
  17131. * @param {number} subtrahend The second number in a subtraction.
  17132. * @returns {number} Returns the difference.
  17133. * @example
  17134. *
  17135. * _.subtract(6, 4);
  17136. * // => 2
  17137. */
  17138. var subtract = createMathOperation(function(minuend, subtrahend) {
  17139. return minuend - subtrahend;
  17140. }, 0);
  17141. /**
  17142. * Computes the sum of the values in `array`.
  17143. *
  17144. * @static
  17145. * @memberOf _
  17146. * @since 3.4.0
  17147. * @category Math
  17148. * @param {Array} array The array to iterate over.
  17149. * @returns {number} Returns the sum.
  17150. * @example
  17151. *
  17152. * _.sum([4, 2, 8, 6]);
  17153. * // => 20
  17154. */
  17155. function sum(array) {
  17156. return (array && array.length)
  17157. ? baseSum(array, identity)
  17158. : 0;
  17159. }
  17160. /**
  17161. * This method is like `_.sum` except that it accepts `iteratee` which is
  17162. * invoked for each element in `array` to generate the value to be summed.
  17163. * The iteratee is invoked with one argument: (value).
  17164. *
  17165. * @static
  17166. * @memberOf _
  17167. * @since 4.0.0
  17168. * @category Math
  17169. * @param {Array} array The array to iterate over.
  17170. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  17171. * @returns {number} Returns the sum.
  17172. * @example
  17173. *
  17174. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  17175. *
  17176. * _.sumBy(objects, function(o) { return o.n; });
  17177. * // => 20
  17178. *
  17179. * // The `_.property` iteratee shorthand.
  17180. * _.sumBy(objects, 'n');
  17181. * // => 20
  17182. */
  17183. function sumBy(array, iteratee) {
  17184. return (array && array.length)
  17185. ? baseSum(array, getIteratee(iteratee, 2))
  17186. : 0;
  17187. }
  17188. /*------------------------------------------------------------------------*/
  17189. // Add methods that return wrapped values in chain sequences.
  17190. lodash.after = after;
  17191. lodash.ary = ary;
  17192. lodash.assign = assign;
  17193. lodash.assignIn = assignIn;
  17194. lodash.assignInWith = assignInWith;
  17195. lodash.assignWith = assignWith;
  17196. lodash.at = at;
  17197. lodash.before = before;
  17198. lodash.bind = bind;
  17199. lodash.bindAll = bindAll;
  17200. lodash.bindKey = bindKey;
  17201. lodash.castArray = castArray;
  17202. lodash.chain = chain;
  17203. lodash.chunk = chunk;
  17204. lodash.compact = compact;
  17205. lodash.concat = concat;
  17206. lodash.cond = cond;
  17207. lodash.conforms = conforms;
  17208. lodash.constant = constant;
  17209. lodash.countBy = countBy;
  17210. lodash.create = create;
  17211. lodash.curry = curry;
  17212. lodash.curryRight = curryRight;
  17213. lodash.debounce = debounce;
  17214. lodash.defaults = defaults;
  17215. lodash.defaultsDeep = defaultsDeep;
  17216. lodash.defer = defer;
  17217. lodash.delay = delay;
  17218. lodash.difference = difference;
  17219. lodash.differenceBy = differenceBy;
  17220. lodash.differenceWith = differenceWith;
  17221. lodash.drop = drop;
  17222. lodash.dropRight = dropRight;
  17223. lodash.dropRightWhile = dropRightWhile;
  17224. lodash.dropWhile = dropWhile;
  17225. lodash.fill = fill;
  17226. lodash.filter = filter;
  17227. lodash.flatMap = flatMap;
  17228. lodash.flatMapDeep = flatMapDeep;
  17229. lodash.flatMapDepth = flatMapDepth;
  17230. lodash.flatten = flatten;
  17231. lodash.flattenDeep = flattenDeep;
  17232. lodash.flattenDepth = flattenDepth;
  17233. lodash.flip = flip;
  17234. lodash.flow = flow;
  17235. lodash.flowRight = flowRight;
  17236. lodash.fromPairs = fromPairs;
  17237. lodash.functions = functions;
  17238. lodash.functionsIn = functionsIn;
  17239. lodash.groupBy = groupBy;
  17240. lodash.initial = initial;
  17241. lodash.intersection = intersection;
  17242. lodash.intersectionBy = intersectionBy;
  17243. lodash.intersectionWith = intersectionWith;
  17244. lodash.invert = invert;
  17245. lodash.invertBy = invertBy;
  17246. lodash.invokeMap = invokeMap;
  17247. lodash.iteratee = iteratee;
  17248. lodash.keyBy = keyBy;
  17249. lodash.keys = keys;
  17250. lodash.keysIn = keysIn;
  17251. lodash.map = map;
  17252. lodash.mapKeys = mapKeys;
  17253. lodash.mapValues = mapValues;
  17254. lodash.matches = matches;
  17255. lodash.matchesProperty = matchesProperty;
  17256. lodash.memoize = memoize;
  17257. lodash.merge = merge;
  17258. lodash.mergeWith = mergeWith;
  17259. lodash.method = method;
  17260. lodash.methodOf = methodOf;
  17261. lodash.mixin = mixin;
  17262. lodash.negate = negate;
  17263. lodash.nthArg = nthArg;
  17264. lodash.omit = omit;
  17265. lodash.omitBy = omitBy;
  17266. lodash.once = once;
  17267. lodash.orderBy = orderBy;
  17268. lodash.over = over;
  17269. lodash.overArgs = overArgs;
  17270. lodash.overEvery = overEvery;
  17271. lodash.overSome = overSome;
  17272. lodash.partial = partial;
  17273. lodash.partialRight = partialRight;
  17274. lodash.partition = partition;
  17275. lodash.pick = pick;
  17276. lodash.pickBy = pickBy;
  17277. lodash.property = property;
  17278. lodash.propertyOf = propertyOf;
  17279. lodash.pull = pull;
  17280. lodash.pullAll = pullAll;
  17281. lodash.pullAllBy = pullAllBy;
  17282. lodash.pullAllWith = pullAllWith;
  17283. lodash.pullAt = pullAt;
  17284. lodash.range = range;
  17285. lodash.rangeRight = rangeRight;
  17286. lodash.rearg = rearg;
  17287. lodash.reject = reject;
  17288. lodash.remove = remove;
  17289. lodash.rest = rest;
  17290. lodash.reverse = reverse;
  17291. lodash.sampleSize = sampleSize;
  17292. lodash.set = set;
  17293. lodash.setWith = setWith;
  17294. lodash.shuffle = shuffle;
  17295. lodash.slice = slice;
  17296. lodash.sortBy = sortBy;
  17297. lodash.sortedUniq = sortedUniq;
  17298. lodash.sortedUniqBy = sortedUniqBy;
  17299. lodash.split = split;
  17300. lodash.spread = spread;
  17301. lodash.tail = tail;
  17302. lodash.take = take;
  17303. lodash.takeRight = takeRight;
  17304. lodash.takeRightWhile = takeRightWhile;
  17305. lodash.takeWhile = takeWhile;
  17306. lodash.tap = tap;
  17307. lodash.throttle = throttle;
  17308. lodash.thru = thru;
  17309. lodash.toArray = toArray;
  17310. lodash.toPairs = toPairs;
  17311. lodash.toPairsIn = toPairsIn;
  17312. lodash.toPath = toPath;
  17313. lodash.toPlainObject = toPlainObject;
  17314. lodash.transform = transform;
  17315. lodash.unary = unary;
  17316. lodash.union = union;
  17317. lodash.unionBy = unionBy;
  17318. lodash.unionWith = unionWith;
  17319. lodash.uniq = uniq;
  17320. lodash.uniqBy = uniqBy;
  17321. lodash.uniqWith = uniqWith;
  17322. lodash.unset = unset;
  17323. lodash.unzip = unzip;
  17324. lodash.unzipWith = unzipWith;
  17325. lodash.update = update;
  17326. lodash.updateWith = updateWith;
  17327. lodash.values = values;
  17328. lodash.valuesIn = valuesIn;
  17329. lodash.without = without;
  17330. lodash.words = words;
  17331. lodash.wrap = wrap;
  17332. lodash.xor = xor;
  17333. lodash.xorBy = xorBy;
  17334. lodash.xorWith = xorWith;
  17335. lodash.zip = zip;
  17336. lodash.zipObject = zipObject;
  17337. lodash.zipObjectDeep = zipObjectDeep;
  17338. lodash.zipWith = zipWith;
  17339. // Add aliases.
  17340. lodash.entries = toPairs;
  17341. lodash.entriesIn = toPairsIn;
  17342. lodash.extend = assignIn;
  17343. lodash.extendWith = assignInWith;
  17344. // Add methods to `lodash.prototype`.
  17345. mixin(lodash, lodash);
  17346. /*------------------------------------------------------------------------*/
  17347. // Add methods that return unwrapped values in chain sequences.
  17348. lodash.add = add;
  17349. lodash.attempt = attempt;
  17350. lodash.camelCase = camelCase;
  17351. lodash.capitalize = capitalize;
  17352. lodash.ceil = ceil;
  17353. lodash.clamp = clamp;
  17354. lodash.clone = clone;
  17355. lodash.cloneDeep = cloneDeep;
  17356. lodash.cloneDeepWith = cloneDeepWith;
  17357. lodash.cloneWith = cloneWith;
  17358. lodash.conformsTo = conformsTo;
  17359. lodash.deburr = deburr;
  17360. lodash.defaultTo = defaultTo;
  17361. lodash.divide = divide;
  17362. lodash.endsWith = endsWith;
  17363. lodash.eq = eq;
  17364. lodash.escape = escape;
  17365. lodash.escapeRegExp = escapeRegExp;
  17366. lodash.every = every;
  17367. lodash.find = find;
  17368. lodash.findIndex = findIndex;
  17369. lodash.findKey = findKey;
  17370. lodash.findLast = findLast;
  17371. lodash.findLastIndex = findLastIndex;
  17372. lodash.findLastKey = findLastKey;
  17373. lodash.floor = floor;
  17374. lodash.forEach = forEach;
  17375. lodash.forEachRight = forEachRight;
  17376. lodash.forIn = forIn;
  17377. lodash.forInRight = forInRight;
  17378. lodash.forOwn = forOwn;
  17379. lodash.forOwnRight = forOwnRight;
  17380. lodash.get = get;
  17381. lodash.gt = gt;
  17382. lodash.gte = gte;
  17383. lodash.has = has;
  17384. lodash.hasIn = hasIn;
  17385. lodash.head = head;
  17386. lodash.identity = identity;
  17387. lodash.includes = includes;
  17388. lodash.indexOf = indexOf;
  17389. lodash.inRange = inRange;
  17390. lodash.invoke = invoke;
  17391. lodash.isArguments = isArguments;
  17392. lodash.isArray = isArray;
  17393. lodash.isArrayBuffer = isArrayBuffer;
  17394. lodash.isArrayLike = isArrayLike;
  17395. lodash.isArrayLikeObject = isArrayLikeObject;
  17396. lodash.isBoolean = isBoolean;
  17397. lodash.isBuffer = isBuffer;
  17398. lodash.isDate = isDate;
  17399. lodash.isElement = isElement;
  17400. lodash.isEmpty = isEmpty;
  17401. lodash.isEqual = isEqual;
  17402. lodash.isEqualWith = isEqualWith;
  17403. lodash.isError = isError;
  17404. lodash.isFinite = isFinite;
  17405. lodash.isFunction = isFunction;
  17406. lodash.isInteger = isInteger;
  17407. lodash.isLength = isLength;
  17408. lodash.isMap = isMap;
  17409. lodash.isMatch = isMatch;
  17410. lodash.isMatchWith = isMatchWith;
  17411. lodash.isNaN = isNaN;
  17412. lodash.isNative = isNative;
  17413. lodash.isNil = isNil;
  17414. lodash.isNull = isNull;
  17415. lodash.isNumber = isNumber;
  17416. lodash.isObject = isObject;
  17417. lodash.isObjectLike = isObjectLike;
  17418. lodash.isPlainObject = isPlainObject;
  17419. lodash.isRegExp = isRegExp;
  17420. lodash.isSafeInteger = isSafeInteger;
  17421. lodash.isSet = isSet;
  17422. lodash.isString = isString;
  17423. lodash.isSymbol = isSymbol;
  17424. lodash.isTypedArray = isTypedArray;
  17425. lodash.isUndefined = isUndefined;
  17426. lodash.isWeakMap = isWeakMap;
  17427. lodash.isWeakSet = isWeakSet;
  17428. lodash.join = join;
  17429. lodash.kebabCase = kebabCase;
  17430. lodash.last = last;
  17431. lodash.lastIndexOf = lastIndexOf;
  17432. lodash.lowerCase = lowerCase;
  17433. lodash.lowerFirst = lowerFirst;
  17434. lodash.lt = lt;
  17435. lodash.lte = lte;
  17436. lodash.max = max;
  17437. lodash.maxBy = maxBy;
  17438. lodash.mean = mean;
  17439. lodash.meanBy = meanBy;
  17440. lodash.min = min;
  17441. lodash.minBy = minBy;
  17442. lodash.stubArray = stubArray;
  17443. lodash.stubFalse = stubFalse;
  17444. lodash.stubObject = stubObject;
  17445. lodash.stubString = stubString;
  17446. lodash.stubTrue = stubTrue;
  17447. lodash.multiply = multiply;
  17448. lodash.nth = nth;
  17449. lodash.noConflict = noConflict;
  17450. lodash.noop = noop;
  17451. lodash.now = now;
  17452. lodash.pad = pad;
  17453. lodash.padEnd = padEnd;
  17454. lodash.padStart = padStart;
  17455. lodash.parseInt = parseInt;
  17456. lodash.random = random;
  17457. lodash.reduce = reduce;
  17458. lodash.reduceRight = reduceRight;
  17459. lodash.repeat = repeat;
  17460. lodash.replace = replace;
  17461. lodash.result = result;
  17462. lodash.round = round;
  17463. lodash.runInContext = runInContext;
  17464. lodash.sample = sample;
  17465. lodash.size = size;
  17466. lodash.snakeCase = snakeCase;
  17467. lodash.some = some;
  17468. lodash.sortedIndex = sortedIndex;
  17469. lodash.sortedIndexBy = sortedIndexBy;
  17470. lodash.sortedIndexOf = sortedIndexOf;
  17471. lodash.sortedLastIndex = sortedLastIndex;
  17472. lodash.sortedLastIndexBy = sortedLastIndexBy;
  17473. lodash.sortedLastIndexOf = sortedLastIndexOf;
  17474. lodash.startCase = startCase;
  17475. lodash.startsWith = startsWith;
  17476. lodash.subtract = subtract;
  17477. lodash.sum = sum;
  17478. lodash.sumBy = sumBy;
  17479. lodash.template = template;
  17480. lodash.times = times;
  17481. lodash.toFinite = toFinite;
  17482. lodash.toInteger = toInteger;
  17483. lodash.toLength = toLength;
  17484. lodash.toLower = toLower;
  17485. lodash.toNumber = toNumber;
  17486. lodash.toSafeInteger = toSafeInteger;
  17487. lodash.toString = toString;
  17488. lodash.toUpper = toUpper;
  17489. lodash.trim = trim;
  17490. lodash.trimEnd = trimEnd;
  17491. lodash.trimStart = trimStart;
  17492. lodash.truncate = truncate;
  17493. lodash.unescape = unescape;
  17494. lodash.uniqueId = uniqueId;
  17495. lodash.upperCase = upperCase;
  17496. lodash.upperFirst = upperFirst;
  17497. // Add aliases.
  17498. lodash.each = forEach;
  17499. lodash.eachRight = forEachRight;
  17500. lodash.first = head;
  17501. mixin(lodash, (function() {
  17502. var source = {};
  17503. baseForOwn(lodash, function(func, methodName) {
  17504. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  17505. source[methodName] = func;
  17506. }
  17507. });
  17508. return source;
  17509. }()), { 'chain': false });
  17510. /*------------------------------------------------------------------------*/
  17511. /**
  17512. * The semantic version number.
  17513. *
  17514. * @static
  17515. * @memberOf _
  17516. * @type {string}
  17517. */
  17518. lodash.VERSION = VERSION;
  17519. // Assign default placeholders.
  17520. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  17521. lodash[methodName].placeholder = lodash;
  17522. });
  17523. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  17524. arrayEach(['drop', 'take'], function(methodName, index) {
  17525. LazyWrapper.prototype[methodName] = function(n) {
  17526. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  17527. var result = (this.__filtered__ && !index)
  17528. ? new LazyWrapper(this)
  17529. : this.clone();
  17530. if (result.__filtered__) {
  17531. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  17532. } else {
  17533. result.__views__.push({
  17534. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  17535. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  17536. });
  17537. }
  17538. return result;
  17539. };
  17540. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  17541. return this.reverse()[methodName](n).reverse();
  17542. };
  17543. });
  17544. // Add `LazyWrapper` methods that accept an `iteratee` value.
  17545. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  17546. var type = index + 1,
  17547. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  17548. LazyWrapper.prototype[methodName] = function(iteratee) {
  17549. var result = this.clone();
  17550. result.__iteratees__.push({
  17551. 'iteratee': getIteratee(iteratee, 3),
  17552. 'type': type
  17553. });
  17554. result.__filtered__ = result.__filtered__ || isFilter;
  17555. return result;
  17556. };
  17557. });
  17558. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  17559. arrayEach(['head', 'last'], function(methodName, index) {
  17560. var takeName = 'take' + (index ? 'Right' : '');
  17561. LazyWrapper.prototype[methodName] = function() {
  17562. return this[takeName](1).value()[0];
  17563. };
  17564. });
  17565. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  17566. arrayEach(['initial', 'tail'], function(methodName, index) {
  17567. var dropName = 'drop' + (index ? '' : 'Right');
  17568. LazyWrapper.prototype[methodName] = function() {
  17569. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  17570. };
  17571. });
  17572. LazyWrapper.prototype.compact = function() {
  17573. return this.filter(identity);
  17574. };
  17575. LazyWrapper.prototype.find = function(predicate) {
  17576. return this.filter(predicate).head();
  17577. };
  17578. LazyWrapper.prototype.findLast = function(predicate) {
  17579. return this.reverse().find(predicate);
  17580. };
  17581. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  17582. if (typeof path == 'function') {
  17583. return new LazyWrapper(this);
  17584. }
  17585. return this.map(function(value) {
  17586. return baseInvoke(value, path, args);
  17587. });
  17588. });
  17589. LazyWrapper.prototype.reject = function(predicate) {
  17590. return this.filter(negate(getIteratee(predicate)));
  17591. };
  17592. LazyWrapper.prototype.slice = function(start, end) {
  17593. start = toInteger(start);
  17594. var result = this;
  17595. if (result.__filtered__ && (start > 0 || end < 0)) {
  17596. return new LazyWrapper(result);
  17597. }
  17598. if (start < 0) {
  17599. result = result.takeRight(-start);
  17600. } else if (start) {
  17601. result = result.drop(start);
  17602. }
  17603. if (end !== undefined) {
  17604. end = toInteger(end);
  17605. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  17606. }
  17607. return result;
  17608. };
  17609. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  17610. return this.reverse().takeWhile(predicate).reverse();
  17611. };
  17612. LazyWrapper.prototype.toArray = function() {
  17613. return this.take(MAX_ARRAY_LENGTH);
  17614. };
  17615. // Add `LazyWrapper` methods to `lodash.prototype`.
  17616. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  17617. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  17618. isTaker = /^(?:head|last)$/.test(methodName),
  17619. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  17620. retUnwrapped = isTaker || /^find/.test(methodName);
  17621. if (!lodashFunc) {
  17622. return;
  17623. }
  17624. lodash.prototype[methodName] = function() {
  17625. var value = this.__wrapped__,
  17626. args = isTaker ? [1] : arguments,
  17627. isLazy = value instanceof LazyWrapper,
  17628. iteratee = args[0],
  17629. useLazy = isLazy || isArray(value);
  17630. var interceptor = function(value) {
  17631. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  17632. return (isTaker && chainAll) ? result[0] : result;
  17633. };
  17634. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  17635. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  17636. isLazy = useLazy = false;
  17637. }
  17638. var chainAll = this.__chain__,
  17639. isHybrid = !!this.__actions__.length,
  17640. isUnwrapped = retUnwrapped && !chainAll,
  17641. onlyLazy = isLazy && !isHybrid;
  17642. if (!retUnwrapped && useLazy) {
  17643. value = onlyLazy ? value : new LazyWrapper(this);
  17644. var result = func.apply(value, args);
  17645. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  17646. return new LodashWrapper(result, chainAll);
  17647. }
  17648. if (isUnwrapped && onlyLazy) {
  17649. return func.apply(this, args);
  17650. }
  17651. result = this.thru(interceptor);
  17652. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  17653. };
  17654. });
  17655. // Add `Array` methods to `lodash.prototype`.
  17656. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  17657. var func = arrayProto[methodName],
  17658. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  17659. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  17660. lodash.prototype[methodName] = function() {
  17661. var args = arguments;
  17662. if (retUnwrapped && !this.__chain__) {
  17663. var value = this.value();
  17664. return func.apply(isArray(value) ? value : [], args);
  17665. }
  17666. return this[chainName](function(value) {
  17667. return func.apply(isArray(value) ? value : [], args);
  17668. });
  17669. };
  17670. });
  17671. // Map minified method names to their real names.
  17672. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  17673. var lodashFunc = lodash[methodName];
  17674. if (lodashFunc) {
  17675. var key = lodashFunc.name + '';
  17676. if (!hasOwnProperty.call(realNames, key)) {
  17677. realNames[key] = [];
  17678. }
  17679. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  17680. }
  17681. });
  17682. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  17683. 'name': 'wrapper',
  17684. 'func': undefined
  17685. }];
  17686. // Add methods to `LazyWrapper`.
  17687. LazyWrapper.prototype.clone = lazyClone;
  17688. LazyWrapper.prototype.reverse = lazyReverse;
  17689. LazyWrapper.prototype.value = lazyValue;
  17690. // Add chain sequence methods to the `lodash` wrapper.
  17691. lodash.prototype.at = wrapperAt;
  17692. lodash.prototype.chain = wrapperChain;
  17693. lodash.prototype.commit = wrapperCommit;
  17694. lodash.prototype.next = wrapperNext;
  17695. lodash.prototype.plant = wrapperPlant;
  17696. lodash.prototype.reverse = wrapperReverse;
  17697. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  17698. // Add lazy aliases.
  17699. lodash.prototype.first = lodash.prototype.head;
  17700. if (symIterator) {
  17701. lodash.prototype[symIterator] = wrapperToIterator;
  17702. }
  17703. return lodash;
  17704. });
  17705. /*--------------------------------------------------------------------------*/
  17706. // Export lodash.
  17707. var _ = runInContext();
  17708. // Some AMD build optimizers, like r.js, check for condition patterns like:
  17709. if (true) {
  17710. // Expose Lodash on the global object to prevent errors when Lodash is
  17711. // loaded by a script tag in the presence of an AMD loader.
  17712. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  17713. // Use `_.noConflict` to remove Lodash from the global object.
  17714. root._ = _;
  17715. // Define as an anonymous module so, through path mapping, it can be
  17716. // referenced as the "underscore" module.
  17717. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  17718. return _;
  17719. }).call(exports, __webpack_require__, exports, module),
  17720. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  17721. }
  17722. // Check for `exports` after `define` in case a build optimizer adds it.
  17723. else {}
  17724. }.call(this));
  17725. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module)))
  17726. /***/ }),
  17727. /***/ "./node_modules/process/browser.js":
  17728. /*!*****************************************!*\
  17729. !*** ./node_modules/process/browser.js ***!
  17730. \*****************************************/
  17731. /*! no static exports found */
  17732. /***/ (function(module, exports) {
  17733. // shim for using process in browser
  17734. var process = module.exports = {};
  17735. // cached from whatever global is present so that test runners that stub it
  17736. // don't break things. But we need to wrap it in a try catch in case it is
  17737. // wrapped in strict mode code which doesn't define any globals. It's inside a
  17738. // function because try/catches deoptimize in certain engines.
  17739. var cachedSetTimeout;
  17740. var cachedClearTimeout;
  17741. function defaultSetTimout() {
  17742. throw new Error('setTimeout has not been defined');
  17743. }
  17744. function defaultClearTimeout () {
  17745. throw new Error('clearTimeout has not been defined');
  17746. }
  17747. (function () {
  17748. try {
  17749. if (typeof setTimeout === 'function') {
  17750. cachedSetTimeout = setTimeout;
  17751. } else {
  17752. cachedSetTimeout = defaultSetTimout;
  17753. }
  17754. } catch (e) {
  17755. cachedSetTimeout = defaultSetTimout;
  17756. }
  17757. try {
  17758. if (typeof clearTimeout === 'function') {
  17759. cachedClearTimeout = clearTimeout;
  17760. } else {
  17761. cachedClearTimeout = defaultClearTimeout;
  17762. }
  17763. } catch (e) {
  17764. cachedClearTimeout = defaultClearTimeout;
  17765. }
  17766. } ())
  17767. function runTimeout(fun) {
  17768. if (cachedSetTimeout === setTimeout) {
  17769. //normal enviroments in sane situations
  17770. return setTimeout(fun, 0);
  17771. }
  17772. // if setTimeout wasn't available but was latter defined
  17773. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  17774. cachedSetTimeout = setTimeout;
  17775. return setTimeout(fun, 0);
  17776. }
  17777. try {
  17778. // when when somebody has screwed with setTimeout but no I.E. maddness
  17779. return cachedSetTimeout(fun, 0);
  17780. } catch(e){
  17781. try {
  17782. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  17783. return cachedSetTimeout.call(null, fun, 0);
  17784. } catch(e){
  17785. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  17786. return cachedSetTimeout.call(this, fun, 0);
  17787. }
  17788. }
  17789. }
  17790. function runClearTimeout(marker) {
  17791. if (cachedClearTimeout === clearTimeout) {
  17792. //normal enviroments in sane situations
  17793. return clearTimeout(marker);
  17794. }
  17795. // if clearTimeout wasn't available but was latter defined
  17796. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  17797. cachedClearTimeout = clearTimeout;
  17798. return clearTimeout(marker);
  17799. }
  17800. try {
  17801. // when when somebody has screwed with setTimeout but no I.E. maddness
  17802. return cachedClearTimeout(marker);
  17803. } catch (e){
  17804. try {
  17805. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  17806. return cachedClearTimeout.call(null, marker);
  17807. } catch (e){
  17808. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  17809. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  17810. return cachedClearTimeout.call(this, marker);
  17811. }
  17812. }
  17813. }
  17814. var queue = [];
  17815. var draining = false;
  17816. var currentQueue;
  17817. var queueIndex = -1;
  17818. function cleanUpNextTick() {
  17819. if (!draining || !currentQueue) {
  17820. return;
  17821. }
  17822. draining = false;
  17823. if (currentQueue.length) {
  17824. queue = currentQueue.concat(queue);
  17825. } else {
  17826. queueIndex = -1;
  17827. }
  17828. if (queue.length) {
  17829. drainQueue();
  17830. }
  17831. }
  17832. function drainQueue() {
  17833. if (draining) {
  17834. return;
  17835. }
  17836. var timeout = runTimeout(cleanUpNextTick);
  17837. draining = true;
  17838. var len = queue.length;
  17839. while(len) {
  17840. currentQueue = queue;
  17841. queue = [];
  17842. while (++queueIndex < len) {
  17843. if (currentQueue) {
  17844. currentQueue[queueIndex].run();
  17845. }
  17846. }
  17847. queueIndex = -1;
  17848. len = queue.length;
  17849. }
  17850. currentQueue = null;
  17851. draining = false;
  17852. runClearTimeout(timeout);
  17853. }
  17854. process.nextTick = function (fun) {
  17855. var args = new Array(arguments.length - 1);
  17856. if (arguments.length > 1) {
  17857. for (var i = 1; i < arguments.length; i++) {
  17858. args[i - 1] = arguments[i];
  17859. }
  17860. }
  17861. queue.push(new Item(fun, args));
  17862. if (queue.length === 1 && !draining) {
  17863. runTimeout(drainQueue);
  17864. }
  17865. };
  17866. // v8 likes predictible objects
  17867. function Item(fun, array) {
  17868. this.fun = fun;
  17869. this.array = array;
  17870. }
  17871. Item.prototype.run = function () {
  17872. this.fun.apply(null, this.array);
  17873. };
  17874. process.title = 'browser';
  17875. process.browser = true;
  17876. process.env = {};
  17877. process.argv = [];
  17878. process.version = ''; // empty string to avoid regexp issues
  17879. process.versions = {};
  17880. function noop() {}
  17881. process.on = noop;
  17882. process.addListener = noop;
  17883. process.once = noop;
  17884. process.off = noop;
  17885. process.removeListener = noop;
  17886. process.removeAllListeners = noop;
  17887. process.emit = noop;
  17888. process.prependListener = noop;
  17889. process.prependOnceListener = noop;
  17890. process.listeners = function (name) { return [] }
  17891. process.binding = function (name) {
  17892. throw new Error('process.binding is not supported');
  17893. };
  17894. process.cwd = function () { return '/' };
  17895. process.chdir = function (dir) {
  17896. throw new Error('process.chdir is not supported');
  17897. };
  17898. process.umask = function() { return 0; };
  17899. /***/ }),
  17900. /***/ "./node_modules/webpack/buildin/global.js":
  17901. /*!***********************************!*\
  17902. !*** (webpack)/buildin/global.js ***!
  17903. \***********************************/
  17904. /*! no static exports found */
  17905. /***/ (function(module, exports) {
  17906. var g;
  17907. // This works in non-strict mode
  17908. g = (function() {
  17909. return this;
  17910. })();
  17911. try {
  17912. // This works if eval is allowed (see CSP)
  17913. g = g || new Function("return this")();
  17914. } catch (e) {
  17915. // This works if the window reference is available
  17916. if (typeof window === "object") g = window;
  17917. }
  17918. // g can still be undefined, but nothing to do about it...
  17919. // We return undefined, instead of nothing here, so it's
  17920. // easier to handle this case. if(!global) { ...}
  17921. module.exports = g;
  17922. /***/ }),
  17923. /***/ "./node_modules/webpack/buildin/module.js":
  17924. /*!***********************************!*\
  17925. !*** (webpack)/buildin/module.js ***!
  17926. \***********************************/
  17927. /*! no static exports found */
  17928. /***/ (function(module, exports) {
  17929. module.exports = function(module) {
  17930. if (!module.webpackPolyfill) {
  17931. module.deprecate = function() {};
  17932. module.paths = [];
  17933. // module.parent = undefined by default
  17934. if (!module.children) module.children = [];
  17935. Object.defineProperty(module, "loaded", {
  17936. enumerable: true,
  17937. get: function() {
  17938. return module.l;
  17939. }
  17940. });
  17941. Object.defineProperty(module, "id", {
  17942. enumerable: true,
  17943. get: function() {
  17944. return module.i;
  17945. }
  17946. });
  17947. module.webpackPolyfill = 1;
  17948. }
  17949. return module;
  17950. };
  17951. /***/ }),
  17952. /***/ "./resources/css/app.css":
  17953. /*!*******************************!*\
  17954. !*** ./resources/css/app.css ***!
  17955. \*******************************/
  17956. /*! no static exports found */
  17957. /***/ (function(module, exports) {
  17958. // removed by extract-text-webpack-plugin
  17959. /***/ }),
  17960. /***/ "./resources/js/app.js":
  17961. /*!*****************************!*\
  17962. !*** ./resources/js/app.js ***!
  17963. \*****************************/
  17964. /*! no static exports found */
  17965. /***/ (function(module, exports, __webpack_require__) {
  17966. __webpack_require__(/*! ./bootstrap */ "./resources/js/bootstrap.js");
  17967. /***/ }),
  17968. /***/ "./resources/js/bootstrap.js":
  17969. /*!***********************************!*\
  17970. !*** ./resources/js/bootstrap.js ***!
  17971. \***********************************/
  17972. /*! no static exports found */
  17973. /***/ (function(module, exports, __webpack_require__) {
  17974. window._ = __webpack_require__(/*! lodash */ "./node_modules/lodash/lodash.js");
  17975. /**
  17976. * We'll load the axios HTTP library which allows us to easily issue requests
  17977. * to our Laravel back-end. This library automatically handles sending the
  17978. * CSRF token as a header based on the value of the "XSRF" token cookie.
  17979. */
  17980. window.axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  17981. window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  17982. /**
  17983. * Echo exposes an expressive API for subscribing to channels and listening
  17984. * for events that are broadcast by Laravel. Echo and event broadcasting
  17985. * allows your team to easily build robust real-time web applications.
  17986. */
  17987. // import Echo from 'laravel-echo';
  17988. // window.Pusher = require('pusher-js');
  17989. // window.Echo = new Echo({
  17990. // broadcaster: 'pusher',
  17991. // key: process.env.MIX_PUSHER_APP_KEY,
  17992. // cluster: process.env.MIX_PUSHER_APP_CLUSTER,
  17993. // forceTLS: true
  17994. // });
  17995. /***/ }),
  17996. /***/ 0:
  17997. /*!***********************************************************!*\
  17998. !*** multi ./resources/js/app.js ./resources/css/app.css ***!
  17999. \***********************************************************/
  18000. /*! no static exports found */
  18001. /***/ (function(module, exports, __webpack_require__) {
  18002. __webpack_require__(/*! C:\Users\KL\Desktop\marvel\resources\js\app.js */"./resources/js/app.js");
  18003. module.exports = __webpack_require__(/*! C:\Users\KL\Desktop\marvel\resources\css\app.css */"./resources/css/app.css");
  18004. /***/ })
  18005. /******/ });