PageRenderTime 57ms CodeModel.GetById 14ms 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

Large files files are truncated, but you can click here to view the full file

  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, bo

Large files files are truncated, but you can click here to view the full file