PageRenderTime 72ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/underscore/underscore.d.ts

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

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