PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/underscore/underscore.d.ts

https://github.com/F0rt1s/DefinitelyTyped
TypeScript Typings | 3149 lines | 711 code | 458 blank | 1980 comment | 3 complexity | e2a644cd429751103f9c00f1fa70a2e0 MD5 | raw file
Possible License(s): MIT
  1. // Type definitions for Underscore 1.6.0
  2. // Project: http://underscorejs.org/
  3. // Definitions by: Boris Yankov <https://github.com/borisyankov/>
  4. // Definitions by: Josh Baldwin <https://github.com/jbaldwin/>
  5. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  6. declare module _ {
  7. /**
  8. * underscore.js _.throttle options.
  9. **/
  10. interface ThrottleSettings {
  11. /**
  12. * If you'd like to disable the leading-edge call, pass this as false.
  13. **/
  14. leading?: boolean;
  15. /**
  16. * If you'd like to disable the execution on the trailing-edge, pass false.
  17. **/
  18. trailing?: boolean;
  19. }
  20. /**
  21. * underscore.js template settings, set templateSettings or pass as an argument
  22. * to 'template()' to override defaults.
  23. **/
  24. interface TemplateSettings {
  25. /**
  26. * Default value is '/<%([\s\S]+?)%>/g'.
  27. **/
  28. evaluate?: RegExp;
  29. /**
  30. * Default value is '/<%=([\s\S]+?)%>/g'.
  31. **/
  32. interpolate?: RegExp;
  33. /**
  34. * Default value is '/<%-([\s\S]+?)%>/g'.
  35. **/
  36. escape?: RegExp;
  37. }
  38. interface ListIterator<T, TResult> {
  39. (value: T, index: number, list: T[]): TResult;
  40. }
  41. interface ObjectIterator<T, TResult> {
  42. (element: T, key: string, list: any): TResult;
  43. }
  44. interface MemoIterator<T, TResult> {
  45. (prev: TResult, curr: T, index: number, list: T[]): TResult;
  46. }
  47. interface Collection<T> { }
  48. // Common interface between Arrays and jQuery objects
  49. interface List<T> extends Collection<T> {
  50. [index: number]: T;
  51. length: number;
  52. }
  53. interface Dictionary<T> extends Collection<T> {
  54. [index: string]: T;
  55. }
  56. }
  57. interface UnderscoreStatic {
  58. /**
  59. * Underscore OOP Wrapper, all Underscore functions that take an object
  60. * as the first parameter can be invoked through this function.
  61. * @param key First argument to Underscore object functions.
  62. **/
  63. <T>(value: Array<T>): Underscore<T>;
  64. <T>(value: T): Underscore<T>;
  65. /* *************
  66. * Collections *
  67. ************* */
  68. /**
  69. * Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is
  70. * bound to the context object, if one is passed. Each invocation of iterator is called with three
  71. * arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be
  72. * (value, key, object). Delegates to the native forEach function if it exists.
  73. * @param list Iterates over this list of elements.
  74. * @param iterator Iterator function for each element `list`.
  75. * @param context 'this' object in `iterator`, optional.
  76. **/
  77. each<T>(
  78. list: _.List<T>,
  79. iterator: _.ListIterator<T, void>,
  80. context?: any): _.List<T>;
  81. /**
  82. * @see _.each
  83. * @param object Iterates over properties of this object.
  84. * @param iterator Iterator function for each property on `object`.
  85. * @param context 'this' object in `iterator`, optional.
  86. **/
  87. each<T>(
  88. object: _.Dictionary<T>,
  89. iterator: _.ObjectIterator<T, void>,
  90. context?: any): _.Dictionary<T>;
  91. /**
  92. * @see _.each
  93. **/
  94. forEach<T>(
  95. list: _.List<T>,
  96. iterator: _.ListIterator<T, void>,
  97. context?: any): _.List<T>;
  98. /**
  99. * @see _.each
  100. **/
  101. forEach<T>(
  102. object: _.Dictionary<T>,
  103. iterator: _.ObjectIterator<T, void>,
  104. context?: any): _.Dictionary<T>;
  105. /**
  106. * Produces a new array of values by mapping each value in list through a transformation function
  107. * (iterator). If the native map method exists, it will be used instead. If list is a JavaScript
  108. * object, iterator's arguments will be (value, key, object).
  109. * @param list Maps the elements of this array.
  110. * @param iterator Map iterator function for each element in `list`.
  111. * @param context `this` object in `iterator`, optional.
  112. * @return The mapped array result.
  113. **/
  114. map<T, TResult>(
  115. list: _.List<T>,
  116. iterator: _.ListIterator<T, TResult>,
  117. context?: any): TResult[];
  118. /**
  119. * @see _.map
  120. * @param object Maps the properties of this object.
  121. * @param iterator Map iterator function for each property on `object`.
  122. * @param context `this` object in `iterator`, optional.
  123. * @return The mapped object result.
  124. **/
  125. map<T, TResult>(
  126. object: _.Dictionary<T>,
  127. iterator: _.ObjectIterator<T, TResult>,
  128. context?: any): TResult[];
  129. /**
  130. * @see _.map
  131. **/
  132. collect<T, TResult>(
  133. list: _.List<T>,
  134. iterator: _.ListIterator<T, TResult>,
  135. context?: any): TResult[];
  136. /**
  137. * @see _.map
  138. **/
  139. collect<T, TResult>(
  140. object: _.Dictionary<T>,
  141. iterator: _.ObjectIterator<T, TResult>,
  142. context?: any): TResult[];
  143. /**
  144. * Also known as inject and foldl, reduce boils down a list of values into a single value.
  145. * Memo is the initial state of the reduction, and each successive step of it should be
  146. * returned by iterator. The iterator is passed four arguments: the memo, then the value
  147. * and index (or key) of the iteration, and finally a reference to the entire list.
  148. * @param list Reduces the elements of this array.
  149. * @param iterator Reduce iterator function for each element in `list`.
  150. * @param memo Initial reduce state.
  151. * @param context `this` object in `iterator`, optional.
  152. * @return Reduced object result.
  153. **/
  154. reduce<T, TResult>(
  155. list: _.Collection<T>,
  156. iterator: _.MemoIterator<T, TResult>,
  157. memo?: TResult,
  158. context?: any): TResult;
  159. /**
  160. * @see _.reduce
  161. **/
  162. inject<T, TResult>(
  163. list: _.Collection<T>,
  164. iterator: _.MemoIterator<T, TResult>,
  165. memo?: TResult,
  166. context?: any): TResult;
  167. /**
  168. * @see _.reduce
  169. **/
  170. foldl<T, TResult>(
  171. list: _.Collection<T>,
  172. iterator: _.MemoIterator<T, TResult>,
  173. memo?: TResult,
  174. context?: any): TResult;
  175. /**
  176. * The right-associative version of reduce. Delegates to the JavaScript 1.8 version of
  177. * reduceRight, if it exists. `foldr` is not as useful in JavaScript as it would be in a
  178. * language with lazy evaluation.
  179. * @param list Reduces the elements of this array.
  180. * @param iterator Reduce iterator function for each element in `list`.
  181. * @param memo Initial reduce state.
  182. * @param context `this` object in `iterator`, optional.
  183. * @return Reduced object result.
  184. **/
  185. reduceRight<T, TResult>(
  186. list: _.Collection<T>,
  187. iterator: _.MemoIterator<T, TResult>,
  188. memo?: TResult,
  189. context?: any): TResult;
  190. /**
  191. * @see _.reduceRight
  192. **/
  193. foldr<T, TResult>(
  194. list: _.Collection<T>,
  195. iterator: _.MemoIterator<T, TResult>,
  196. memo?: TResult,
  197. context?: any): TResult;
  198. /**
  199. * Looks through each value in the list, returning the first one that passes a truth
  200. * test (iterator). The function returns as soon as it finds an acceptable element,
  201. * and doesn't traverse the entire list.
  202. * @param list Searches for a value in this list.
  203. * @param iterator Search iterator function for each element in `list`.
  204. * @param context `this` object in `iterator`, optional.
  205. * @return The first acceptable found element in `list`, if nothing is found undefined/null is returned.
  206. **/
  207. find<T>(
  208. list: _.List<T>,
  209. iterator: _.ListIterator<T, boolean>,
  210. context?: any): T;
  211. /**
  212. * @see _.find
  213. **/
  214. find<T>(
  215. object: _.Dictionary<T>,
  216. iterator: _.ObjectIterator<T, boolean>,
  217. context?: any): T;
  218. /**
  219. * @see _.find
  220. **/
  221. detect<T>(
  222. list: _.List<T>,
  223. iterator: _.ListIterator<T, boolean>,
  224. context?: any): T;
  225. /**
  226. * @see _.find
  227. **/
  228. detect<T>(
  229. object: _.Dictionary<T>,
  230. iterator: _.ObjectIterator<T, boolean>,
  231. context?: any): T;
  232. /**
  233. * Looks through each value in the list, returning an array of all the values that pass a truth
  234. * test (iterator). Delegates to the native filter method, if it exists.
  235. * @param list Filter elements out of this list.
  236. * @param iterator Filter iterator function for each element in `list`.
  237. * @param context `this` object in `iterator`, optional.
  238. * @return The filtered list of elements.
  239. **/
  240. filter<T>(
  241. list: _.List<T>,
  242. iterator: _.ListIterator<T, boolean>,
  243. context?: any): T[];
  244. /**
  245. * @see _.filter
  246. **/
  247. filter<T>(
  248. object: _.Dictionary<T>,
  249. iterator: _.ObjectIterator<T, boolean>,
  250. context?: any): T[];
  251. /**
  252. * @see _.filter
  253. **/
  254. select<T>(
  255. list: _.List<T>,
  256. iterator: _.ListIterator<T, boolean>,
  257. context?: any): T[];
  258. /**
  259. * @see _.filter
  260. **/
  261. select<T>(
  262. object: _.Dictionary<T>,
  263. iterator: _.ObjectIterator<T, boolean>,
  264. context?: any): T[];
  265. /**
  266. * Looks through each value in the list, returning an array of all the values that contain all
  267. * of the key-value pairs listed in properties.
  268. * @param list List to match elements again `properties`.
  269. * @param properties The properties to check for on each element within `list`.
  270. * @return The elements within `list` that contain the required `properties`.
  271. **/
  272. where<T, U extends {}>(
  273. list: _.List<T>,
  274. properties: U): T[];
  275. /**
  276. * Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.
  277. * @param list Search through this list's elements for the first object with all `properties`.
  278. * @param properties Properties to look for on the elements within `list`.
  279. * @return The first element in `list` that has all `properties`.
  280. **/
  281. findWhere<T, U extends {}>(
  282. list: _.List<T>,
  283. properties: U): T;
  284. /**
  285. * Returns the values in list without the elements that the truth test (iterator) passes.
  286. * The opposite of filter.
  287. * Return all the elements for which a truth test fails.
  288. * @param list Reject elements within this list.
  289. * @param iterator Reject iterator function for each element in `list`.
  290. * @param context `this` object in `iterator`, optional.
  291. * @return The rejected list of elements.
  292. **/
  293. reject<T>(
  294. list: _.List<T>,
  295. iterator: _.ListIterator<T, boolean>,
  296. context?: any): T[];
  297. /**
  298. * @see _.reject
  299. **/
  300. reject<T>(
  301. object: _.Dictionary<T>,
  302. iterator: _.ObjectIterator<T, boolean>,
  303. context?: any): T[];
  304. /**
  305. * Returns true if all of the values in the list pass the iterator truth test. Delegates to the
  306. * native method every, if present.
  307. * @param list Truth test against all elements within this list.
  308. * @param iterator Trust test iterator function for each element in `list`.
  309. * @param context `this` object in `iterator`, optional.
  310. * @return True if all elements passed the truth test, otherwise false.
  311. **/
  312. every<T>(
  313. list: _.List<T>,
  314. iterator?: _.ListIterator<T, boolean>,
  315. context?: any): boolean;
  316. /**
  317. * @see _.every
  318. **/
  319. every<T>(
  320. list: _.Dictionary<T>,
  321. iterator?: _.ObjectIterator<T, boolean>,
  322. context?: any): boolean;
  323. /**
  324. * @see _.every
  325. **/
  326. all<T>(
  327. list: _.List<T>,
  328. iterator?: _.ListIterator<T, boolean>,
  329. context?: any): boolean;
  330. /**
  331. * @see _.every
  332. **/
  333. all<T>(
  334. list: _.Dictionary<T>,
  335. iterator?: _.ObjectIterator<T, boolean>,
  336. context?: any): boolean;
  337. /**
  338. * Returns true if any of the values in the list pass the iterator truth test. Short-circuits and
  339. * stops traversing the list if a true element is found. Delegates to the native method some, if present.
  340. * @param list Truth test against all elements within this list.
  341. * @param iterator Trust test iterator function for each element in `list`.
  342. * @param context `this` object in `iterator`, optional.
  343. * @return True if any elements passed the truth test, otherwise false.
  344. **/
  345. some<T>(
  346. list: _.List<T>,
  347. iterator?: _.ListIterator<T, boolean>,
  348. context?: any): boolean;
  349. /**
  350. * @see _.some
  351. **/
  352. some<T>(
  353. object: _.Dictionary<T>,
  354. iterator?: _.ObjectIterator<T, boolean>,
  355. context?: any): boolean;
  356. /**
  357. * @see _.some
  358. **/
  359. any<T>(
  360. list: _.List<T>,
  361. iterator?: _.ListIterator<T, boolean>,
  362. context?: any): boolean;
  363. /**
  364. * @see _.some
  365. **/
  366. any<T>(
  367. object: _.Dictionary<T>,
  368. iterator?: _.ObjectIterator<T, boolean>,
  369. context?: any): boolean;
  370. /**
  371. * Returns true if the value is present in the list. Uses indexOf internally,
  372. * if list is an Array.
  373. * @param list Checks each element to see if `value` is present.
  374. * @param value The value to check for within `list`.
  375. * @return True if `value` is present in `list`, otherwise false.
  376. **/
  377. contains<T>(
  378. list: _.List<T>,
  379. value: T): boolean;
  380. /**
  381. * @see _.contains
  382. **/
  383. contains<T>(
  384. object: _.Dictionary<T>,
  385. value: T): boolean;
  386. /**
  387. * @see _.contains
  388. **/
  389. include<T>(
  390. list: _.Collection<T>,
  391. value: T): boolean;
  392. /**
  393. * @see _.contains
  394. **/
  395. include<T>(
  396. object: _.Dictionary<T>,
  397. value: T): boolean;
  398. /**
  399. * Calls the method named by methodName on each value in the list. Any extra arguments passed to
  400. * invoke will be forwarded on to the method invocation.
  401. * @param list The element's in this list will each have the method `methodName` invoked.
  402. * @param methodName The method's name to call on each element within `list`.
  403. * @param arguments Additional arguments to pass to the method `methodName`.
  404. **/
  405. invoke<T extends {}>(
  406. list: _.List<T>,
  407. methodName: string,
  408. ...arguments: any[]): any;
  409. /**
  410. * A convenient version of what is perhaps the most common use-case for map: extracting a list of
  411. * property values.
  412. * @param list The list to pluck elements out of that have the property `propertyName`.
  413. * @param propertyName The property to look for on each element within `list`.
  414. * @return The list of elements within `list` that have the property `propertyName`.
  415. **/
  416. pluck<T extends {}>(
  417. list: _.List<T>,
  418. propertyName: string): any[];
  419. /**
  420. * Returns the maximum value in list.
  421. * @param list Finds the maximum value in this list.
  422. * @return Maximum value in `list`.
  423. **/
  424. max(list: _.List<number>): number;
  425. /**
  426. * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate
  427. * the criterion by which the value is ranked.
  428. * @param list Finds the maximum value in this list.
  429. * @param iterator Compares each element in `list` to find the maximum value.
  430. * @param context `this` object in `iterator`, optional.
  431. * @return The maximum element within `list`.
  432. **/
  433. max<T>(
  434. list: _.List<T>,
  435. iterator?: _.ListIterator<T, any>,
  436. context?: any): T;
  437. /**
  438. * Returns the minimum value in list.
  439. * @param list Finds the minimum value in this list.
  440. * @return Minimum value in `list`.
  441. **/
  442. min(list: _.List<number>): number;
  443. /**
  444. * Returns the minimum value in list. If iterator is passed, it will be used on each value to generate
  445. * the criterion by which the value is ranked.
  446. * @param list Finds the minimum value in this list.
  447. * @param iterator Compares each element in `list` to find the minimum value.
  448. * @param context `this` object in `iterator`, optional.
  449. * @return The minimum element within `list`.
  450. **/
  451. min<T>(
  452. list: _.List<T>,
  453. iterator?: _.ListIterator<T, any>,
  454. context?: any): T;
  455. /**
  456. * Returns a sorted copy of list, ranked in ascending order by the results of running each value
  457. * through iterator. Iterator may also be the string name of the property to sort by (eg. length).
  458. * @param list Sorts this list.
  459. * @param iterator Sort iterator for each element within `list`.
  460. * @param context `this` object in `iterator`, optional.
  461. * @return A sorted copy of `list`.
  462. **/
  463. sortBy<T, TSort>(
  464. list: _.List<T>,
  465. iterator?: _.ListIterator<T, TSort>,
  466. context?: any): T[];
  467. /**
  468. * @see _.sortBy
  469. * @param iterator Sort iterator for each element within `list`.
  470. **/
  471. sortBy<T>(
  472. list: _.List<T>,
  473. iterator: string,
  474. context?: any): T[];
  475. /**
  476. * Splits a collection into sets, grouped by the result of running each value through iterator.
  477. * If iterator is a string instead of a function, groups by the property named by iterator on
  478. * each of the values.
  479. * @param list Groups this list.
  480. * @param iterator Group iterator for each element within `list`, return the key to group the element by.
  481. * @param context `this` object in `iterator`, optional.
  482. * @return An object with the group names as properties where each property contains the grouped elements from `list`.
  483. **/
  484. groupBy<T>(
  485. list: _.List<T>,
  486. iterator?: _.ListIterator<T, any>,
  487. context?: any): _.Dictionary<T[]>;
  488. /**
  489. * @see _.groupBy
  490. * @param iterator Property on each object to group them by.
  491. **/
  492. groupBy<T>(
  493. list: _.List<T>,
  494. iterator: string,
  495. context?: any): _.Dictionary<T[]>;
  496. /**
  497. * Given a `list`, and an `iterator` function that returns a key for each element in the list (or a property name),
  498. * returns an object with an index of each item. Just like _.groupBy, but for when you know your keys are unique.
  499. **/
  500. indexBy<T>(
  501. list: _.List<T>,
  502. iterator: _.ListIterator<T, any>,
  503. context?: any): _.Dictionary<T>;
  504. /**
  505. * @see _.indexBy
  506. * @param iterator Property on each object to index them by.
  507. **/
  508. indexBy<T>(
  509. list: _.List<T>,
  510. iterator: string,
  511. context?: any): _.Dictionary<T>;
  512. /**
  513. * Sorts a list into groups and returns a count for the number of objects in each group. Similar
  514. * to groupBy, but instead of returning a list of values, returns a count for the number of values
  515. * in that group.
  516. * @param list Group elements in this list and then count the number of elements in each group.
  517. * @param iterator Group iterator for each element within `list`, return the key to group the element by.
  518. * @param context `this` object in `iterator`, optional.
  519. * @return An object with the group names as properties where each property contains the number of elements in that group.
  520. **/
  521. countBy<T>(
  522. list: _.List<T>,
  523. iterator?: _.ListIterator<T, any>,
  524. context?: any): _.Dictionary<number>;
  525. /**
  526. * @see _.countBy
  527. * @param iterator Function name
  528. **/
  529. countBy<T>(
  530. list: _.List<T>,
  531. iterator: string,
  532. context?: any): _.Dictionary<number>;
  533. /**
  534. * Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle.
  535. * @param list List to shuffle.
  536. * @return Shuffled copy of `list`.
  537. **/
  538. shuffle<T>(list: _.Collection<T>): T[];
  539. /**
  540. * Produce a random sample from the `list`. Pass a number to return `n` random elements from the list. Otherwise a single random item will be returned.
  541. * @param list List to sample.
  542. * @return Random sample of `n` elements in `list`.
  543. **/
  544. sample<T>(list: _.Collection<T>, n: number): T[];
  545. /**
  546. * @see _.sample
  547. **/
  548. sample<T>(list: _.Collection<T>): T;
  549. /**
  550. * Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting
  551. * the arguments object.
  552. * @param list object to transform into an array.
  553. * @return `list` as an array.
  554. **/
  555. toArray<T>(list: _.Collection<T>): T[];
  556. /**
  557. * Return the number of values in the list.
  558. * @param list Count the number of values/elements in this list.
  559. * @return Number of values in `list`.
  560. **/
  561. size<T>(list: _.Collection<T>): number;
  562. /**
  563. * Split array into two arrays:
  564. * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
  565. * @param array Array to split in two.
  566. * @param iterator Filter iterator function for each element in `array`.
  567. * @param context `this` object in `iterator`, optional.
  568. * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not.
  569. **/
  570. partition<T>(
  571. array: Array<T>,
  572. iterator: _.ListIterator<T, boolean>,
  573. context?: any): T[][];
  574. /*********
  575. * Arrays *
  576. **********/
  577. /**
  578. * Returns the first element of an array. Passing n will return the first n elements of the array.
  579. * @param array Retrieves the first element of this array.
  580. * @return Returns the first element of `array`.
  581. **/
  582. first<T>(array: _.List<T>): T;
  583. /**
  584. * @see _.first
  585. * @param n Return more than one element from `array`.
  586. **/
  587. first<T>(
  588. array: _.List<T>,
  589. n: number): T[];
  590. /**
  591. * @see _.first
  592. **/
  593. head<T>(array: _.List<T>): T;
  594. /**
  595. * @see _.first
  596. **/
  597. head<T>(
  598. array: _.List<T>,
  599. n: number): T[];
  600. /**
  601. * @see _.first
  602. **/
  603. take<T>(array: _.List<T>): T;
  604. /**
  605. * @see _.first
  606. **/
  607. take<T>(
  608. array: _.List<T>,
  609. n: number): T[];
  610. /**
  611. * Returns everything but the last entry of the array. Especially useful on the arguments object.
  612. * Pass n to exclude the last n elements from the result.
  613. * @param array Retrieve all elements except the last `n`.
  614. * @param n Leaves this many elements behind, optional.
  615. * @return Returns everything but the last `n` elements of `array`.
  616. **/
  617. initial<T>(
  618. array: _.List<T>,
  619. n?: number): T[];
  620. /**
  621. * Returns the last element of an array. Passing n will return the last n elements of the array.
  622. * @param array Retrieves the last element of this array.
  623. * @return Returns the last element of `array`.
  624. **/
  625. last<T>(array: _.List<T>): T;
  626. /**
  627. * @see _.last
  628. * @param n Return more than one element from `array`.
  629. **/
  630. last<T>(
  631. array: _.List<T>,
  632. n: number): T[];
  633. /**
  634. * Returns the rest of the elements in an array. Pass an index to return the values of the array
  635. * from that index onward.
  636. * @param array The array to retrieve all but the first `index` elements.
  637. * @param n The index to start retrieving elements forward from, optional, default = 1.
  638. * @return Returns the elements of `array` from `index` to the end of `array`.
  639. **/
  640. rest<T>(
  641. array: _.List<T>,
  642. n?: number): T[];
  643. /**
  644. * @see _.rest
  645. **/
  646. tail<T>(
  647. array: _.List<T>,
  648. n?: number): T[];
  649. /**
  650. * @see _.rest
  651. **/
  652. drop<T>(
  653. array: _.List<T>,
  654. n?: number): T[];
  655. /**
  656. * Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, "",
  657. * undefined and NaN are all falsy.
  658. * @param array Array to compact.
  659. * @return Copy of `array` without false values.
  660. **/
  661. compact<T>(array: _.List<T>): T[];
  662. /**
  663. * Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will
  664. * only be flattened a single level.
  665. * @param array The array to flatten.
  666. * @param shallow If true then only flatten one level, optional, default = false.
  667. * @return `array` flattened.
  668. **/
  669. flatten(
  670. array: _.List<any>,
  671. shallow?: boolean): any[];
  672. /**
  673. * Returns a copy of the array with all instances of the values removed.
  674. * @param array The array to remove `values` from.
  675. * @param values The values to remove from `array`.
  676. * @return Copy of `array` without `values`.
  677. **/
  678. without<T>(
  679. array: _.List<T>,
  680. ...values: T[]): T[];
  681. /**
  682. * Computes the union of the passed-in arrays: the list of unique items, in order, that are
  683. * present in one or more of the arrays.
  684. * @param arrays Array of arrays to compute the union of.
  685. * @return The union of elements within `arrays`.
  686. **/
  687. union<T>(...arrays: _.List<T>[]): T[];
  688. /**
  689. * Computes the list of values that are the intersection of all the arrays. Each value in the result
  690. * is present in each of the arrays.
  691. * @param arrays Array of arrays to compute the intersection of.
  692. * @return The intersection of elements within `arrays`.
  693. **/
  694. intersection<T>(...arrays: _.List<T>[]): T[];
  695. /**
  696. * Similar to without, but returns the values from array that are not present in the other arrays.
  697. * @param array Keeps values that are within `others`.
  698. * @param others The values to keep within `array`.
  699. * @return Copy of `array` with only `others` values.
  700. **/
  701. difference<T>(
  702. array: _.List<T>,
  703. ...others: _.List<T>[]): T[];
  704. /**
  705. * Produces a duplicate-free version of the array, using === to test object equality. If you know in
  706. * advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If
  707. * you want to compute unique items based on a transformation, pass an iterator function.
  708. * @param array Array to remove duplicates from.
  709. * @param isSorted True if `array` is already sorted, optional, default = false.
  710. * @param iterator Transform the elements of `array` before comparisons for uniqueness.
  711. * @param context 'this' object in `iterator`, optional.
  712. * @return Copy of `array` where all elements are unique.
  713. **/
  714. uniq<T, TSort>(
  715. array: _.List<T>,
  716. isSorted?: boolean,
  717. iterator?: _.ListIterator<T, TSort>,
  718. context?: any): T[];
  719. /**
  720. * @see _.uniq
  721. **/
  722. uniq<T, TSort>(
  723. array: _.List<T>,
  724. iterator?: _.ListIterator<T, TSort>,
  725. context?: any): T[];
  726. /**
  727. * @see _.uniq
  728. **/
  729. unique<T, TSort>(
  730. array: _.List<T>,
  731. iterator?: _.ListIterator<T, TSort>,
  732. context?: any): T[];
  733. /**
  734. * @see _.uniq
  735. **/
  736. unique<T, TSort>(
  737. array: _.List<T>,
  738. isSorted?: boolean,
  739. iterator?: _.ListIterator<T, TSort>,
  740. context?: any): T[];
  741. /**
  742. * Merges together the values of each of the arrays with the values at the corresponding position.
  743. * Useful when you have separate data sources that are coordinated through matching array indexes.
  744. * If you're working with a matrix of nested arrays, zip.apply can transpose the matrix in a similar fashion.
  745. * @param arrays The arrays to merge/zip.
  746. * @return Zipped version of `arrays`.
  747. **/
  748. zip(...arrays: any[][]): any[][];
  749. /**
  750. * @see _.zip
  751. **/
  752. zip(...arrays: any[]): any[];
  753. /**
  754. * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
  755. * list of keys, and a list of values.
  756. * @param keys Key array.
  757. * @param values Value array.
  758. * @return An object containing the `keys` as properties and `values` as the property values.
  759. **/
  760. object<TResult extends {}>(
  761. keys: _.List<string>,
  762. values: _.List<any>): TResult;
  763. /**
  764. * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
  765. * list of keys, and a list of values.
  766. * @param keyValuePairs Array of [key, value] pairs.
  767. * @return An object containing the `keys` as properties and `values` as the property values.
  768. **/
  769. object<TResult extends {}>(...keyValuePairs: any[][]): TResult;
  770. /**
  771. * @see _.object
  772. **/
  773. object<TResult extends {}>(
  774. list: _.List<any>,
  775. values?: any): TResult;
  776. /**
  777. * Returns the index at which value can be found in the array, or -1 if value is not present in the array.
  778. * Uses the native indexOf function unless it's missing. If you're working with a large array, and you know
  779. * that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number
  780. * as the third argument in order to look for the first matching value in the array after the given index.
  781. * @param array The array to search for the index of `value`.
  782. * @param value The value to search for within `array`.
  783. * @param isSorted True if the array is already sorted, optional, default = false.
  784. * @return The index of `value` within `array`.
  785. **/
  786. indexOf<T>(
  787. array: _.List<T>,
  788. value: T,
  789. isSorted?: boolean): number;
  790. /**
  791. * @see _indexof
  792. **/
  793. indexOf<T>(
  794. array: _.List<T>,
  795. value: T,
  796. startFrom: number): number;
  797. /**
  798. * Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the
  799. * native lastIndexOf function if possible. Pass fromIndex to start your search at a given index.
  800. * @param array The array to search for the last index of `value`.
  801. * @param value The value to search for within `array`.
  802. * @param from The starting index for the search, optional.
  803. * @return The index of the last occurrence of `value` within `array`.
  804. **/
  805. lastIndexOf<T>(
  806. array: _.List<T>,
  807. value: T,
  808. from?: number): number;
  809. /**
  810. * Uses a binary search to determine the index at which the value should be inserted into the list in order
  811. * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking
  812. * of each value, including the value you pass.
  813. * @param list The sorted list.
  814. * @param value The value to determine its index within `list`.
  815. * @param iterator Iterator to compute the sort ranking of each value, optional.
  816. * @return The index where `value` should be inserted into `list`.
  817. **/
  818. sortedIndex<T, TSort>(
  819. list: _.List<T>,
  820. value: T,
  821. iterator?: (x: T) => TSort, context?: any): number;
  822. /**
  823. * A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted,
  824. * defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented)
  825. * by step, exclusive.
  826. * @param start Start here.
  827. * @param stop Stop here.
  828. * @param step The number to count up by each iteration, optional, default = 1.
  829. * @return Array of numbers from `start` to `stop` with increments of `step`.
  830. **/
  831. range(
  832. start: number,
  833. stop: number,
  834. step?: number): number[];
  835. /**
  836. * @see _.range
  837. * @param stop Stop here.
  838. * @return Array of numbers from 0 to `stop` with increments of 1.
  839. * @note If start is not specified the implementation will never pull the step (step = arguments[2] || 0)
  840. **/
  841. range(stop: number): number[];
  842. /*************
  843. * Functions *
  844. *************/
  845. /**
  846. * Bind a function to an object, meaning that whenever the function is called, the value of this will
  847. * be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application.
  848. * @param func The function to bind `this` to `object`.
  849. * @param context The `this` pointer whenever `fn` is called.
  850. * @param arguments Additional arguments to pass to `fn` when called.
  851. * @return `fn` with `this` bound to `object`.
  852. **/
  853. bind(
  854. func: Function,
  855. context: any,
  856. ...arguments: any[]): () => any;
  857. /**
  858. * Binds a number of methods on the object, specified by methodNames, to be run in the context of that object
  859. * whenever they are invoked. Very handy for binding functions that are going to be used as event handlers,
  860. * which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the
  861. * object's function properties will be bound to it.
  862. * @param object The object to bind the methods `methodName` to.
  863. * @param methodNames The methods to bind to `object`, optional and if not provided all of `object`'s
  864. * methods are bound.
  865. **/
  866. bindAll(
  867. object: any,
  868. ...methodNames: string[]): any;
  869. /**
  870. * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value.
  871. * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be
  872. * pre-filled, but left open to supply at call-time.
  873. * @param fn Function to partially fill in arguments.
  874. * @param arguments The partial arguments.
  875. * @return `fn` with partially filled in arguments.
  876. **/
  877. partial(
  878. fn: Function,
  879. ...arguments: any[]): Function;
  880. /**
  881. * Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations.
  882. * If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based
  883. * on the arguments to the original function. The default hashFunction just uses the first argument to the
  884. * memoized function as the key.
  885. * @param fn Computationally expensive function that will now memoized results.
  886. * @param hashFn Hash function for storing the result of `fn`.
  887. * @return Memoized version of `fn`.
  888. **/
  889. memoize(
  890. fn: Function,
  891. hashFn?: (...args: any[]) => string): Function;
  892. /**
  893. * Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments,
  894. * they will be forwarded on to the function when it is invoked.
  895. * @param func Function to delay `waitMS` amount of ms.
  896. * @param wait The amount of milliseconds to delay `fn`.
  897. * @arguments Additional arguments to pass to `fn`.
  898. **/
  899. delay(
  900. func: Function,
  901. wait: number,
  902. ...arguments: any[]): any;
  903. /**
  904. * @see _delay
  905. **/
  906. delay(
  907. func: Function,
  908. ...arguments: any[]): any;
  909. /**
  910. * Defers invoking the function until the current call stack has cleared, similar to using setTimeout
  911. * with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without
  912. * blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on
  913. * to the function when it is invoked.
  914. * @param fn The function to defer.
  915. * @param arguments Additional arguments to pass to `fn`.
  916. **/
  917. defer(
  918. fn: Function,
  919. ...arguments: any[]): void;
  920. /**
  921. * Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly,
  922. * will only actually call the original function at most once per every wait milliseconds. Useful for
  923. * rate-limiting events that occur faster than you can keep up with.
  924. * By default, throttle will execute the function as soon as you call it for the first time, and,
  925. * if you call it again any number of times during the wait period, as soon as that period is over.
  926. * If you'd like to disable the leading-edge call, pass {leading: false}, and if you'd like to disable
  927. * the execution on the trailing-edge, pass {trailing: false}.
  928. * @param func Function to throttle `waitMS` ms.
  929. * @param wait The number of milliseconds to wait before `fn` can be invoked again.
  930. * @param options Allows for disabling execution of the throttled function on either the leading or trailing edge.
  931. * @return `fn` with a throttle of `wait`.
  932. **/
  933. throttle(
  934. func: any,
  935. wait: number,
  936. options?: _.ThrottleSettings): Function;
  937. /**
  938. * Creates and returns a new debounced version of the passed function that will postpone its execution
  939. * until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing
  940. * behavior that should only happen after the input has stopped arriving. For example: rendering a preview
  941. * of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on.
  942. *
  943. * Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead
  944. * of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double
  945. *-clicks on a "submit" button from firing a second time.
  946. * @param fn Function to debounce `waitMS` ms.
  947. * @param wait The number of milliseconds to wait before `fn` can be invoked again.
  948. * @param immediate True if `fn` should be invoked on the leading edge of `waitMS` instead of the trailing edge.
  949. * @return Debounced version of `fn` that waits `wait` ms when invoked.
  950. **/
  951. debounce(
  952. fn: Function,
  953. wait: number,
  954. immediate?: boolean): Function;
  955. /**
  956. * Creates a version of the function that can only be called one time. Repeated calls to the modified
  957. * function will have no effect, returning the value from the original call. Useful for initialization
  958. * functions, instead of having to set a boolean flag and then check it later.
  959. * @param fn Function to only execute once.
  960. * @return Copy of `fn` that can only be invoked once.
  961. **/
  962. once(fn: Function): Function;
  963. /**
  964. * Creates a version of the function that will only be run after first being called count times. Useful
  965. * for grouping asynchronous responses, where you want to be sure that all the async calls have finished,
  966. * before proceeding.
  967. * @param count Number of times to be called before actually executing.
  968. * @fn The function to defer execution `count` times.
  969. * @return Copy of `fn` that will not execute until it is invoked `count` times.
  970. **/
  971. after(
  972. count: number,
  973. fn: Function): Function;
  974. /**
  975. * Wraps the first function inside of the wrapper function, passing it as the first argument. This allows
  976. * the wrapper to execute code before and after the function runs, adjust the arguments, and execute it
  977. * conditionally.
  978. * @param fn Function to wrap.
  979. * @param wrapper The function that will wrap `fn`.
  980. * @return Wrapped version of `fn.
  981. **/
  982. wrap(
  983. fn: Function,
  984. wrapper: (fn: Function, ...args: any[]) => any): Function;
  985. /**
  986. * Returns the composition of a list of functions, where each function consumes the return value of the
  987. * function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
  988. * @param functions List of functions to compose.
  989. * @return Composition of `functions`.
  990. **/
  991. compose(...functions: Function[]): Function;
  992. /**********
  993. * Objects *
  994. ***********/
  995. /**
  996. * Retrieve all the names of the object's properties.
  997. * @param object Retrieve the key or property names from this object.
  998. * @return List of all the property names on `object`.
  999. **/
  1000. keys(object: any): string[];
  1001. /**
  1002. * Return all of the values of the object's properties.
  1003. * @param object Retrieve the values of all the properties on this object.
  1004. * @return List of all the values on `object`.
  1005. **/
  1006. values(object: any): any[];
  1007. /**
  1008. * Convert an object into a list of [key, value] pairs.
  1009. * @param object Convert this object to a list of [key, value] pairs.
  1010. * @return List of [key, value] pairs on `object`.
  1011. **/
  1012. pairs(object: any): any[][];
  1013. /**
  1014. * Returns a copy of the object where the keys have become the values and the values the keys.
  1015. * For this to work, all of your object's values should be unique and string serializable.
  1016. * @param object Object to invert key/value pairs.
  1017. * @return An inverted key/value paired version of `object`.
  1018. **/
  1019. invert(object: any): any;
  1020. /**
  1021. * Returns a sorted list of the names of every method in an object - that is to say,
  1022. * the name of every function property of the object.
  1023. * @param object Object to pluck all function property names from.
  1024. * @return List of all the function names on `object`.
  1025. **/
  1026. functions(object: any): string[];
  1027. /**
  1028. * @see _functions
  1029. **/
  1030. methods(object: any): string[];
  1031. /**
  1032. * Copy all of the properties in the source objects over to the destination object, and return
  1033. * the destination object. It's in-order, so the last source will override properties of the
  1034. * same name in previous arguments.
  1035. * @param destination Object to extend all the properties from `sources`.
  1036. * @param sources Extends `destination` with all properties from these source objects.
  1037. * @return `destination` extended with all the properties from the `sources` objects.
  1038. **/
  1039. extend(
  1040. destination: any,
  1041. ...sources: any[]): any;
  1042. /**
  1043. * Return a copy of the object, filtered to only have values for the whitelisted keys
  1044. * (or array of valid keys).
  1045. * @param object Object to strip unwanted key/value pairs.
  1046. * @keys The key/value pairs to keep on `object`.
  1047. * @return Copy of `object` with only the `keys` properties.
  1048. **/
  1049. pick(
  1050. object: any,
  1051. ...keys: string[]): any;
  1052. /**
  1053. * Return a copy of the object, filtered to omit the blacklisted keys (or array of keys).
  1054. * @param object Object to strip unwanted key/value pairs.
  1055. * @param keys The key/value pairs to remove on `object`.
  1056. * @return Copy of `object` without the `keys` properties.
  1057. **/
  1058. omit(
  1059. object: any,
  1060. ...keys: string[]): any;
  1061. /**
  1062. * @see _.omit
  1063. **/
  1064. omit(
  1065. object: any,
  1066. keys: string[]): any;
  1067. /**
  1068. * Fill in null and undefined properties in object with values from the defaults objects,
  1069. * and return the object. As soon as the property is filled, further defaults will have no effect.
  1070. * @param object Fill this object with default values.
  1071. * @param defaults The default values to add to `object`.
  1072. * @return `object` with added `defaults` values.
  1073. **/
  1074. defaults(
  1075. object: any,
  1076. ...defaults: any[]): any;
  1077. /**
  1078. * Create a shallow-copied clone of the object.
  1079. * Any nested objects or arrays will be copied by reference, not duplicated.
  1080. * @param object Object to clone.
  1081. * @return Copy of `object`.
  1082. **/
  1083. clone<T>(object: T): T;
  1084. /**
  1085. * Invokes interceptor with the object, and then returns object. The primary purpose of this method
  1086. * is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  1087. * @param object Argument to `interceptor`.
  1088. * @param intercepter The function to modify `object` before continuing the method chain.
  1089. * @return Modified `object`.
  1090. **/
  1091. tap<T>(object: T, intercepter: Function): T;
  1092. /**
  1093. * Does the object contain the given key? Identical to object.hasOwnProperty(key), but uses a safe
  1094. * reference to the hasOwnProperty function, in case it's been overridden accidentally.
  1095. * @param object Object to check for `key`.
  1096. * @param key The key to check for on `object`.
  1097. * @return True if `key` is a property on `object`, otherwise false.
  1098. **/
  1099. has(object: any, key: string): boolean;
  1100. /**
  1101. * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.
  1102. * @param attrs Object with key values pair
  1103. * @return Predicate function
  1104. **/
  1105. matches<T, TResult>(attrs: T): _.ListIterator<T, TResult>;
  1106. /**
  1107. * Returns a function that will itself return the key property of any passed-in object.
  1108. * @param key Property of the object.
  1109. * @return Function which accept an object an returns the value of key in that object.
  1110. **/
  1111. property(key: string): (object: Object) => any;
  1112. /**
  1113. * Performs an optimized deep comparison between the two objects,
  1114. * to determine if they should be considered equal.
  1115. * @param object Compare to `other`.
  1116. * @param other Compare to `object`.
  1117. * @return True if `object` is equal to `other`.
  1118. **/
  1119. isEqual(object: any, other: any): boolean;
  1120. /**
  1121. * Returns true if object contains no values.
  1122. * @param object Check if this object has no properties or values.
  1123. * @return True if `object` is empty.
  1124. **/
  1125. isEmpty(object: any): boolean;
  1126. /**
  1127. * Returns true if object is a DOM element.
  1128. * @param object Check if this object is a DOM element.
  1129. * @return True if `object` is a DOM element, otherwise false.
  1130. **/
  1131. isElement(object: any): boolean;
  1132. /**
  1133. * Returns true if object is an Array.
  1134. * @param object Check if this object is an Array.
  1135. * @return True if `object` is an Array, otherwise false.
  1136. **/
  1137. isArray(object: any): boolean;
  1138. /**
  1139. * Returns true if value is an Object. Note that JavaScript arrays and functions are objects,
  1140. * while (normal) strings and numbers are not.
  1141. * @param object Check if this object is an Object.
  1142. * @return True of `object` is an Object, otherwise false.
  1143. **/
  1144. isObject(object: any): boolean;
  1145. /**
  1146. * Returns true if object is an Arguments object.
  1147. * @param object Check if this object is an Arguments object.
  1148. * @return True if `object` is an Arguments object, otherwise false.
  1149. **/
  1150. isArguments(object: any): boolean;
  1151. /**
  1152. * Returns true if object is a Function.
  1153. * @param object Check if this object is a Function.
  1154. * @return True if `object` is a Function, otherwise false.
  1155. **/
  1156. isFunction(object: any): boolean;
  1157. /**
  1158. * Returns true if object is a String.
  1159. * @param object Check if this object is a String.
  1160. * @return True if `object` is a String, otherwise false.
  1161. **/
  1162. isString(object: any): boolean;
  1163. /**
  1164. * Returns true if object is a Number (including NaN).
  1165. * @param object Check if this object is a Number.
  1166. * @return True if `object` is a Number, otherwise false.
  1167. **/
  1168. isNumber(object: any): boolean;
  1169. /**
  1170. * Returns true if object is a finite Number.
  1171. * @param object Check if this object is a finite Number.
  1172. * @return True if `object` is a finite Number.
  1173. **/
  1174. isFinite(object: any): boolean;
  1175. /**
  1176. * Returns true if object is either true or false.
  1177. * @param object Check if this object is a bool.
  1178. * @return True if `object` is a bool, otherwise false.
  1179. **/
  1180. isBoolean(object: any): boolean;
  1181. /**
  1182. * Returns true if object is a Date.
  1183. * @param object Check if this object is a Date.
  1184. * @return True if `object` is a Date, otherwise false.
  1185. **/
  1186. isDate(object: any): boolean;
  1187. /**
  1188. * Returns true if object is a RegExp.
  1189. * @param object Check if this object is a RegExp.
  1190. * @return True if `object` is a RegExp, otherwise false.
  1191. **/
  1192. isRegExp(object: any): boolean;
  1193. /**
  1194. * Returns true if object is NaN.
  1195. * Note: this is not the same as the native isNaN function,
  1196. * which will also return true if the variable is undefined.
  1197. * @param object Check if this object is NaN.
  1198. * @return True if `object` is NaN, otherwise false.
  1199. **/
  1200. isNaN(object: any): boolean;
  1201. /**
  1202. * Returns true if the value of object is null.
  1203. * @param object Check if this object is null.
  1204. * @return True if `object` is null, otherwise false.
  1205. **/
  1206. isNull(object: any): boolean;
  1207. /**
  1208. * Returns true if value is undefined.
  1209. * @param object Check if this object is undefined.
  1210. * @return True if `object` is undefined, otherwise false.
  1211. **/
  1212. isUndefined(value: any): boolean;
  1213. /* *********
  1214. * Utility *
  1215. ********** */
  1216. /**
  1217. * Give control of the "_" variable back to its previous owner.
  1218. * Returns a reference to the Underscore object.
  1219. * @return Underscore object reference.
  1220. **/
  1221. noConflict(): any;
  1222. /**
  1223. * Returns the same value that is used as the argument. In math: f(x) = x
  1224. * This function looks useless, but is used throughout Underscore as a default iterator.
  1225. * @param value Identity of this object.
  1226. * @return `value`.
  1227. **/
  1228. identity<T>(value: T): T;
  1229. /**
  1230. * Creates a function that returns the same value that is used as the argument of _.constant
  1231. * @param value Identity of this object.
  1232. * @return Function that return value.
  1233. **/
  1234. constant<T>(value: T): () => T;
  1235. /**
  1236. * Invokes the given iterator function n times.
  1237. * Each invocation of iterator is called with an index argument
  1238. * @param n Number of times to invoke `iterator`.
  1239. * @param iterator Function iterator to invoke `n` times.
  1240. * @param context `this` object in `iterator`, optional.
  1241. **/
  1242. times<TResult>(n: number, iterator: (n: number) => TResult, context?: any): TResult[];
  1243. /**
  1244. * Returns a random integer between min and max, inclusive. If you only pass one argument,
  1245. * it will return a number between 0 and that number.
  1246. * @param max The maximum random number.
  1247. * @return A random number between 0 and `max`.
  1248. **/
  1249. random(max: number): number;
  1250. /**
  1251. * @see _.random
  1252. * @param min The minimum random number.
  1253. * @return A random number between `min` and `max`.
  1254. **/
  1255. random(min: number, max: number): number;
  1256. /**
  1257. * Allows you to extend Underscore with your own utility functions. Pass a hash of
  1258. * {name: function} definitions to have your functions added to the Underscore object,
  1259. * as well as the OOP wrapper.
  1260. * @param object Mixin object containing key/function pairs to add to the Underscore object.
  1261. **/
  1262. mixin(object: any): void;
  1263. /**
  1264. * Generate a globally-unique id for client-side models or DOM elements that need one.
  1265. * If prefix is passed, the id will be appended to it. Without prefix, returns an integer.
  1266. * @param prefix A prefix string to start the unique ID with.
  1267. * @return Unique string ID beginning with `prefix`.
  1268. **/
  1269. uniqueId(prefix: string): string;
  1270. /**
  1271. * @see _.uniqueId
  1272. **/
  1273. uniqueId(): number;
  1274. /**
  1275. * Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters.
  1276. * @param str Raw string to escape.
  1277. * @return `str` HTML escaped.
  1278. **/
  1279. escape(str: string): string;
  1280. /**
  1281. * If the value of the named property is a function then invoke it; otherwise, return it.
  1282. * @param object Object to maybe invoke function `property` on.
  1283. * @param property The function by name to invoke on `object`.
  1284. * @return The result of invoking the function `property` on `object.
  1285. **/
  1286. result(object: any, property: string): any;
  1287. /**
  1288. * Compiles JavaScript templates into functions that can be evaluated for rendering. Useful
  1289. * for rendering complicated bits of HTML from JSON data sources. Template functions can both
  1290. * interpolate variables, using <%= ... %>, as well as execute arbitrary JavaScript code, with
  1291. * <% ... %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- ... %> When
  1292. * you evaluate a template function, pass in a data object that has properties corresponding to
  1293. * the template's free variables. If you're writing a one-off, you can pass the data object as
  1294. * the second parameter to template in order to render immediately instead of returning a template
  1295. * function. The settings argument should be a hash containing any _.templateSettings that should
  1296. * be overridden.
  1297. * @param templateString Underscore HTML template.
  1298. * @param data Data to use when compiling `templateString`.
  1299. * @param settings Settings to use while compiling.
  1300. * @return Returns the compiled Underscore HTML template.
  1301. **/
  1302. template(templateString: string, data?: any, settings?: _.TemplateSettings): (...data: any[]) => string;
  1303. /**
  1304. * By default, Underscore uses ERB-style template delimiters, change the
  1305. * following template settings to use alternative delimiters.
  1306. **/
  1307. templateSettings: _.TemplateSettings;
  1308. /**
  1309. * Returns an integer timestamp for the current time, using the fastest method available in the runtime. Useful for implementing timing/animation functions.
  1310. **/
  1311. now(): number;
  1312. /* **********
  1313. * Chaining *
  1314. *********** */
  1315. /**
  1316. * Returns a wrapped object. Calling methods on this object will continue to return wrapped objects
  1317. * until value() is used.
  1318. * @param obj Object to chain.
  1319. * @return Wrapped `obj`.
  1320. **/
  1321. chain<T>(obj: T[]): _Chain<T>;
  1322. chain<T extends {}>(obj: T): _Chain<T>;
  1323. /**
  1324. * Extracts the value of a wrapped object.
  1325. * @param obj Wrapped object to extract the value from.
  1326. * @return Value of `obj`.
  1327. **/
  1328. value<T, TResult>(obj: T): TResult;
  1329. }
  1330. interface Underscore<T> {
  1331. /* *************
  1332. * Collections *
  1333. ************* */
  1334. /**
  1335. * Wrapped type `any[]`.
  1336. * @see _.each
  1337. **/
  1338. each(iterator: _.ListIterator<T, void>, context?: any): T[];
  1339. /**
  1340. * @see _.each
  1341. **/
  1342. each(iterator: _.ObjectIterator<T, void>, context?: any): T[];
  1343. /**
  1344. * @see _.each
  1345. **/
  1346. forEach(iterator: _.ListIterator<T, void>, context?: any): T[];
  1347. /**
  1348. * @see _.each
  1349. **/
  1350. forEach(iterator: _.ObjectIterator<T, void>, context?: any): T[];
  1351. /**
  1352. * Wrapped type `any[]`.
  1353. * @see _.map
  1354. **/
  1355. map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): TResult[];
  1356. /**
  1357. * Wrapped type `any[]`.
  1358. * @see _.map
  1359. **/
  1360. map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): TResult[];
  1361. /**
  1362. * @see _.map
  1363. **/
  1364. collect<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): TResult[];
  1365. /**
  1366. * @see _.map
  1367. **/
  1368. collect<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): TResult[];
  1369. /**
  1370. * Wrapped type `any[]`.
  1371. * @see _.reduce
  1372. **/
  1373. reduce<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1374. /**
  1375. * @see _.reduce
  1376. **/
  1377. inject<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1378. /**
  1379. * @see _.reduce
  1380. **/
  1381. foldl<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1382. /**
  1383. * Wrapped type `any[]`.
  1384. * @see _.reduceRight
  1385. **/
  1386. reduceRight<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1387. /**
  1388. * @see _.reduceRight
  1389. **/
  1390. foldr<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1391. /**
  1392. * Wrapped type `any[]`.
  1393. * @see _.find
  1394. **/
  1395. find(iterator: _.ListIterator<T, boolean>, context?: any): T;
  1396. /**
  1397. * @see _.find
  1398. **/
  1399. detect(iterator: _.ListIterator<T, boolean>, context?: any): T;
  1400. /**
  1401. * Wrapped type `any[]`.
  1402. * @see _.filter
  1403. **/
  1404. filter(iterator: _.ListIterator<T, boolean>, context?: any): T[];
  1405. /**
  1406. * @see _.filter
  1407. **/
  1408. select(iterator: _.ListIterator<T, boolean>, context?: any): T[];
  1409. /**
  1410. * Wrapped type `any[]`.
  1411. * @see _.where
  1412. **/
  1413. where<U extends {}>(properties: U): T[];
  1414. /**
  1415. * Wrapped type `any[]`.
  1416. * @see _.findWhere
  1417. **/
  1418. findWhere<U extends {}>(properties: U): T;
  1419. /**
  1420. * Wrapped type `any[]`.
  1421. * @see _.reject
  1422. **/
  1423. reject(iterator: _.ListIterator<T, boolean>, context?: any): T[];
  1424. /**
  1425. * Wrapped type `any[]`.
  1426. * @see _.all
  1427. **/
  1428. all(iterator?: _.ListIterator<T, boolean>, context?: any): boolean;
  1429. /**
  1430. * @see _.all
  1431. **/
  1432. every(iterator?: _.ListIterator<T, boolean>, context?: any): boolean;
  1433. /**
  1434. * Wrapped type `any[]`.
  1435. * @see _.any
  1436. **/
  1437. any(iterator?: _.ListIterator<T, boolean>, context?: any): boolean;
  1438. /**
  1439. * @see _.any
  1440. **/
  1441. some(iterator?: _.ListIterator<T, boolean>, context?: any): boolean;
  1442. /**
  1443. * Wrapped type `any[]`.
  1444. * @see _.contains
  1445. **/
  1446. contains(value: T): boolean;
  1447. /**
  1448. * Alias for 'contains'.
  1449. * @see contains
  1450. **/
  1451. include(value: T): boolean;
  1452. /**
  1453. * Wrapped type `any[]`.
  1454. * @see _.invoke
  1455. **/
  1456. invoke(methodName: string, ...arguments: any[]): any;
  1457. /**
  1458. * Wrapped type `any[]`.
  1459. * @see _.pluck
  1460. **/
  1461. pluck(propertyName: string): any[];
  1462. /**
  1463. * Wrapped type `number[]`.
  1464. * @see _.max
  1465. **/
  1466. max(): number;
  1467. /**
  1468. * Wrapped type `any[]`.
  1469. * @see _.max
  1470. **/
  1471. max(iterator: _.ListIterator<T, number>, context?: any): T;
  1472. /**
  1473. * Wrapped type `any[]`.
  1474. * @see _.max
  1475. **/
  1476. max(iterator?: _.ListIterator<T, any>, context?: any): T;
  1477. /**
  1478. * Wrapped type `number[]`.
  1479. * @see _.min
  1480. **/
  1481. min(): number;
  1482. /**
  1483. * Wrapped type `any[]`.
  1484. * @see _.min
  1485. **/
  1486. min(iterator: _.ListIterator<T, number>, context?: any): T;
  1487. /**
  1488. * Wrapped type `any[]`.
  1489. * @see _.min
  1490. **/
  1491. min(iterator?: _.ListIterator<T, any>, context?: any): T;
  1492. /**
  1493. * Wrapped type `any[]`.
  1494. * @see _.sortBy
  1495. **/
  1496. sortBy(iterator?: _.ListIterator<T, any>, context?: any): T[];
  1497. /**
  1498. * Wrapped type `any[]`.
  1499. * @see _.sortBy
  1500. **/
  1501. sortBy(iterator: string, context?: any): T[];
  1502. /**
  1503. * Wrapped type `any[]`.
  1504. * @see _.groupBy
  1505. **/
  1506. groupBy(iterator?: _.ListIterator<T, any>, context?: any): _.Dictionary<_.List<T>>;
  1507. /**
  1508. * Wrapped type `any[]`.
  1509. * @see _.groupBy
  1510. **/
  1511. groupBy(iterator: string, context?: any): _.Dictionary<T[]>;
  1512. /**
  1513. * Wrapped type `any[]`.
  1514. * @see _.indexBy
  1515. **/
  1516. indexBy(iterator: _.ListIterator<T, any>, context?: any): _.Dictionary<T>;
  1517. /**
  1518. * Wrapped type `any[]`.
  1519. * @see _.indexBy
  1520. **/
  1521. indexBy(iterator: string, context?: any): _.Dictionary<T>;
  1522. /**
  1523. * Wrapped type `any[]`.
  1524. * @see _.countBy
  1525. **/
  1526. countBy(iterator?: _.ListIterator<T, any>, context?: any): _.Dictionary<number>;
  1527. /**
  1528. * Wrapped type `any[]`.
  1529. * @see _.countBy
  1530. **/
  1531. countBy(iterator: string, context?: any): _.Dictionary<number>;
  1532. /**
  1533. * Wrapped type `any[]`.
  1534. * @see _.shuffle
  1535. **/
  1536. shuffle(): T[];
  1537. /**
  1538. * Wrapped type `any[]`.
  1539. * @see _.sample
  1540. **/
  1541. sample<T>(n: number): T[];
  1542. /**
  1543. * @see _.sample
  1544. **/
  1545. sample<T>(): T;
  1546. /**
  1547. * Wrapped type `any`.
  1548. * @see _.toArray
  1549. **/
  1550. toArray(): T[];
  1551. /**
  1552. * Wrapped type `any`.
  1553. * @see _.size
  1554. **/
  1555. size(): number;
  1556. /*********
  1557. * Arrays *
  1558. **********/
  1559. /**
  1560. * Wrapped type `any[]`.
  1561. * @see _.first
  1562. **/
  1563. first(): T;
  1564. /**
  1565. * Wrapped type `any[]`.
  1566. * @see _.first
  1567. **/
  1568. first(n: number): T[];
  1569. /**
  1570. * @see _.first
  1571. **/
  1572. head(): T;
  1573. /**
  1574. * @see _.first
  1575. **/
  1576. head(n: number): T[];
  1577. /**
  1578. * @see _.first
  1579. **/
  1580. take(): T;
  1581. /**
  1582. * @see _.first
  1583. **/
  1584. take(n: number): T[];
  1585. /**
  1586. * Wrapped type `any[]`.
  1587. * @see _.initial
  1588. **/
  1589. initial(n?: number): T[];
  1590. /**
  1591. * Wrapped type `any[]`.
  1592. * @see _.last
  1593. **/
  1594. last(): T;
  1595. /**
  1596. * Wrapped type `any[]`.
  1597. * @see _.last
  1598. **/
  1599. last(n: number): T[];
  1600. /**
  1601. * Wrapped type `any[]`.
  1602. * @see _.rest
  1603. **/
  1604. rest(n?: number): T[];
  1605. /**
  1606. * @see _.rest
  1607. **/
  1608. tail(n?: number): T[];
  1609. /**
  1610. * @see _.rest
  1611. **/
  1612. drop(n?: number): T[];
  1613. /**
  1614. * Wrapped type `any[]`.
  1615. * @see _.compact
  1616. **/
  1617. compact(): T[];
  1618. /**
  1619. * Wrapped type `any`.
  1620. * @see _.flatten
  1621. **/
  1622. flatten(shallow?: boolean): any[];
  1623. /**
  1624. * Wrapped type `any[]`.
  1625. * @see _.without
  1626. **/
  1627. without(...values: T[]): T[];
  1628. /**
  1629. * Wrapped type `any[]`.
  1630. * @see _.partition
  1631. **/
  1632. partition(iterator: _.ListIterator<T, boolean>, context?: any): T[][];
  1633. /**
  1634. * Wrapped type `any[][]`.
  1635. * @see _.union
  1636. **/
  1637. union(...arrays: _.List<T>[]): T[];
  1638. /**
  1639. * Wrapped type `any[][]`.
  1640. * @see _.intersection
  1641. **/
  1642. intersection(...arrays: _.List<T>[]): T[];
  1643. /**
  1644. * Wrapped type `any[]`.
  1645. * @see _.difference
  1646. **/
  1647. difference(...others: _.List<T>[]): T[];
  1648. /**
  1649. * Wrapped type `any[]`.
  1650. * @see _.uniq
  1651. **/
  1652. uniq(isSorted?: boolean, iterator?: _.ListIterator<T, any>): T[];
  1653. /**
  1654. * Wrapped type `any[]`.
  1655. * @see _.uniq
  1656. **/
  1657. uniq<TSort>(iterator?: _.ListIterator<T, TSort>, context?: any): T[];
  1658. /**
  1659. * @see _.uniq
  1660. **/
  1661. unique<TSort>(isSorted?: boolean, iterator?: _.ListIterator<T, TSort>): T[];
  1662. /**
  1663. * @see _.uniq
  1664. **/
  1665. unique<TSort>(iterator?: _.ListIterator<T, TSort>, context?: any): T[];
  1666. /**
  1667. * Wrapped type `any[][]`.
  1668. * @see _.zip
  1669. **/
  1670. zip(...arrays: any[][]): any[][];
  1671. /**
  1672. * Wrapped type `any[][]`.
  1673. * @see _.object
  1674. **/
  1675. object(...keyValuePairs: any[][]): any;
  1676. /**
  1677. * @see _.object
  1678. **/
  1679. object(values?: any): any;
  1680. /**
  1681. * Wrapped type `any[]`.
  1682. * @see _.indexOf
  1683. **/
  1684. indexOf(value: T, isSorted?: boolean): number;
  1685. /**
  1686. * @see _.indexOf
  1687. **/
  1688. indexOf(value: T, startFrom: number): number;
  1689. /**
  1690. * Wrapped type `any[]`.
  1691. * @see _.lastIndexOf
  1692. **/
  1693. lastIndexOf(value: T, from?: number): number;
  1694. /**
  1695. * Wrapped type `any[]`.
  1696. * @see _.sortedIndex
  1697. **/
  1698. sortedIndex(value: T, iterator?: (x: T) => any, context?: any): number;
  1699. /**
  1700. * Wrapped type `number`.
  1701. * @see _.range
  1702. **/
  1703. range(stop: number, step?: number): number[];
  1704. /**
  1705. * Wrapped type `number`.
  1706. * @see _.range
  1707. **/
  1708. range(): number[];
  1709. /* ***********
  1710. * Functions *
  1711. ************ */
  1712. /**
  1713. * Wrapped type `Function`.
  1714. * @see _.bind
  1715. **/
  1716. bind(object: any, ...arguments: any[]): Function;
  1717. /**
  1718. * Wrapped type `object`.
  1719. * @see _.bindAll
  1720. **/
  1721. bindAll(...methodNames: string[]): any;
  1722. /**
  1723. * Wrapped type `Function`.
  1724. * @see _.partial
  1725. **/
  1726. partial(...arguments: any[]): Function;
  1727. /**
  1728. * Wrapped type `Function`.
  1729. * @see _.memoize
  1730. **/
  1731. memoize(hashFn?: (n: any) => string): Function;
  1732. /**
  1733. * Wrapped type `Function`.
  1734. * @see _.defer
  1735. **/
  1736. defer(...arguments: any[]): void;
  1737. /**
  1738. * Wrapped type `Function`.
  1739. * @see _.delay
  1740. **/
  1741. delay(wait: number, ...arguments: any[]): any;
  1742. /**
  1743. * @see _.delay
  1744. **/
  1745. delay(...arguments: any[]): any;
  1746. /**
  1747. * Wrapped type `Function`.
  1748. * @see _.throttle
  1749. **/
  1750. throttle(wait: number, options?: _.ThrottleSettings): Function;
  1751. /**
  1752. * Wrapped type `Function`.
  1753. * @see _.debounce
  1754. **/
  1755. debounce(wait: number, immediate?: boolean): Function;
  1756. /**
  1757. * Wrapped type `Function`.
  1758. * @see _.once
  1759. **/
  1760. once(): Function;
  1761. /**
  1762. * Wrapped type `number`.
  1763. * @see _.after
  1764. **/
  1765. after(func: Function): Function;
  1766. /**
  1767. * Wrapped type `Function`.
  1768. * @see _.wrap
  1769. **/
  1770. wrap(wrapper: Function): () => Function;
  1771. /**
  1772. * Wrapped type `Function[]`.
  1773. * @see _.compose
  1774. **/
  1775. compose(...functions: Function[]): Function;
  1776. /********* *
  1777. * Objects *
  1778. ********** */
  1779. /**
  1780. * Wrapped type `object`.
  1781. * @see _.keys
  1782. **/
  1783. keys(): string[];
  1784. /**
  1785. * Wrapped type `object`.
  1786. * @see _.values
  1787. **/
  1788. values(): T[];
  1789. /**
  1790. * Wrapped type `object`.
  1791. * @see _.pairs
  1792. **/
  1793. pairs(): any[][];
  1794. /**
  1795. * Wrapped type `object`.
  1796. * @see _.invert
  1797. **/
  1798. invert(): any;
  1799. /**
  1800. * Wrapped type `object`.
  1801. * @see _.functions
  1802. **/
  1803. functions(): string[];
  1804. /**
  1805. * @see _.functions
  1806. **/
  1807. methods(): string[];
  1808. /**
  1809. * Wrapped type `object`.
  1810. * @see _.extend
  1811. **/
  1812. extend(...sources: any[]): any;
  1813. /**
  1814. * Wrapped type `object`.
  1815. * @see _.pick
  1816. **/
  1817. pick(...keys: string[]): any;
  1818. pick(keys: string[]): any;
  1819. /**
  1820. * Wrapped type `object`.
  1821. * @see _.omit
  1822. **/
  1823. omit(...keys: string[]): any;
  1824. omit(keys: string[]): any;
  1825. /**
  1826. * Wrapped type `object`.
  1827. * @see _.defaults
  1828. **/
  1829. defaults(...defaults: any[]): any;
  1830. /**
  1831. * Wrapped type `any[]`.
  1832. * @see _.clone
  1833. **/
  1834. clone(): T;
  1835. /**
  1836. * Wrapped type `object`.
  1837. * @see _.tap
  1838. **/
  1839. tap(interceptor: (...as: any[]) => any): any;
  1840. /**
  1841. * Wrapped type `object`.
  1842. * @see _.has
  1843. **/
  1844. has(key: string): boolean;
  1845. /**
  1846. * Wrapped type `any[]`.
  1847. * @see _.matches
  1848. **/
  1849. matches<TResult>(): _.ListIterator<T, TResult>;
  1850. /**
  1851. * Wrapped type `string`.
  1852. * @see _.property
  1853. **/
  1854. property(): (object: Object) => any;
  1855. /**
  1856. * Wrapped type `object`.
  1857. * @see _.isEqual
  1858. **/
  1859. isEqual(other: any): boolean;
  1860. /**
  1861. * Wrapped type `object`.
  1862. * @see _.isEmpty
  1863. **/
  1864. isEmpty(): boolean;
  1865. /**
  1866. * Wrapped type `object`.
  1867. * @see _.isElement
  1868. **/
  1869. isElement(): boolean;
  1870. /**
  1871. * Wrapped type `object`.
  1872. * @see _.isArray
  1873. **/
  1874. isArray(): boolean;
  1875. /**
  1876. * Wrapped type `object`.
  1877. * @see _.isObject
  1878. **/
  1879. isObject(): boolean;
  1880. /**
  1881. * Wrapped type `object`.
  1882. * @see _.isArguments
  1883. **/
  1884. isArguments(): boolean;
  1885. /**
  1886. * Wrapped type `object`.
  1887. * @see _.isFunction
  1888. **/
  1889. isFunction(): boolean;
  1890. /**
  1891. * Wrapped type `object`.
  1892. * @see _.isString
  1893. **/
  1894. isString(): boolean;
  1895. /**
  1896. * Wrapped type `object`.
  1897. * @see _.isNumber
  1898. **/
  1899. isNumber(): boolean;
  1900. /**
  1901. * Wrapped type `object`.
  1902. * @see _.isFinite
  1903. **/
  1904. isFinite(): boolean;
  1905. /**
  1906. * Wrapped type `object`.
  1907. * @see _.isBoolean
  1908. **/
  1909. isBoolean(): boolean;
  1910. /**
  1911. * Wrapped type `object`.
  1912. * @see _.isDate
  1913. **/
  1914. isDate(): boolean;
  1915. /**
  1916. * Wrapped type `object`.
  1917. * @see _.isRegExp
  1918. **/
  1919. isRegExp(): boolean;
  1920. /**
  1921. * Wrapped type `object`.
  1922. * @see _.isNaN
  1923. **/
  1924. isNaN(): boolean;
  1925. /**
  1926. * Wrapped type `object`.
  1927. * @see _.isNull
  1928. **/
  1929. isNull(): boolean;
  1930. /**
  1931. * Wrapped type `object`.
  1932. * @see _.isUndefined
  1933. **/
  1934. isUndefined(): boolean;
  1935. /********* *
  1936. * Utility *
  1937. ********** */
  1938. /**
  1939. * Wrapped type `any`.
  1940. * @see _.identity
  1941. **/
  1942. identity(): any;
  1943. /**
  1944. * Wrapped type `any`.
  1945. * @see _.constant
  1946. **/
  1947. constant(): () => T;
  1948. /**
  1949. * Wrapped type `number`.
  1950. * @see _.times
  1951. **/
  1952. times<TResult>(iterator: (n: number) => TResult, context?: any): TResult[];
  1953. /**
  1954. * Wrapped type `number`.
  1955. * @see _.random
  1956. **/
  1957. random(): number;
  1958. /**
  1959. * Wrapped type `number`.
  1960. * @see _.random
  1961. **/
  1962. random(max: number): number;
  1963. /**
  1964. * Wrapped type `object`.
  1965. * @see _.mixin
  1966. **/
  1967. mixin(): void;
  1968. /**
  1969. * Wrapped type `string`.
  1970. * @see _.uniqueId
  1971. **/
  1972. uniqueId(): string;
  1973. /**
  1974. * Wrapped type `string`.
  1975. * @see _.escape
  1976. **/
  1977. escape(): string;
  1978. /**
  1979. * Wrapped type `object`.
  1980. * @see _.result
  1981. **/
  1982. result(property: string): any;
  1983. /**
  1984. * Wrapped type `string`.
  1985. * @see _.template
  1986. **/
  1987. template(data?: any, settings?: _.TemplateSettings): (...data: any[]) => string;
  1988. /********** *
  1989. * Chaining *
  1990. *********** */
  1991. /**
  1992. * Wrapped type `any`.
  1993. * @see _.chain
  1994. **/
  1995. chain(): _Chain<T>;
  1996. /**
  1997. * Wrapped type `any`.
  1998. * @see _.value
  1999. **/
  2000. value<TResult>(): TResult;
  2001. }
  2002. interface _Chain<T> {
  2003. /* *************
  2004. * Collections *
  2005. ************* */
  2006. /**
  2007. * Wrapped type `any[]`.
  2008. * @see _.each
  2009. **/
  2010. each(iterator: _.ListIterator<T, void>, context?: any): _Chain<T>;
  2011. /**
  2012. * @see _.each
  2013. **/
  2014. each(iterator: _.ObjectIterator<T, void>, context?: any): _Chain<T>;
  2015. /**
  2016. * @see _.each
  2017. **/
  2018. forEach(iterator: _.ListIterator<T, void>, context?: any): _Chain<T>;
  2019. /**
  2020. * @see _.each
  2021. **/
  2022. forEach(iterator: _.ObjectIterator<T, void>, context?: any): _Chain<T>;
  2023. /**
  2024. * Wrapped type `any[]`.
  2025. * @see _.map
  2026. **/
  2027. map<TArray>(iterator: _.ListIterator<T, TArray[]>, context?: any): _ChainOfArrays<TArray>;
  2028. /**
  2029. * Wrapped type `any[]`.
  2030. * @see _.map
  2031. **/
  2032. map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): _Chain<TResult>;
  2033. /**
  2034. * Wrapped type `any[]`.
  2035. * @see _.map
  2036. **/
  2037. map<TArray>(iterator: _.ObjectIterator<T, TArray[]>, context?: any): _ChainOfArrays<TArray>;
  2038. /**
  2039. * Wrapped type `any[]`.
  2040. * @see _.map
  2041. **/
  2042. map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): _Chain<TResult>;
  2043. /**
  2044. * @see _.map
  2045. **/
  2046. collect<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): _Chain<T>;
  2047. /**
  2048. * @see _.map
  2049. **/
  2050. collect<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): _Chain<T>;
  2051. /**
  2052. * Wrapped type `any[]`.
  2053. * @see _.reduce
  2054. **/
  2055. reduce<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): _Chain<T>;
  2056. /**
  2057. * @see _.reduce
  2058. **/
  2059. inject<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): _Chain<T>;
  2060. /**
  2061. * @see _.reduce
  2062. **/
  2063. foldl<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): _Chain<T>;
  2064. /**
  2065. * Wrapped type `any[]`.
  2066. * @see _.reduceRight
  2067. **/
  2068. reduceRight<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): _Chain<T>;
  2069. /**
  2070. * @see _.reduceRight
  2071. **/
  2072. foldr<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): _Chain<T>;
  2073. /**
  2074. * Wrapped type `any[]`.
  2075. * @see _.find
  2076. **/
  2077. find(iterator: _.ListIterator<T, boolean>, context?: any): _ChainSingle<T>;
  2078. /**
  2079. * @see _.find
  2080. **/
  2081. detect(iterator: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2082. /**
  2083. * Wrapped type `any[]`.
  2084. * @see _.filter
  2085. **/
  2086. filter(iterator: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2087. /**
  2088. * @see _.filter
  2089. **/
  2090. select(iterator: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2091. /**
  2092. * Wrapped type `any[]`.
  2093. * @see _.where
  2094. **/
  2095. where<U extends {}>(properties: U): _Chain<T>;
  2096. /**
  2097. * Wrapped type `any[]`.
  2098. * @see _.findWhere
  2099. **/
  2100. findWhere<U extends {}>(properties: U): _ChainSingle<T>;
  2101. /**
  2102. * Wrapped type `any[]`.
  2103. * @see _.reject
  2104. **/
  2105. reject(iterator: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2106. /**
  2107. * Wrapped type `any[]`.
  2108. * @see _.all
  2109. **/
  2110. all(iterator?: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2111. /**
  2112. * @see _.all
  2113. **/
  2114. every(iterator?: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2115. /**
  2116. * Wrapped type `any[]`.
  2117. * @see _.any
  2118. **/
  2119. any(iterator?: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2120. /**
  2121. * @see _.any
  2122. **/
  2123. some(iterator?: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
  2124. /**
  2125. * Wrapped type `any[]`.
  2126. * @see _.contains
  2127. **/
  2128. contains(value: T): _Chain<T>;
  2129. /**
  2130. * Alias for 'contains'.
  2131. * @see contains
  2132. **/
  2133. include(value: T): _Chain<T>;
  2134. /**
  2135. * Wrapped type `any[]`.
  2136. * @see _.invoke
  2137. **/
  2138. invoke(methodName: string, ...arguments: any[]): _Chain<T>;
  2139. /**
  2140. * Wrapped type `any[]`.
  2141. * @see _.pluck
  2142. **/
  2143. pluck(propertyName: string): _Chain<any>;
  2144. /**
  2145. * Wrapped type `number[]`.
  2146. * @see _.max
  2147. **/
  2148. max(): _ChainSingle<T>;
  2149. /**
  2150. * Wrapped type `any[]`.
  2151. * @see _.max
  2152. **/
  2153. max(iterator: _.ListIterator<T, number>, context?: any): _ChainSingle<T>;
  2154. /**
  2155. * Wrapped type `any[]`.
  2156. * @see _.max
  2157. **/
  2158. max(iterator?: _.ListIterator<T, any>, context?: any): _ChainSingle<T>;
  2159. /**
  2160. * Wrapped type `number[]`.
  2161. * @see _.min
  2162. **/
  2163. min(): _ChainSingle<T>;
  2164. /**
  2165. * Wrapped type `any[]`.
  2166. * @see _.min
  2167. **/
  2168. min(iterator: _.ListIterator<T, number>, context?: any): _ChainSingle<T>;
  2169. /**
  2170. * Wrapped type `any[]`.
  2171. * @see _.min
  2172. **/
  2173. min(iterator?: _.ListIterator<T, any>, context?: any): _ChainSingle<T>;
  2174. /**
  2175. * Wrapped type `any[]`.
  2176. * @see _.sortBy
  2177. **/
  2178. sortBy(iterator?: _.ListIterator<T, any>, context?: any): _Chain<T>;
  2179. /**
  2180. * Wrapped type `any[]`.
  2181. * @see _.sortBy
  2182. **/
  2183. sortBy(iterator: string, context?: any): _Chain<T>;
  2184. /**
  2185. * Wrapped type `any[]`.
  2186. * @see _.groupBy
  2187. **/
  2188. groupBy(iterator?: _.ListIterator<T, any>, context?: any): _Chain<T>;
  2189. /**
  2190. * Wrapped type `any[]`.
  2191. * @see _.groupBy
  2192. **/
  2193. groupBy(iterator: string, context?: any): _Chain<T>;
  2194. /**
  2195. * Wrapped type `any[]`.
  2196. * @see _.indexBy
  2197. **/
  2198. indexBy(iterator: _.ListIterator<T, any>, context?: any): _Chain<T>;
  2199. /**
  2200. * Wrapped type `any[]`.
  2201. * @see _.indexBy
  2202. **/
  2203. indexBy(iterator: string, context?: any): _Chain<T>;
  2204. /**
  2205. * Wrapped type `any[]`.
  2206. * @see _.countBy
  2207. **/
  2208. countBy(iterator?: _.ListIterator<T, any>, context?: any): _Chain<T>;
  2209. /**
  2210. * Wrapped type `any[]`.
  2211. * @see _.countBy
  2212. **/
  2213. countBy(iterator: string, context?: any): _Chain<T>;
  2214. /**
  2215. * Wrapped type `any[]`.
  2216. * @see _.shuffle
  2217. **/
  2218. shuffle(): _Chain<T>;
  2219. /**
  2220. * Wrapped type `any[]`.
  2221. * @see _.sample
  2222. **/
  2223. sample<T>(n: number): _Chain<T>;
  2224. /**
  2225. * @see _.sample
  2226. **/
  2227. sample<T>(): _Chain<T>;
  2228. /**
  2229. * Wrapped type `any`.
  2230. * @see _.toArray
  2231. **/
  2232. toArray(): _Chain<T>;
  2233. /**
  2234. * Wrapped type `any`.
  2235. * @see _.size
  2236. **/
  2237. size(): _Chain<T>;
  2238. /*********
  2239. * Arrays *
  2240. **********/
  2241. /**
  2242. * Wrapped type `any[]`.
  2243. * @see _.first
  2244. **/
  2245. first(): _Chain<T>;
  2246. /**
  2247. * Wrapped type `any[]`.
  2248. * @see _.first
  2249. **/
  2250. first(n: number): _Chain<T>;
  2251. /**
  2252. * @see _.first
  2253. **/
  2254. head(): _Chain<T>;
  2255. /**
  2256. * @see _.first
  2257. **/
  2258. head(n: number): _Chain<T>;
  2259. /**
  2260. * @see _.first
  2261. **/
  2262. take(): _Chain<T>;
  2263. /**
  2264. * @see _.first
  2265. **/
  2266. take(n: number): _Chain<T>;
  2267. /**
  2268. * Wrapped type `any[]`.
  2269. * @see _.initial
  2270. **/
  2271. initial(n?: number): _Chain<T>;
  2272. /**
  2273. * Wrapped type `any[]`.
  2274. * @see _.last
  2275. **/
  2276. last(): _Chain<T>;
  2277. /**
  2278. * Wrapped type `any[]`.
  2279. * @see _.last
  2280. **/
  2281. last(n: number): _Chain<T>;
  2282. /**
  2283. * Wrapped type `any[]`.
  2284. * @see _.rest
  2285. **/
  2286. rest(n?: number): _Chain<T>;
  2287. /**
  2288. * @see _.rest
  2289. **/
  2290. tail(n?: number): _Chain<T>;
  2291. /**
  2292. * @see _.rest
  2293. **/
  2294. drop(n?: number): _Chain<T>;
  2295. /**
  2296. * Wrapped type `any[]`.
  2297. * @see _.compact
  2298. **/
  2299. compact(): _Chain<T>;
  2300. /**
  2301. * Wrapped type `any`.
  2302. * @see _.flatten
  2303. **/
  2304. flatten(shallow?: boolean): _Chain<any>;
  2305. /**
  2306. * Wrapped type `any[]`.
  2307. * @see _.without
  2308. **/
  2309. without(...values: T[]): _Chain<T>;
  2310. /**
  2311. * Wrapped type `any[]`.
  2312. * @see _.partition
  2313. **/
  2314. partition(iterator: _.ListIterator<T, boolean>, context?: any): _Chain<T[][]>;
  2315. /**
  2316. * Wrapped type `any[][]`.
  2317. * @see _.union
  2318. **/
  2319. union(...arrays: _.List<T>[]): _Chain<T>;
  2320. /**
  2321. * Wrapped type `any[][]`.
  2322. * @see _.intersection
  2323. **/
  2324. intersection(...arrays: _.List<T>[]): _Chain<T>;
  2325. /**
  2326. * Wrapped type `any[]`.
  2327. * @see _.difference
  2328. **/
  2329. difference(...others: _.List<T>[]): _Chain<T>;
  2330. /**
  2331. * Wrapped type `any[]`.
  2332. * @see _.uniq
  2333. **/
  2334. uniq(isSorted?: boolean, iterator?: _.ListIterator<T, any>): _Chain<T>;
  2335. /**
  2336. * Wrapped type `any[]`.
  2337. * @see _.uniq
  2338. **/
  2339. uniq<TSort>(iterator?: _.ListIterator<T, TSort>, context?: any): _Chain<T>;
  2340. /**
  2341. * @see _.uniq
  2342. **/
  2343. unique<TSort>(isSorted?: boolean, iterator?: _.ListIterator<T, TSort>): _Chain<T>;
  2344. /**
  2345. * @see _.uniq
  2346. **/
  2347. unique<TSort>(iterator?: _.ListIterator<T, TSort>, context?: any): _Chain<T>;
  2348. /**
  2349. * Wrapped type `any[][]`.
  2350. * @see _.zip
  2351. **/
  2352. zip(...arrays: any[][]): _Chain<T>;
  2353. /**
  2354. * Wrapped type `any[][]`.
  2355. * @see _.object
  2356. **/
  2357. object(...keyValuePairs: any[][]): _Chain<T>;
  2358. /**
  2359. * @see _.object
  2360. **/
  2361. object(values?: any): _Chain<T>;
  2362. /**
  2363. * Wrapped type `any[]`.
  2364. * @see _.indexOf
  2365. **/
  2366. indexOf(value: T, isSorted?: boolean): _Chain<T>;
  2367. /**
  2368. * @see _.indexOf
  2369. **/
  2370. indexOf(value: T, startFrom: number): _Chain<T>;
  2371. /**
  2372. * Wrapped type `any[]`.
  2373. * @see _.lastIndexOf
  2374. **/
  2375. lastIndexOf(value: T, from?: number): _Chain<T>;
  2376. /**
  2377. * Wrapped type `any[]`.
  2378. * @see _.sortedIndex
  2379. **/
  2380. sortedIndex(value: T, iterator?: (x: T) => any, context?: any): _Chain<T>;
  2381. /**
  2382. * Wrapped type `number`.
  2383. * @see _.range
  2384. **/
  2385. range(stop: number, step?: number): _Chain<T>;
  2386. /**
  2387. * Wrapped type `number`.
  2388. * @see _.range
  2389. **/
  2390. range(): _Chain<T>;
  2391. /* ***********
  2392. * Functions *
  2393. ************ */
  2394. /**
  2395. * Wrapped type `Function`.
  2396. * @see _.bind
  2397. **/
  2398. bind(object: any, ...arguments: any[]): _Chain<T>;
  2399. /**
  2400. * Wrapped type `object`.
  2401. * @see _.bindAll
  2402. **/
  2403. bindAll(...methodNames: string[]): _Chain<T>;
  2404. /**
  2405. * Wrapped type `Function`.
  2406. * @see _.partial
  2407. **/
  2408. partial(...arguments: any[]): _Chain<T>;
  2409. /**
  2410. * Wrapped type `Function`.
  2411. * @see _.memoize
  2412. **/
  2413. memoize(hashFn?: (n: any) => string): _Chain<T>;
  2414. /**
  2415. * Wrapped type `Function`.
  2416. * @see _.defer
  2417. **/
  2418. defer(...arguments: any[]): _Chain<T>;
  2419. /**
  2420. * Wrapped type `Function`.
  2421. * @see _.delay
  2422. **/
  2423. delay(wait: number, ...arguments: any[]): _Chain<T>;
  2424. /**
  2425. * @see _.delay
  2426. **/
  2427. delay(...arguments: any[]): _Chain<T>;
  2428. /**
  2429. * Wrapped type `Function`.
  2430. * @see _.throttle
  2431. **/
  2432. throttle(wait: number, options?: _.ThrottleSettings): _Chain<T>;
  2433. /**
  2434. * Wrapped type `Function`.
  2435. * @see _.debounce
  2436. **/
  2437. debounce(wait: number, immediate?: boolean): _Chain<T>;
  2438. /**
  2439. * Wrapped type `Function`.
  2440. * @see _.once
  2441. **/
  2442. once(): _Chain<T>;
  2443. /**
  2444. * Wrapped type `number`.
  2445. * @see _.after
  2446. **/
  2447. after(func: Function): _Chain<T>;
  2448. /**
  2449. * Wrapped type `Function`.
  2450. * @see _.wrap
  2451. **/
  2452. wrap(wrapper: Function): () => _Chain<T>;
  2453. /**
  2454. * Wrapped type `Function[]`.
  2455. * @see _.compose
  2456. **/
  2457. compose(...functions: Function[]): _Chain<T>;
  2458. /********* *
  2459. * Objects *
  2460. ********** */
  2461. /**
  2462. * Wrapped type `object`.
  2463. * @see _.keys
  2464. **/
  2465. keys(): _Chain<string>;
  2466. /**
  2467. * Wrapped type `object`.
  2468. * @see _.values
  2469. **/
  2470. values(): _Chain<T>;
  2471. /**
  2472. * Wrapped type `object`.
  2473. * @see _.pairs
  2474. **/
  2475. pairs(): _Chain<T>;
  2476. /**
  2477. * Wrapped type `object`.
  2478. * @see _.invert
  2479. **/
  2480. invert(): _Chain<T>;
  2481. /**
  2482. * Wrapped type `object`.
  2483. * @see _.functions
  2484. **/
  2485. functions(): _Chain<T>;
  2486. /**
  2487. * @see _.functions
  2488. **/
  2489. methods(): _Chain<T>;
  2490. /**
  2491. * Wrapped type `object`.
  2492. * @see _.extend
  2493. **/
  2494. extend(...sources: any[]): _Chain<T>;
  2495. /**
  2496. * Wrapped type `object`.
  2497. * @see _.pick
  2498. **/
  2499. pick(...keys: string[]): _Chain<T>;
  2500. /**
  2501. * Wrapped type `object`.
  2502. * @see _.omit
  2503. **/
  2504. omit(...keys: string[]): _Chain<T>;
  2505. /**
  2506. * Wrapped type `object`.
  2507. * @see _.defaults
  2508. **/
  2509. defaults(...defaults: any[]): _Chain<T>;
  2510. /**
  2511. * Wrapped type `any[]`.
  2512. * @see _.clone
  2513. **/
  2514. clone(): _Chain<T>;
  2515. /**
  2516. * Wrapped type `object`.
  2517. * @see _.tap
  2518. **/
  2519. tap(interceptor: (...as: any[]) => any): _Chain<T>;
  2520. /**
  2521. * Wrapped type `object`.
  2522. * @see _.has
  2523. **/
  2524. has(key: string): _Chain<T>;
  2525. /**
  2526. * Wrapped type `any[]`.
  2527. * @see _.matches
  2528. **/
  2529. matches<TResult>(): _Chain<T>;
  2530. /**
  2531. * Wrapped type `string`.
  2532. * @see _.property
  2533. **/
  2534. property(): _Chain<T>;
  2535. /**
  2536. * Wrapped type `object`.
  2537. * @see _.isEqual
  2538. **/
  2539. isEqual(other: any): _Chain<T>;
  2540. /**
  2541. * Wrapped type `object`.
  2542. * @see _.isEmpty
  2543. **/
  2544. isEmpty(): _Chain<T>;
  2545. /**
  2546. * Wrapped type `object`.
  2547. * @see _.isElement
  2548. **/
  2549. isElement(): _Chain<T>;
  2550. /**
  2551. * Wrapped type `object`.
  2552. * @see _.isArray
  2553. **/
  2554. isArray(): _Chain<T>;
  2555. /**
  2556. * Wrapped type `object`.
  2557. * @see _.isObject
  2558. **/
  2559. isObject(): _Chain<T>;
  2560. /**
  2561. * Wrapped type `object`.
  2562. * @see _.isArguments
  2563. **/
  2564. isArguments(): _Chain<T>;
  2565. /**
  2566. * Wrapped type `object`.
  2567. * @see _.isFunction
  2568. **/
  2569. isFunction(): _Chain<T>;
  2570. /**
  2571. * Wrapped type `object`.
  2572. * @see _.isString
  2573. **/
  2574. isString(): _Chain<T>;
  2575. /**
  2576. * Wrapped type `object`.
  2577. * @see _.isNumber
  2578. **/
  2579. isNumber(): _Chain<T>;
  2580. /**
  2581. * Wrapped type `object`.
  2582. * @see _.isFinite
  2583. **/
  2584. isFinite(): _Chain<T>;
  2585. /**
  2586. * Wrapped type `object`.
  2587. * @see _.isBoolean
  2588. **/
  2589. isBoolean(): _Chain<T>;
  2590. /**
  2591. * Wrapped type `object`.
  2592. * @see _.isDate
  2593. **/
  2594. isDate(): _Chain<T>;
  2595. /**
  2596. * Wrapped type `object`.
  2597. * @see _.isRegExp
  2598. **/
  2599. isRegExp(): _Chain<T>;
  2600. /**
  2601. * Wrapped type `object`.
  2602. * @see _.isNaN
  2603. **/
  2604. isNaN(): _Chain<T>;
  2605. /**
  2606. * Wrapped type `object`.
  2607. * @see _.isNull
  2608. **/
  2609. isNull(): _Chain<T>;
  2610. /**
  2611. * Wrapped type `object`.
  2612. * @see _.isUndefined
  2613. **/
  2614. isUndefined(): _Chain<T>;
  2615. /********* *
  2616. * Utility *
  2617. ********** */
  2618. /**
  2619. * Wrapped type `any`.
  2620. * @see _.identity
  2621. **/
  2622. identity(): _Chain<T>;
  2623. /**
  2624. * Wrapped type `any`.
  2625. * @see _.constant
  2626. **/
  2627. constant(): _Chain<T>;
  2628. /**
  2629. * Wrapped type `number`.
  2630. * @see _.times
  2631. **/
  2632. times<TResult>(iterator: (n: number) => TResult, context?: any): _Chain<T>;
  2633. /**
  2634. * Wrapped type `number`.
  2635. * @see _.random
  2636. **/
  2637. random(): _Chain<T>;
  2638. /**
  2639. * Wrapped type `number`.
  2640. * @see _.random
  2641. **/
  2642. random(max: number): _Chain<T>;
  2643. /**
  2644. * Wrapped type `object`.
  2645. * @see _.mixin
  2646. **/
  2647. mixin(): _Chain<T>;
  2648. /**
  2649. * Wrapped type `string`.
  2650. * @see _.uniqueId
  2651. **/
  2652. uniqueId(): _Chain<T>;
  2653. /**
  2654. * Wrapped type `string`.
  2655. * @see _.escape
  2656. **/
  2657. escape(): _Chain<T>;
  2658. /**
  2659. * Wrapped type `object`.
  2660. * @see _.result
  2661. **/
  2662. result(property: string): _Chain<T>;
  2663. /**
  2664. * Wrapped type `string`.
  2665. * @see _.template
  2666. **/
  2667. template(data?: any, settings?: _.TemplateSettings): (...data: any[]) => _Chain<T>;
  2668. /********** *
  2669. * Chaining *
  2670. *********** */
  2671. /**
  2672. * Wrapped type `any`.
  2673. * @see _.chain
  2674. **/
  2675. chain(): _Chain<T>;
  2676. /**
  2677. * Wrapped type `any`.
  2678. * @see _.value
  2679. **/
  2680. value<TResult>(): T[];
  2681. }
  2682. interface _ChainSingle<T> {
  2683. value(): T;
  2684. }
  2685. interface _ChainOfArrays<T> extends _Chain<T[]> {
  2686. flatten(): _Chain<T>;
  2687. }
  2688. declare var _: UnderscoreStatic;
  2689. declare module "underscore" {
  2690. export = _;
  2691. }