PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/underscore/underscore.d.ts

https://github.com/F0rt1s/DefinitelyTyped
TypeScript Typings | 3149 lines | 711 code | 458 blank | 1980 comment | 3 complexity | e2a644cd429751103f9c00f1fa70a2e0 MD5 | raw file
Possible License(s): MIT

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/>
  4. // Definitions by: Josh Baldwin <https://github.com/jbaldwin/>
  5. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  6. declare module _ {
  7. /**
  8. * underscore.js _.throttle options.
  9. **/
  10. interface ThrottleSettings {
  11. /**
  12. * If you'd like to disable the leading-edge call, pass this as false.
  13. **/
  14. leading?: boolean;
  15. /**
  16. * If you'd like to disable the execution on the trailing-edge, pass false.
  17. **/
  18. trailing?: boolean;
  19. }
  20. /**
  21. * underscore.js template settings, set templateSettings or pass as an argument
  22. * to 'template()' to override defaults.
  23. **/
  24. interface TemplateSettings {
  25. /**
  26. * Default value is '/<%([\s\S]+?)%>/g'.
  27. **/
  28. evaluate?: RegExp;
  29. /**
  30. * Default value is '/<%=([\s\S]+?)%>/g'.
  31. **/
  32. interpolate?: RegExp;
  33. /**
  34. * Default value is '/<%-([\s\S]+?)%>/g'.
  35. **/
  36. escape?: RegExp;
  37. }
  38. interface ListIterator<T, TResult> {
  39. (value: T, index: number, list: T[]): TResult;
  40. }
  41. interface ObjectIterator<T, TResult> {
  42. (element: T, key: string, list: any): TResult;
  43. }
  44. interface MemoIterator<T, TResult> {
  45. (prev: TResult, curr: T, index: number, list: T[]): TResult;
  46. }
  47. interface Collection<T> { }
  48. // Common interface between Arrays and jQuery objects
  49. interface List<T> extends Collection<T> {
  50. [index: number]: T;
  51. length: number;
  52. }
  53. interface Dictionary<T> extends Collection<T> {
  54. [index: string]: T;
  55. }
  56. }
  57. interface UnderscoreStatic {
  58. /**
  59. * Underscore OOP Wrapper, all Underscore functions that take an object
  60. * as the first parameter can be invoked through this function.
  61. * @param key First argument to Underscore object functions.
  62. **/
  63. <T>(value: Array<T>): Underscore<T>;
  64. <T>(value: T): Underscore<T>;
  65. /* *************
  66. * Collections *
  67. ************* */
  68. /**
  69. * Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is
  70. * bound to the context object, if one is passed. Each invocation of iterator is called with three
  71. * arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be
  72. * (value, key, object). Delegates to the native forEach function if it exists.
  73. * @param list Iterates over this list of elements.
  74. * @param iterator Iterator function for each element `list`.
  75. * @param context 'this' object in `iterator`, optional.
  76. **/
  77. each<T>(
  78. list: _.List<T>,
  79. iterator: _.ListIterator<T, void>,
  80. context?: any): _.List<T>;
  81. /**
  82. * @see _.each
  83. * @param object Iterates over properties of this object.
  84. * @param iterator Iterator function for each property on `object`.
  85. * @param context 'this' object in `iterator`, optional.
  86. **/
  87. each<T>(
  88. object: _.Dictionary<T>,
  89. iterator: _.ObjectIterator<T, void>,
  90. context?: any): _.Dictionary<T>;
  91. /**
  92. * @see _.each
  93. **/
  94. forEach<T>(
  95. list: _.List<T>,
  96. iterator: _.ListIterator<T, void>,
  97. context?: any): _.List<T>;
  98. /**
  99. * @see _.each
  100. **/
  101. forEach<T>(
  102. object: _.Dictionary<T>,
  103. iterator: _.ObjectIterator<T, void>,
  104. context?: any): _.Dictionary<T>;
  105. /**
  106. * Produces a new array of values by mapping each value in list through a transformation function
  107. * (iterator). If the native map method exists, it will be used instead. If list is a JavaScript
  108. * object, iterator's arguments will be (value, key, object).
  109. * @param list Maps the elements of this array.
  110. * @param iterator Map iterator function for each element in `list`.
  111. * @param context `this` object in `iterator`, optional.
  112. * @return The mapped array result.
  113. **/
  114. map<T, TResult>(
  115. list: _.List<T>,
  116. iterator: _.ListIterator<T, TResult>,
  117. context?: any): TResult[];
  118. /**
  119. * @see _.map
  120. * @param object Maps the properties of this object.
  121. * @param iterator Map iterator function for each property on `object`.
  122. * @param context `this` object in `iterator`, optional.
  123. * @return The mapped object result.
  124. **/
  125. map<T, TResult>(
  126. object: _.Dictionary<T>,
  127. iterator: _.ObjectIterator<T, TResult>,
  128. context?: any): TResult[];
  129. /**
  130. * @see _.map
  131. **/
  132. collect<T, TResult>(
  133. list: _.List<T>,
  134. iterator: _.ListIterator<T, TResult>,
  135. context?: any): TResult[];
  136. /**
  137. * @see _.map
  138. **/
  139. collect<T, TResult>(
  140. object: _.Dictionary<T>,
  141. iterator: _.ObjectIterator<T, TResult>,
  142. context?: any): TResult[];
  143. /**
  144. * Also known as inject and foldl, reduce boils down a list of values into a single value.
  145. * Memo is the initial state of the reduction, and each successive step of it should be
  146. * returned by iterator. The iterator is passed four arguments: the memo, then the value
  147. * and index (or key) of the iteration, and finally a reference to the entire list.
  148. * @param list Reduces the elements of this array.
  149. * @param iterator Reduce iterator function for each element in `list`.
  150. * @param memo Initial reduce state.
  151. * @param context `this` object in `iterator`, optional.
  152. * @return Reduced object result.
  153. **/
  154. reduce<T, TResult>(
  155. list: _.Collection<T>,
  156. iterator: _.MemoIterator<T, TResult>,
  157. memo?: TResult,
  158. context?: any): TResult;
  159. /**
  160. * @see _.reduce
  161. **/
  162. inject<T, TResult>(
  163. list: _.Collection<T>,
  164. iterator: _.MemoIterator<T, TResult>,
  165. memo?: TResult,
  166. context?: any): TResult;
  167. /**
  168. * @see _.reduce
  169. **/
  170. foldl<T, TResult>(
  171. list: _.Collection<T>,
  172. iterator: _.MemoIterator<T, TResult>,
  173. memo?: TResult,
  174. context?: any): TResult;
  175. /**
  176. * The right-associative version of reduce. Delegates to the JavaScript 1.8 version of
  177. * reduceRight, if it exists. `foldr` is not as useful in JavaScript as it would be in a
  178. * language with lazy evaluation.
  179. * @param list Reduces the elements of this array.
  180. * @param iterator Reduce iterator function for each element in `list`.
  181. * @param memo Initial reduce state.
  182. * @param context `this` object in `iterator`, optional.
  183. * @return Reduced object result.
  184. **/
  185. reduceRight<T, TResult>(
  186. list: _.Collection<T>,
  187. iterator: _.MemoIterator<T, TResult>,
  188. memo?: TResult,
  189. context?: any): TResult;
  190. /**
  191. * @see _.reduceRight
  192. **/
  193. foldr<T, TResult>(
  194. list: _.Collection<T>,
  195. iterator: _.MemoIterator<T, TResult>,
  196. memo?: TResult,
  197. context?: any): TResult;
  198. /**
  199. * Looks through each value in the list, returning the first one that passes a truth
  200. * test (iterator). The function returns as soon as it finds an acceptable element,
  201. * and doesn't traverse the entire list.
  202. * @param list Searches for a value in this list.
  203. * @param iterator Search iterator function for each element in `list`.
  204. * @param context `this` object in `iterator`, optional.
  205. * @return The first acceptable found element in `list`, if nothing is found undefined/null is returned.
  206. **/
  207. find<T>(
  208. list: _.List<T>,
  209. iterator: _.ListIterator<T, boolean>,
  210. context?: any): T;
  211. /**
  212. * @see _.find
  213. **/
  214. find<T>(
  215. object: _.Dictionary<T>,
  216. iterator: _.ObjectIterator<T, boolean>,
  217. context?: any): T;
  218. /**
  219. * @see _.find
  220. **/
  221. detect<T>(
  222. list: _.List<T>,
  223. iterator: _.ListIterator<T, boolean>,
  224. context?: any): T;
  225. /**
  226. * @see _.find
  227. **/
  228. detect<T>(
  229. object: _.Dictionary<T>,
  230. iterator: _.ObjectIterator<T, boolean>,
  231. context?: any): T;
  232. /**
  233. * Looks through each value in the list, returning an array of all the values that pass a truth
  234. * test (iterator). Delegates to the native filter method, if it exists.
  235. * @param list Filter elements out of this list.
  236. * @param iterator Filter iterator function for each element in `list`.
  237. * @param context `this` object in `iterator`, optional.
  238. * @return The filtered list of elements.
  239. **/
  240. filter<T>(
  241. list: _.List<T>,
  242. iterator: _.ListIterator<T, boolean>,
  243. context?: any): T[];
  244. /**
  245. * @see _.filter
  246. **/
  247. filter<T>(
  248. object: _.Dictionary<T>,
  249. iterator: _.ObjectIterator<T, boolean>,
  250. context?: any): T[];
  251. /**
  252. * @see _.filter
  253. **/
  254. select<T>(
  255. list: _.List<T>,
  256. iterator: _.ListIterator<T, boolean>,
  257. context?: any): T[];
  258. /**
  259. * @see _.filter
  260. **/
  261. select<T>(
  262. object: _.Dictionary<T>,
  263. iterator: _.ObjectIterator<T, boolean>,
  264. context?: any): T[];
  265. /**
  266. * Looks through each value in the list, returning an array of all the values that contain all
  267. * of the key-value pairs listed in properties.
  268. * @param list List to match elements again `properties`.
  269. * @param properties The properties to check for on each element within `list`.
  270. * @return The elements within `list` that contain the required `properties`.
  271. **/
  272. where<T, U extends {}>(
  273. list: _.List<T>,
  274. properties: U): T[];
  275. /**
  276. * Looks through the list and returns the first value that matches all of the key-value pairs listed in properties.
  277. * @param list Search through this list's elements for the first object with all `properties`.
  278. * @param properties Properties to look for on the elements within `list`.
  279. * @return The first element in `list` that has all `properties`.
  280. **/
  281. findWhere<T, U extends {}>(
  282. list: _.List<T>,
  283. properties: U): T;
  284. /**
  285. * Returns the values in list without the elements that the truth test (iterator) passes.
  286. * The opposite of filter.
  287. * Return all the elements for which a truth test fails.
  288. * @param list Reject elements within this list.
  289. * @param iterator Reject iterator function for each element in `list`.
  290. * @param context `this` object in `iterator`, optional.
  291. * @return The rejected list of elements.
  292. **/
  293. reject<T>(
  294. list: _.List<T>,
  295. iterator: _.ListIterator<T, boolean>,
  296. context?: any): T[];
  297. /**
  298. * @see _.reject
  299. **/
  300. reject<T>(
  301. object: _.Dictionary<T>,
  302. iterator: _.ObjectIterator<T, boolean>,
  303. context?: any): T[];
  304. /**
  305. * Returns true if all of the values in the list pass the iterator truth test. Delegates to the
  306. * native method every, if present.
  307. * @param list Truth test against all elements within this list.
  308. * @param iterator Trust test iterator function for each element in `list`.
  309. * @param context `this` object in `iterator`, optional.
  310. * @return True if all elements passed the truth test, otherwise false.
  311. **/
  312. every<T>(
  313. list: _.List<T>,
  314. iterator?: _.ListIterator<T, boolean>,
  315. context?: any): boolean;
  316. /**
  317. * @see _.every
  318. **/
  319. every<T>(
  320. list: _.Dictionary<T>,
  321. iterator?: _.ObjectIterator<T, boolean>,
  322. context?: any): boolean;
  323. /**
  324. * @see _.every
  325. **/
  326. all<T>(
  327. list: _.List<T>,
  328. iterator?: _.ListIterator<T, boolean>,
  329. context?: any): boolean;
  330. /**
  331. * @see _.every
  332. **/
  333. all<T>(
  334. list: _.Dictionary<T>,
  335. iterator?: _.ObjectIterator<T, boolean>,
  336. context?: any): boolean;
  337. /**
  338. * Returns true if any of the values in the list pass the iterator truth test. Short-circuits and
  339. * stops traversing the list if a true element is found. Delegates to the native method some, if present.
  340. * @param list Truth test against all elements within this list.
  341. * @param iterator Trust test iterator function for each element in `list`.
  342. * @param context `this` object in `iterator`, optional.
  343. * @return True if any elements passed the truth test, otherwise false.
  344. **/
  345. some<T>(
  346. list: _.List<T>,
  347. iterator?: _.ListIterator<T, boolean>,
  348. context?: any): boolean;
  349. /**
  350. * @see _.some
  351. **/
  352. some<T>(
  353. object: _.Dictionary<T>,
  354. iterator?: _.ObjectIterator<T, boolean>,
  355. context?: any): boolean;
  356. /**
  357. * @see _.some
  358. **/
  359. any<T>(
  360. list: _.List<T>,
  361. iterator?: _.ListIterator<T, boolean>,
  362. context?: any): boolean;
  363. /**
  364. * @see _.some
  365. **/
  366. any<T>(
  367. object: _.Dictionary<T>,
  368. iterator?: _.ObjectIterator<T, boolean>,
  369. context?: any): boolean;
  370. /**
  371. * Returns true if the value is present in the list. Uses indexOf internally,
  372. * if list is an Array.
  373. * @param list Checks each element to see if `value` is present.
  374. * @param value The value to check for within `list`.
  375. * @return True if `value` is present in `list`, otherwise false.
  376. **/
  377. contains<T>(
  378. list: _.List<T>,
  379. value: T): boolean;
  380. /**
  381. * @see _.contains
  382. **/
  383. contains<T>(
  384. object: _.Dictionary<T>,
  385. value: T): boolean;
  386. /**
  387. * @see _.contains
  388. **/
  389. include<T>(
  390. list: _.Collection<T>,
  391. value: T): boolean;
  392. /**
  393. * @see _.contains
  394. **/
  395. include<T>(
  396. object: _.Dictionary<T>,
  397. value: T): boolean;
  398. /**
  399. * Calls the method named by methodName on each value in the list. Any extra arguments passed to
  400. * invoke will be forwarded on to the method invocation.
  401. * @param list The element's in this list will each have the method `methodName` invoked.
  402. * @param methodName The method's name to call on each element within `list`.
  403. * @param arguments Additional arguments to pass to the method `methodName`.
  404. **/
  405. invoke<T extends {}>(
  406. list: _.List<T>,
  407. methodName: string,
  408. ...arguments: any[]): any;
  409. /**
  410. * A convenient version of what is perhaps the most common use-case for map: extracting a list of
  411. * property values.
  412. * @param list The list to pluck elements out of that have the property `propertyName`.
  413. * @param propertyName The property to look for on each element within `list`.
  414. * @return The list of elements within `list` that have the property `propertyName`.
  415. **/
  416. pluck<T extends {}>(
  417. list: _.List<T>,
  418. propertyName: string): any[];
  419. /**
  420. * Returns the maximum value in list.
  421. * @param list Finds the maximum value in this list.
  422. * @return Maximum value in `list`.
  423. **/
  424. max(list: _.List<number>): number;
  425. /**
  426. * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate
  427. * the criterion by which the value is ranked.
  428. * @param list Finds the maximum value in this list.
  429. * @param iterator Compares each element in `list` to find the maximum value.
  430. * @param context `this` object in `iterator`, optional.
  431. * @return The maximum element within `list`.
  432. **/
  433. max<T>(
  434. list: _.List<T>,
  435. iterator?: _.ListIterator<T, any>,
  436. context?: any): T;
  437. /**
  438. * Returns the minimum value in list.
  439. * @param list Finds the minimum value in this list.
  440. * @return Minimum value in `list`.
  441. **/
  442. min(list: _.List<number>): number;
  443. /**
  444. * Returns the minimum value in list. If iterator is passed, it will be used on each value to generate
  445. * the criterion by which the value is ranked.
  446. * @param list Finds the minimum value in this list.
  447. * @param iterator Compares each element in `list` to find the minimum value.
  448. * @param context `this` object in `iterator`, optional.
  449. * @return The minimum element within `list`.
  450. **/
  451. min<T>(
  452. list: _.List<T>,
  453. iterator?: _.ListIterator<T, any>,
  454. context?: any): T;
  455. /**
  456. * Returns a sorted copy of list, ranked in ascending order by the results of running each value
  457. * through iterator. Iterator may also be the string name of the property to sort by (eg. length).
  458. * @param list Sorts this list.
  459. * @param iterator Sort iterator for each element within `list`.
  460. * @param context `this` object in `iterator`, optional.
  461. * @return A sorted copy of `list`.
  462. **/
  463. sortBy<T, TSort>(
  464. list: _.List<T>,
  465. iterator?: _.ListIterator<T, TSort>,
  466. context?: any): T[];
  467. /**
  468. * @see _.sortBy
  469. * @param iterator Sort iterator for each element within `list`.
  470. **/
  471. sortBy<T>(
  472. list: _.List<T>,
  473. iterator: string,
  474. context?: any): T[];
  475. /**
  476. * Splits a collection into sets, grouped by the result of running each value through iterator.
  477. * If iterator is a string instead of a function, groups by the property named by iterator on
  478. * each of the values.
  479. * @param list Groups this list.
  480. * @param iterator Group iterator for each element within `list`, return the key to group the element by.
  481. * @param context `this` object in `iterator`, optional.
  482. * @return An object with the group names as properties where each property contains the grouped elements from `list`.
  483. **/
  484. groupBy<T>(
  485. list: _.List<T>,
  486. iterator?: _.ListIterator<T, any>,
  487. context?: any): _.Dictionary<T[]>;
  488. /**
  489. * @see _.groupBy
  490. * @param iterator Property on each object to group them by.
  491. **/
  492. groupBy<T>(
  493. list: _.List<T>,
  494. iterator: string,
  495. context?: any): _.Dictionary<T[]>;
  496. /**
  497. * Given a `list`, and an `iterator` function that returns a key for each element in the list (or a property name),
  498. * returns an object with an index of each item. Just like _.groupBy, but for when you know your keys are unique.
  499. **/
  500. indexBy<T>(
  501. list: _.List<T>,
  502. iterator: _.ListIterator<T, any>,
  503. context?: any): _.Dictionary<T>;
  504. /**
  505. * @see _.indexBy
  506. * @param iterator Property on each object to index them by.
  507. **/
  508. indexBy<T>(
  509. list: _.List<T>,
  510. iterator: string,
  511. context?: any): _.Dictionary<T>;
  512. /**
  513. * Sorts a list into groups and returns a count for the number of objects in each group. Similar
  514. * to groupBy, but instead of returning a list of values, returns a count for the number of values
  515. * in that group.
  516. * @param list Group elements in this list and then count the number of elements in each group.
  517. * @param iterator Group iterator for each element within `list`, return the key to group the element by.
  518. * @param context `this` object in `iterator`, optional.
  519. * @return An object with the group names as properties where each property contains the number of elements in that group.
  520. **/
  521. countBy<T>(
  522. list: _.List<T>,
  523. iterator?: _.ListIterator<T, any>,
  524. context?: any): _.Dictionary<number>;
  525. /**
  526. * @see _.countBy
  527. * @param iterator Function name
  528. **/
  529. countBy<T>(
  530. list: _.List<T>,
  531. iterator: string,
  532. context?: any): _.Dictionary<number>;
  533. /**
  534. * Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle.
  535. * @param list List to shuffle.
  536. * @return Shuffled copy of `list`.
  537. **/
  538. shuffle<T>(list: _.Collection<T>): T[];
  539. /**
  540. * Produce a random sample from the `list`. Pass a number to return `n` random elements from the list. Otherwise a single random item will be returned.
  541. * @param list List to sample.
  542. * @return Random sample of `n` elements in `list`.
  543. **/
  544. sample<T>(list: _.Collection<T>, n: number): T[];
  545. /**
  546. * @see _.sample
  547. **/
  548. sample<T>(list: _.Collection<T>): T;
  549. /**
  550. * Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting
  551. * the arguments object.
  552. * @param list object to transform into an array.
  553. * @return `list` as an array.
  554. **/
  555. toArray<T>(list: _.Collection<T>): T[];
  556. /**
  557. * Return the number of values in the list.
  558. * @param list Count the number of values/elements in this list.
  559. * @return Number of values in `list`.
  560. **/
  561. size<T>(list: _.Collection<T>): number;
  562. /**
  563. * Split array into two arrays:
  564. * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
  565. * @param array Array to split in two.
  566. * @param iterator Filter iterator function for each element in `array`.
  567. * @param context `this` object in `iterator`, optional.
  568. * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not.
  569. **/
  570. partition<T>(
  571. array: Array<T>,
  572. iterator: _.ListIterator<T, boolean>,
  573. context?: any): T[][];
  574. /*********
  575. * Arrays *
  576. **********/
  577. /**
  578. * Returns the first element of an array. Passing n will return the first n elements of the array.
  579. * @param array Retrieves the first element of this array.
  580. * @return Returns the first element of `array`.
  581. **/
  582. first<T>(array: _.List<T>): T;
  583. /**
  584. * @see _.first
  585. * @param n Return more than one element from `array`.
  586. **/
  587. first<T>(
  588. array: _.List<T>,
  589. n: number): T[];
  590. /**
  591. * @see _.first
  592. **/
  593. head<T>(array: _.List<T>): T;
  594. /**
  595. * @see _.first
  596. **/
  597. head<T>(
  598. array: _.List<T>,
  599. n: number): T[];
  600. /**
  601. * @see _.first
  602. **/
  603. take<T>(array: _.List<T>): T;
  604. /**
  605. * @see _.first
  606. **/
  607. take<T>(
  608. array: _.List<T>,
  609. n: number): T[];
  610. /**
  611. * Returns everything but the last entry of the array. Especially useful on the arguments object.
  612. * Pass n to exclude the last n elements from the result.
  613. * @param array Retrieve all elements except the last `n`.
  614. * @param n Leaves this many elements behind, optional.
  615. * @return Returns everything but the last `n` elements of `array`.
  616. **/
  617. initial<T>(
  618. array: _.List<T>,
  619. n?: number): T[];
  620. /**
  621. * Returns the last element of an array. Passing n will return the last n elements of the array.
  622. * @param array Retrieves the last element of this array.
  623. * @return Returns the last element of `array`.
  624. **/
  625. last<T>(array: _.List<T>): T;
  626. /**
  627. * @see _.last
  628. * @param n Return more than one element from `array`.
  629. **/
  630. last<T>(
  631. array: _.List<T>,
  632. n: number): T[];
  633. /**
  634. * Returns the rest of the elements in an array. Pass an index to return the values of the array
  635. * from that index onward.
  636. * @param array The array to retrieve all but the first `index` elements.
  637. * @param n The index to start retrieving elements forward from, optional, default = 1.
  638. * @return Returns the elements of `array` from `index` to the end of `array`.
  639. **/
  640. rest<T>(
  641. array: _.List<T>,
  642. n?: number): T[];
  643. /**
  644. * @see _.rest
  645. **/
  646. tail<T>(
  647. array: _.List<T>,
  648. n?: number): T[];
  649. /**
  650. * @see _.rest
  651. **/
  652. drop<T>(
  653. array: _.List<T>,
  654. n?: number): T[];
  655. /**
  656. * Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, "",
  657. * undefined and NaN are all falsy.
  658. * @param array Array to compact.
  659. * @return Copy of `array` without false values.
  660. **/
  661. compact<T>(array: _.List<T>): T[];
  662. /**
  663. * Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will
  664. * only be flattened a single level.
  665. * @param array The array to flatten.
  666. * @param shallow If true then only flatten one level, optional, default = false.
  667. * @return `array` flattened.
  668. **/
  669. flatten(
  670. array: _.List<any>,
  671. shallow?: boolean): any[];
  672. /**
  673. * Returns a copy of the array with all instances of the values removed.
  674. * @param array The array to remove `values` from.
  675. * @param values The values to remove from `array`.
  676. * @return Copy of `array` without `values`.
  677. **/
  678. without<T>(
  679. array: _.List<T>,
  680. ...values: T[]): T[];
  681. /**
  682. * Computes the union of the passed-in arrays: the list of unique items, in order, that are
  683. * present in one or more of the arrays.
  684. * @param arrays Array of arrays to compute the union of.
  685. * @return The union of elements within `arrays`.
  686. **/
  687. union<T>(...arrays: _.List<T>[]): T[];
  688. /**
  689. * Computes the list of values that are the intersection of all the arrays. Each value in the result
  690. * is present in each of the arrays.
  691. * @param arrays Array of arrays to compute the intersection of.
  692. * @return The intersection of elements within `arrays`.
  693. **/
  694. intersection<T>(...arrays: _.List<T>[]): T[];
  695. /**
  696. * Similar to without, but returns the values from array that are not present in the other arrays.
  697. * @param array Keeps values that are within `others`.
  698. * @param others The values to keep within `array`.
  699. * @return Copy of `array` with only `others` values.
  700. **/
  701. difference<T>(
  702. array: _.List<T>,
  703. ...others: _.List<T>[]): T[];
  704. /**
  705. * Produces a duplicate-free version of the array, using === to test object equality. If you know in
  706. * advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If
  707. * you want to compute unique items based on a transformation, pass an iterator function.
  708. * @param array Array to remove duplicates from.
  709. * @param isSorted True if `array` is already sorted, optional, default = false.
  710. * @param iterator Transform the elements of `array` before comparisons for uniqueness.
  711. * @param context 'this' object in `iterator`, optional.
  712. * @return Copy of `array` where all elements are unique.
  713. **/
  714. uniq<T, TSort>(
  715. array: _.List<T>,
  716. isSorted?: boolean,
  717. iterator?: _.ListIterator<T, TSort>,
  718. context?: any): T[];
  719. /**
  720. * @see _.uniq
  721. **/
  722. uniq<T, TSort>(
  723. array: _.List<T>,
  724. iterator?: _.ListIterator<T, TSort>,
  725. context?: any): T[];
  726. /**
  727. * @see _.uniq
  728. **/
  729. unique<T, TSort>(
  730. array: _.List<T>,
  731. iterator?: _.ListIterator<T, TSort>,
  732. context?: any): T[];
  733. /**
  734. * @see _.uniq
  735. **/
  736. unique<T, TSort>(
  737. array: _.List<T>,
  738. isSorted?: boolean,
  739. iterator?: _.ListIterator<T, TSort>,
  740. context?: any): T[];
  741. /**
  742. * Merges together the values of each of the arrays with the values at the corresponding position.
  743. * Useful when you have separate data sources that are coordinated through matching array indexes.
  744. * If you're working with a matrix of nested arrays, zip.apply can transpose the matrix in a similar fashion.
  745. * @param arrays The arrays to merge/zip.
  746. * @return Zipped version of `arrays`.
  747. **/
  748. zip(...arrays: any[][]): any[][];
  749. /**
  750. * @see _.zip
  751. **/
  752. zip(...arrays: any[]): any[];
  753. /**
  754. * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
  755. * list of keys, and a list of values.
  756. * @param keys Key array.
  757. * @param values Value array.
  758. * @return An object containing the `keys` as properties and `values` as the property values.
  759. **/
  760. object<TResult extends {}>(
  761. keys: _.List<string>,
  762. values: _.List<any>): TResult;
  763. /**
  764. * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
  765. * list of keys, and a list of values.
  766. * @param keyValuePairs Array of [key, value] pairs.
  767. * @return An object containing the `keys` as properties and `values` as the property values.
  768. **/
  769. object<TResult extends {}>(...keyValuePairs: any[][]): TResult;
  770. /**
  771. * @see _.object
  772. **/
  773. object<TResult extends {}>(
  774. list: _.List<any>,
  775. values?: any): TResult;
  776. /**
  777. * Returns the index at which value can be found in the array, or -1 if value is not present in the array.
  778. * Uses the native indexOf function unless it's missing. If you're working with a large array, and you know
  779. * that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number
  780. * as the third argument in order to look for the first matching value in the array after the given index.
  781. * @param array The array to search for the index of `value`.
  782. * @param value The value to search for within `array`.
  783. * @param isSorted True if the array is already sorted, optional, default = false.
  784. * @return The index of `value` within `array`.
  785. **/
  786. indexOf<T>(
  787. array: _.List<T>,
  788. value: T,
  789. isSorted?: boolean): number;
  790. /**
  791. * @see _indexof
  792. **/
  793. indexOf<T>(
  794. array: _.List<T>,
  795. value: T,
  796. startFrom: number): number;
  797. /**
  798. * Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the
  799. * native lastIndexOf function if possible. Pass fromIndex to start your search at a given index.
  800. * @param array The array to search for the last index of `value`.
  801. * @param value The value to search for within `array`.
  802. * @param from The starting index for the search, optional.
  803. * @return The index of the last occurrence of `value` within `array`.
  804. **/
  805. lastIndexOf<T>(
  806. array: _.List<T>,
  807. value: T,
  808. from?: number): number;
  809. /**
  810. * Uses a binary search to determine the index at which the value should be inserted into the list in order
  811. * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking
  812. * of each value, including the value you pass.
  813. * @param list The sorted list.
  814. * @param value The value to determine its index within `list`.
  815. * @param iterator Iterator to compute the sort ranking of each value, optional.
  816. * @return The index where `value` should be inserted into `list`.
  817. **/
  818. sortedIndex<T, TSort>(
  819. list: _.List<T>,
  820. value: T,
  821. iterator?: (x: T) => TSort, context?: any): number;
  822. /**
  823. * A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted,
  824. * defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented)
  825. * by step, exclusive.
  826. * @param start Start here.
  827. * @param stop Stop here.
  828. * @param step The number to count up by each iteration, optional, default = 1.
  829. * @return Array of numbers from `start` to `stop` with increments of `step`.
  830. **/
  831. range(
  832. start: number,
  833. stop: number,
  834. step?: number): number[];
  835. /**
  836. * @see _.range
  837. * @param stop Stop here.
  838. * @return Array of numbers from 0 to `stop` with increments of 1.
  839. * @note If start is not specified the implementation will never pull the step (step = arguments[2] || 0)
  840. **/
  841. range(stop: number): number[];
  842. /*************
  843. * Functions *
  844. *************/
  845. /**
  846. * Bind a function to an object, meaning that whenever the function is called, the value of this will
  847. * be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application.
  848. * @param func The function to bind `this` to `object`.
  849. * @param context The `this` pointer whenever `fn` is called.
  850. * @param arguments Additional arguments to pass to `fn` when called.
  851. * @return `fn` with `this` bound to `object`.
  852. **/
  853. bind(
  854. func: Function,
  855. context: any,
  856. ...arguments: any[]): () => any;
  857. /**
  858. * Binds a number of methods on the object, specified by methodNames, to be run in the context of that object
  859. * whenever they are invoked. Very handy for binding functions that are going to be used as event handlers,
  860. * which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the
  861. * object's function properties will be bound to it.
  862. * @param object The object to bind the methods `methodName` to.
  863. * @param methodNames The methods to bind to `object`, optional and if not provided all of `object`'s
  864. * methods are bound.
  865. **/
  866. bindAll(
  867. object: any,
  868. ...methodNames: string[]): any;
  869. /**
  870. * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value.
  871. * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be
  872. * pre-filled, but left open to supply at call-time.
  873. * @param fn Function to partially fill in arguments.
  874. * @param arguments The partial arguments.
  875. * @return `fn` with partially filled in arguments.
  876. **/
  877. partial(
  878. fn: Function,
  879. ...arguments: any[]): Function;
  880. /**
  881. * Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations.
  882. * If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based
  883. * on the arguments to the original function. The default hashFunction just uses the first argument to the
  884. * memoized function as the key.
  885. * @param fn Computationally expensive function that will now memoized results.
  886. * @param hashFn Hash function for storing the result of `fn`.
  887. * @return Memoized version of `fn`.
  888. **/
  889. memoize(
  890. fn: Function,
  891. hashFn?: (...args: any[]) => string): Function;
  892. /**
  893. * Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments,
  894. * they will be forwarded on to the function when it is invoked.
  895. * @param func Function to delay `waitMS` amount of ms.
  896. * @param wait The amount of milliseconds to delay `fn`.
  897. * @arguments Additional arguments to pass to `fn`.
  898. **/
  899. delay(
  900. func: Function,
  901. wait: number,
  902. ...arguments: any[]): any;
  903. /**
  904. * @see _delay
  905. **/
  906. delay(
  907. func: Function,
  908. ...arguments: any[]): any;
  909. /**
  910. * Defers invoking the function until the current call stack has cleared, similar to using setTimeout
  911. * with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without
  912. * blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on
  913. * to the function when it is invoked.
  914. * @param fn The function to defer.
  915. * @param arguments Additional arguments to pass to `fn`.
  916. **/
  917. defer(
  918. fn: Function,
  919. ...arguments: any[]): void;
  920. /**
  921. * Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly,
  922. * will only actually call the original function at most once per every wait milliseconds. Useful for
  923. * rate-limiting events that occur faster than you can keep up with.
  924. * By default, throttle will execute the function as soon as you call it for the first time, and,
  925. * if you call it again any number of times during the wait period, as soon as that period is over.
  926. * If you'd like to disable the leading-edge call, pass {leading: false}, and if you'd like to disable
  927. * the execution on the trailing-edge, pass {trailing: false}.
  928. * @param func Function to throttle `waitMS` ms.
  929. * @param wait The number of milliseconds to wait before `fn` can be invoked again.
  930. * @param options Allows for disabling execution of the throttled function on either the leading or trailing edge.
  931. * @return `fn` with a throttle of `wait`.
  932. **/
  933. throttle(
  934. func: any,
  935. wait: number,
  936. options?: _.ThrottleSettings): Function;
  937. /**
  938. * Creates and returns a new debounced version of the passed function that will postpone its execution
  939. * until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing
  940. * behavior that should only happen after the input has stopped arriving. For example: rendering a preview
  941. * of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on.
  942. *
  943. * Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead
  944. * of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double
  945. *-clicks on a "submit" button from firing a second time.
  946. * @param fn Function to debounce `waitMS` ms.
  947. * @param wait The number of milliseconds to wait before `fn` can be invoked again.
  948. * @param immediate True if `fn` should be invoked on the leading edge of `waitMS` instead of the trailing edge.
  949. * @return Debounced version of `fn` that waits `wait` ms when invoked.
  950. **/
  951. debounce(
  952. fn: Function,
  953. wait: number,
  954. immediate?: boolean): Function;
  955. /**
  956. * Creates a version of the function that can only be called one time. Repeated calls to the modified
  957. * function will have no effect, returning the value from the original call. Useful for initialization
  958. * functions, instead of having to set a boolean flag and then check it later.
  959. * @param fn Function to only execute once.
  960. * @return Copy of `fn` that can only be invoked once.
  961. **/
  962. once(fn: Function): Function;
  963. /**
  964. * Creates a version of the function that will only be run after first being called count times. Useful
  965. * for grouping asynchronous responses, where you want to be sure that all the async calls have finished,
  966. * before proceeding.
  967. * @param count Number of times to be called before actually executing.
  968. * @fn The function to defer execution `count` times.
  969. * @return Copy of `fn` that will not execute until it is invoked `count` times.
  970. **/
  971. after(
  972. count: number,
  973. fn: Function): Function;
  974. /**
  975. * Wraps the first function inside of the wrapper function, passing it as the first argument. This allows
  976. * the wrapper to execute code before and after the function runs, adjust the arguments, and execute it
  977. * conditionally.
  978. * @param fn Function to wrap.
  979. * @param wrapper The function that will wrap `fn`.
  980. * @return Wrapped version of `fn.
  981. **/
  982. wrap(
  983. fn: Function,
  984. wrapper: (fn: Function, ...args: any[]) => any): Function;
  985. /**
  986. * Returns the composition of a list of functions, where each function consumes the return value of the
  987. * function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
  988. * @param functions List of functions to compose.
  989. * @return Composition of `functions`.
  990. **/
  991. compose(...functions: Function[]): Function;
  992. /**********
  993. * Objects *
  994. ***********/
  995. /**
  996. * Retrieve all the names of the object's properties.
  997. * @param object Retrieve the key or property names from this object.
  998. * @return List of all the property names on `object`.
  999. **/
  1000. keys(object: any): string[];
  1001. /**
  1002. * Return all of the values of the object's properties.
  1003. * @param object Retrieve the values of all the properties on this object.
  1004. * @return List of all the values on `object`.
  1005. **/
  1006. values(object: any): any[];
  1007. /**
  1008. * Convert an object into a list of [key, value] pairs.
  1009. * @param object Convert this object to a list of [key, value] pairs.
  1010. * @return List of [key, value] pairs on `object`.
  1011. **/
  1012. pairs(object: any): any[][];
  1013. /**
  1014. * Returns a copy of the object where the keys have become the values and the values the keys.
  1015. * For this to work, all of your object's values should be unique and string serializable.
  1016. * @param object Object to invert key/value pairs.
  1017. * @return An inverted key/value paired version of `object`.
  1018. **/
  1019. invert(object: any): any;
  1020. /**
  1021. * Returns a sorted list of the names of every method in an object - that is to say,
  1022. * the name of every function property of the object.
  1023. * @param object Object to pluck all function property names from.
  1024. * @return List of all the function names on `object`.
  1025. **/
  1026. functions(object: any): string[];
  1027. /**
  1028. * @see _functions
  1029. **/
  1030. methods(object: any): string[];
  1031. /**
  1032. * Copy all of the properties in the source objects over to the destination object, and return
  1033. * the destination object. It's in-order, so the last source will override properties of the
  1034. * same name in previous arguments.
  1035. * @param destination Object to extend all the properties from `sources`.
  1036. * @param sources Extends `destination` with all properties from these source objects.
  1037. * @return `destination` extended with all the properties from the `sources` objects.
  1038. **/
  1039. extend(
  1040. destination: any,
  1041. ...sources: any[]): any;
  1042. /**
  1043. * Return a copy of the object, filtered to only have values for the whitelisted keys
  1044. * (or array of valid keys).
  1045. * @param object Object to strip unwanted key/value pairs.
  1046. * @keys The key/value pairs to keep on `object`.
  1047. * @return Copy of `object` with only the `keys` properties.
  1048. **/
  1049. pick(
  1050. object: any,
  1051. ...keys: string[]): any;
  1052. /**
  1053. * Return a copy of the object, filtered to omit the blacklisted keys (or array of keys).
  1054. * @param object Object to strip unwanted key/value pairs.
  1055. * @param keys The key/value pairs to remove on `object`.
  1056. * @return Copy of `object` without the `keys` properties.
  1057. **/
  1058. omit(
  1059. object: any,
  1060. ...keys: string[]): any;
  1061. /**
  1062. * @see _.omit
  1063. **/
  1064. omit(
  1065. object: any,
  1066. keys: string[]): any;
  1067. /**
  1068. * Fill in null and undefined properties in object with values from the defaults objects,
  1069. * and return the object. As soon as the property is filled, further defaults will have no effect.
  1070. * @param object Fill this object with default values.
  1071. * @param defaults The default values to add to `object`.
  1072. * @return `object` with added `defaults` values.
  1073. **/
  1074. defaults(
  1075. object: any,
  1076. ...defaults: any[]): any;
  1077. /**
  1078. * Create a shallow-copied clone of the object.
  1079. * Any nested objects or arrays will be copied by reference, not duplicated.
  1080. * @param object Object to clone.
  1081. * @return Copy of `object`.
  1082. **/
  1083. clone<T>(object: T): T;
  1084. /**
  1085. * Invokes interceptor with the object, and then returns object. The primary purpose of this method
  1086. * is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  1087. * @param object Argument to `interceptor`.
  1088. * @param intercepter The function to modify `object` before continuing the method chain.
  1089. * @return Modified `object`.
  1090. **/
  1091. tap<T>(object: T, intercepter: Function): T;
  1092. /**
  1093. * Does the object contain the given key? Identical to object.hasOwnProperty(key), but uses a safe
  1094. * reference to the hasOwnProperty function, in case it's been overridden accidentally.
  1095. * @param object Object to check for `key`.
  1096. * @param key The key to check for on `object`.
  1097. * @return True if `key` is a property on `object`, otherwise false.
  1098. **/
  1099. has(object: any, key: string): boolean;
  1100. /**
  1101. * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.
  1102. * @param attrs Object with key values pair
  1103. * @return Predicate function
  1104. **/
  1105. matches<T, TResult>(attrs: T): _.ListIterator<T, TResult>;
  1106. /**
  1107. * Returns a function that will itself return the key property of any passed-in object.
  1108. * @param key Property of the object.
  1109. * @return Function which accept an object an returns the value of key in that object.
  1110. **/
  1111. property(key: string): (object: Object) => any;
  1112. /**
  1113. * Performs an optimized deep comparison between the two objects,
  1114. * to determine if they should be considered equal.
  1115. * @param object Compare to `other`.
  1116. * @param other Compare to `object`.
  1117. * @return True if `object` is equal to `other`.
  1118. **/
  1119. isEqual(object: any, other: any): boolean;
  1120. /**
  1121. * Returns true if object contains no values.
  1122. * @param object Check if this object has no properties or values.
  1123. * @return True if `object` is empty.
  1124. **/
  1125. isEmpty(object: any): boolean;
  1126. /**
  1127. * Returns true if object is a DOM element.
  1128. * @param object Check if this object is a DOM element.
  1129. * @return True if `object` is a DOM element, otherwise false.
  1130. **/
  1131. isElement(object: any): boolean;
  1132. /**
  1133. * Returns true if object is an Array.
  1134. * @param object Check if this object is an Array.
  1135. * @return True if `object` is an Array, otherwise false.
  1136. **/
  1137. isArray(object: any): boolean;
  1138. /**
  1139. * Returns true if value is an Object. Note that JavaScript arrays and functions are objects,
  1140. * while (normal) strings and numbers are not.
  1141. * @param object Check if this object is an Object.
  1142. * @return True of `object` is an Object, otherwise false.
  1143. **/
  1144. isObject(object: any): boolean;
  1145. /**
  1146. * Returns true if object is an Arguments object.
  1147. * @param object Check if this object is an Arguments object.
  1148. * @return True if `object` is an Arguments object, otherwise false.
  1149. **/
  1150. isArguments(object: any): boolean;
  1151. /**
  1152. * Returns true if object is a Function.
  1153. * @param object Check if this object is a Function.
  1154. * @return True if `object` is a Function, otherwise false.
  1155. **/
  1156. isFunction(object: any): boolean;
  1157. /**
  1158. * Returns true if object is a String.
  1159. * @param object Check if this object is a String.
  1160. * @return True if `object` is a String, otherwise false.
  1161. **/
  1162. isString(object: any): boolean;
  1163. /**
  1164. * Returns true if object is a Number (including NaN).
  1165. * @param object Check if this object is a Number.
  1166. * @return True if `object` is a Number, otherwise false.
  1167. **/
  1168. isNumber(object: any): boolean;
  1169. /**
  1170. * Returns true if object is a finite Number.
  1171. * @param object Check if this object is a finite Number.
  1172. * @return True if `object` is a finite Number.
  1173. **/
  1174. isFinite(object: any): boolean;
  1175. /**
  1176. * Returns true if object is either true or false.
  1177. * @param object Check if this object is a bool.
  1178. * @return True if `object` is a bool, otherwise false.
  1179. **/
  1180. isBoolean(object: any): boolean;
  1181. /**
  1182. * Returns true if object is a Date.
  1183. * @param object Check if this object is a Date.
  1184. * @return True if `object` is a Date, otherwise false.
  1185. **/
  1186. isDate(object: any): boolean;
  1187. /**
  1188. * Returns true if object is a RegExp.
  1189. * @param object Check if this object is a RegExp.
  1190. * @return True if `object` is a RegExp, otherwise false.
  1191. **/
  1192. isRegExp(object: any): boolean;
  1193. /**
  1194. * Returns true if object is NaN.
  1195. * Note: this is not the same as the native isNaN function,
  1196. * which will also return true if the variable is undefined.
  1197. * @param object Check if this object is NaN.
  1198. * @return True if `object` is NaN, otherwise false.
  1199. **/
  1200. isNaN(object: any): boolean;
  1201. /**
  1202. * Returns true if the value of object is null.
  1203. * @param object Check if this object is null.
  1204. * @return True if `object` is null, otherwise false.
  1205. **/
  1206. isNull(object: any): boolean;
  1207. /**
  1208. * Returns true if value is undefined.
  1209. * @param object Check if this object is undefined.
  1210. * @return True if `object` is undefined, otherwise false.
  1211. **/
  1212. isUndefined(value: any): boolean;
  1213. /* *********
  1214. * Utility *
  1215. ********** */
  1216. /**
  1217. * Give control of the "_" variable back to its previous owner.
  1218. * Returns a reference to the Underscore object.
  1219. * @return Underscore object reference.
  1220. **/
  1221. noConflict(): any;
  1222. /**
  1223. * Returns the same value that is used as the argument. In math: f(x) = x
  1224. * This function looks useless, but is used throughout Underscore as a default iterator.
  1225. * @param value Identity of this object.
  1226. * @return `value`.
  1227. **/
  1228. identity<T>(value: T): T;
  1229. /**
  1230. * Creates a function that returns the same value that is used as the argument of _.constant
  1231. * @param value Identity of this object.
  1232. * @return Function that return value.
  1233. **/
  1234. constant<T>(value: T): () => T;
  1235. /**
  1236. * Invokes the given iterator function n times.
  1237. * Each invocation of iterator is called with an index argument
  1238. * @param n Number of times to invoke `iterator`.
  1239. * @param iterator Function iterator to invoke `n` times.
  1240. * @param context `this` object in `iterator`, optional.
  1241. **/
  1242. times<TResult>(n: number, iterator: (n: number) => TResult, context?: any): TResult[];
  1243. /**
  1244. * Returns a random integer between min and max, inclusive. If you only pass one argument,
  1245. * it will return a number between 0 and that number.
  1246. * @param max The maximum random number.
  1247. * @return A random number between 0 and `max`.
  1248. **/
  1249. random(max: number): number;
  1250. /**
  1251. * @see _.random
  1252. * @param min The minimum random number.
  1253. * @return A random number between `min` and `max`.
  1254. **/
  1255. random(min: number, max: number): number;
  1256. /**
  1257. * Allows you to extend Underscore with your own utility functions. Pass a hash of
  1258. * {name: function} definitions to have your functions added to the Underscore object,
  1259. * as well as the OOP wrapper.
  1260. * @param object Mixin object containing key/function pairs to add to the Underscore object.
  1261. **/
  1262. mixin(object: any): void;
  1263. /**
  1264. * Generate a globally-unique id for client-side models or DOM elements that need one.
  1265. * If prefix is passed, the id will be appended to it. Without prefix, returns an integer.
  1266. * @param prefix A prefix string to start the unique ID with.
  1267. * @return Unique string ID beginning with `prefix`.
  1268. **/
  1269. uniqueId(prefix: string): string;
  1270. /**
  1271. * @see _.uniqueId
  1272. **/
  1273. uniqueId(): number;
  1274. /**
  1275. * Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters.
  1276. * @param str Raw string to escape.
  1277. * @return `str` HTML escaped.
  1278. **/
  1279. escape(str: string): string;
  1280. /**
  1281. * If the value of the named property is a function then invoke it; otherwise, return it.
  1282. * @param object Object to maybe invoke function `property` on.
  1283. * @param property The function by name to invoke on `object`.
  1284. * @return The result of invoking the function `property` on `object.
  1285. **/
  1286. result(object: any, property: string): any;
  1287. /**
  1288. * Compiles JavaScript templates into functions that can be evaluated for rendering. Useful
  1289. * for rendering complicated bits of HTML from JSON data sources. Template functions can both
  1290. * interpolate variables, using <%= ... %>, as well as execute arbitrary JavaScript code, with
  1291. * <% ... %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- ... %> When
  1292. * you evaluate a template function, pass in a data object that has properties corresponding to
  1293. * the template's free variables. If you're writing a one-off, you can pass the data object as
  1294. * the second parameter to template in order to render immediately instead of returning a template
  1295. * function. The settings argument should be a hash containing any _.templateSettings that should
  1296. * be overridden.
  1297. * @param templateString Underscore HTML template.
  1298. * @param data Data to use when compiling `templateString`.
  1299. * @param settings Settings to use while compiling.
  1300. * @return Returns the compiled Underscore HTML template.
  1301. **/
  1302. template(templateString: string, data?: any, settings?: _.TemplateSettings): (...data: any[]) => string;
  1303. /**
  1304. * By default, Underscore uses ERB-style template delimiters, change the
  1305. * following template settings to use alternative delimiters.
  1306. **/
  1307. templateSettings: _.TemplateSettings;
  1308. /**
  1309. * Returns an integer timestamp for the current time, using the fastest method available in the runtime. Useful for implementing timing/animation functions.
  1310. **/
  1311. now(): number;
  1312. /* **********
  1313. * Chaining *
  1314. *********** */
  1315. /**
  1316. * Returns a wrapped object. Calling methods on this object will continue to return wrapped objects
  1317. * until value() is used.
  1318. * @param obj Object to chain.
  1319. * @return Wrapped `obj`.
  1320. **/
  1321. chain<T>(obj: T[]): _Chain<T>;
  1322. chain<T extends {}>(obj: T): _Chain<T>;
  1323. /**
  1324. * Extracts the value of a wrapped object.
  1325. * @param obj Wrapped object to extract the value from.
  1326. * @return Value of `obj`.
  1327. **/
  1328. value<T, TResult>(obj: T): TResult;
  1329. }
  1330. interface Underscore<T> {
  1331. /* *************
  1332. * Collections *
  1333. ************* */
  1334. /**
  1335. * Wrapped type `any[]`.
  1336. * @see _.each
  1337. **/
  1338. each(iterator: _.ListIterator<T, void>, context?: any): T[];
  1339. /**
  1340. * @see _.each
  1341. **/
  1342. each(iterator: _.ObjectIterator<T, void>, context?: any): T[];
  1343. /**
  1344. * @see _.each
  1345. **/
  1346. forEach(iterator: _.ListIterator<T, void>, context?: any): T[];
  1347. /**
  1348. * @see _.each
  1349. **/
  1350. forEach(iterator: _.ObjectIterator<T, void>, context?: any): T[];
  1351. /**
  1352. * Wrapped type `any[]`.
  1353. * @see _.map
  1354. **/
  1355. map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): TResult[];
  1356. /**
  1357. * Wrapped type `any[]`.
  1358. * @see _.map
  1359. **/
  1360. map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): TResult[];
  1361. /**
  1362. * @see _.map
  1363. **/
  1364. collect<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): TResult[];
  1365. /**
  1366. * @see _.map
  1367. **/
  1368. collect<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): TResult[];
  1369. /**
  1370. * Wrapped type `any[]`.
  1371. * @see _.reduce
  1372. **/
  1373. reduce<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1374. /**
  1375. * @see _.reduce
  1376. **/
  1377. inject<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1378. /**
  1379. * @see _.reduce
  1380. **/
  1381. foldl<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1382. /**
  1383. * Wrapped type `any[]`.
  1384. * @see _.reduceRight
  1385. **/
  1386. reduceRight<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1387. /**
  1388. * @see _.reduceRight
  1389. **/
  1390. foldr<TResult>(iterator: _.MemoIterator<T, TResult>, memo?: TResult, context?: any): TResult;
  1391. /**
  1392. * Wrapped type `any[]`.
  1393. * @see _.find
  1394. **/
  1395. find(iterator: _.ListIterator<T, boolean>, context?: any): T;
  1396. /**
  1397. * @see _.find
  1398. **/
  1399. detect(iterator: _.ListIterator<T, boolean>, context?: any): T;
  1400. /**
  1401. * Wrapped type `any[]`.
  1402. * @see _.filter
  1403. **/
  1404. filter(iterator: _.

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