PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/underscore/underscore.d.ts

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