Merge pull request #11117 from webbiesdk/underscoreTo18

Updating underscore to reflect version 1.8.3
This commit is contained in:
Sheetal Nandi
2016-09-08 09:45:11 -07:00
committed by GitHub
2 changed files with 175 additions and 18 deletions

View File

@@ -166,6 +166,8 @@ _.some({ a: 'a', b: 'B', c: 'C', d: 'd' }, l => l === l.toUpperCase());
_.contains([1, 2, 3], 3);
_.contains([1, 2, 3], 3, 1);
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }];
@@ -278,10 +280,12 @@ _.defer(function () { alert('deferred'); });
var updatePosition = (param:string) => alert('updating position... Param: ' + param);
var throttled = _.throttle(updatePosition, 100);
$(window).scroll(throttled);
throttled.cancel();
var calculateLayout = (param:string) => alert('calculating layout... Param: ' + param);
var lazyLayout = _.debounce(calculateLayout, 300);
$(window).resize(lazyLayout);
lazyLayout.cancel();
var createApplication = (param:string) => alert('creating application... Param: ' + param);
var initialize = _.once(createApplication);
@@ -406,6 +410,7 @@ function useBoolean(arg: Boolean) {};
function useDate(arg: Date) {};
function useRegExp(arg: RegExp) {};
function useArray<T>(arg: T[]) {};
function useSymbol(arg: symbol) {};
var guardedType: {};
if(_.isElement(guardedType)) useElement(guardedType);
@@ -419,6 +424,7 @@ if(_.isNumber(guardedType)) useNumber(guardedType);
if(_.isBoolean(guardedType)) useBoolean(guardedType);
if(_.isDate(guardedType)) useDate(guardedType);
if(_.isRegExp(guardedType)) useRegExp(guardedType);
if(_.isSymbol(guardedType)) useSymbol(guardedType);
///////////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,4 +1,4 @@
// Type definitions for Underscore 1.7.0
// Type definitions for Underscore 1.8.3
// Project: http://underscorejs.org/
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Josh Baldwin <https://github.com/jbaldwin/>, Christopher Currens <https://github.com/ccurrens/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -74,6 +74,10 @@ declare module _ {
interface MemoObjectIterator<T, TResult> {
(prev: TResult, curr: T, key: string, list: Dictionary<T>): TResult;
}
interface Cancelable {
cancel() : void;
}
}
interface UnderscoreStatic {
@@ -458,10 +462,10 @@ interface UnderscoreStatic {
object: _.Dictionary<T>,
iterator?: _.ObjectIterator<T, boolean>,
context?: any): boolean;
any<T>(
list: _.List<T>,
value: T): boolean;
value: T): boolean;
/**
* Returns true if the value is present in the list. Uses indexOf internally,
@@ -472,7 +476,8 @@ interface UnderscoreStatic {
**/
contains<T>(
list: _.List<T>,
value: T): boolean;
value: T,
fromIndex?: number): boolean;
/**
* @see _.contains
@@ -486,7 +491,8 @@ interface UnderscoreStatic {
**/
include<T>(
list: _.Collection<T>,
value: T): boolean;
value: T,
fromIndex?: number): boolean;
/**
* @see _.contains
@@ -495,6 +501,21 @@ interface UnderscoreStatic {
object: _.Dictionary<T>,
value: T): boolean;
/**
* @see _.contains
**/
includes<T>(
list: _.Collection<T>,
value: T,
fromIndex?: number): boolean;
/**
* @see _.contains
**/
includes<T>(
object: _.Dictionary<T>,
value: T): boolean;
/**
* Calls the method named by methodName on each value in the list. Any extra arguments passed to
* invoke will be forwarded on to the method invocation.
@@ -1055,6 +1076,14 @@ interface UnderscoreStatic {
**/
range(stop: number): number[];
/**
* Split an **array** into several arrays containing **count** or less elements
* of initial array.
* @param array The array to split
* @param count The maximum size of the inner arrays.
*/
chunk<T>(array: _.Collection<T>, count: number): (_.Collection<T>)[]
/*************
* Functions *
*************/
@@ -3433,7 +3462,7 @@ interface UnderscoreStatic {
throttle<T extends Function>(
func: T,
wait: number,
options?: _.ThrottleSettings): T;
options?: _.ThrottleSettings): T & _.Cancelable;
/**
* Creates and returns a new debounced version of the passed function that will postpone its execution
@@ -3452,7 +3481,7 @@ interface UnderscoreStatic {
debounce<T extends Function>(
fn: T,
wait: number,
immediate?: boolean): T;
immediate?: boolean): T & _.Cancelable;
/**
* Creates a version of the function that can only be called one time. Repeated calls to the modified
@@ -3463,6 +3492,12 @@ interface UnderscoreStatic {
**/
once<T extends Function>(fn: T): T;
/**
* Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html)
* This accumulates the arguments passed into an array, after a given index.
**/
restArgs(func: Function, starIndex?: number) : Function;
/**
* Creates a version of the function that will only be run after first being called count times. Useful
* for grouping asynchronous responses, where you want to be sure that all the async calls have finished,
@@ -3624,6 +3659,14 @@ interface UnderscoreStatic {
destination: any,
...source: any[]): any;
/**
* Returns the first key on an object that passes a predicate test.
* @param obj the object to search in
* @param predicate Predicate function.
* @param context `this` object in `iterator`, optional.
*/
findKey<T>(obj: _.Dictionary<T>, predicate: _.ObjectIterator<T, boolean>, context? : any): T
/**
* Return a copy of the object, filtered to only have values for the whitelisted keys
* (or array of valid keys).
@@ -3677,6 +3720,16 @@ interface UnderscoreStatic {
object: any,
...defaults: any[]): any;
/**
* Creates an object that inherits from the given prototype object.
* If additional properties are provided then they will be added to the
* created object.
* @param prototype The prototype that the returned object will inherit from.
* @param props Additional props added to the returned object.
**/
create(prototype: any, props?: Object): any;
/**
* Create a shallow-copied clone of the object.
* Any nested objects or arrays will be copied by reference, not duplicated.
@@ -3710,6 +3763,14 @@ interface UnderscoreStatic {
**/
matches<T, TResult>(attrs: T): _.ListIterator<T, TResult>;
/**
* Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs.
* @see _.matches
* @param attrs Object with key values pair
* @return Predicate function
**/
matcher<T, TResult>(attrs: T): _.ListIterator<T, TResult>;
/**
* Returns a function that will itself return the key property of any passed-in object.
* @param key Property of the object.
@@ -3760,7 +3821,7 @@ interface UnderscoreStatic {
* @param object Check if this object is an Array.
* @return True if `object` is an Array, otherwise false.
**/
isArray(object: any): object is [];
isArray(object: any): object is any[];
/**
* Returns true if object is an Array.
@@ -3769,6 +3830,13 @@ interface UnderscoreStatic {
**/
isArray<T>(object: any): object is T[];
/**
* Returns true if object is a Symbol.
* @param object Check if this object is a Symbol.
* @return True if `object` is a Symbol, otherwise false.
**/
isSymbol(object: any): object is symbol;
/**
* Returns true if value is an Object. Note that JavaScript arrays and functions are objects,
* while (normal) strings and numbers are not.
@@ -3935,11 +4003,10 @@ interface UnderscoreStatic {
* a property matcher, or a propetery accessor.
* @param string|Function|Object value The value to iterate over, usually the key.
* @param any context
* @param number argCount
* @return Callback that can be applied to each element in a collection.
**/
iteratee(value: string): Function;
iteratee(value: Function, context?: any, argCount?: number): Function;
iteratee(value: Function, context?: any): Function;
iteratee(value: Object): Function;
/**
@@ -4178,13 +4245,19 @@ interface Underscore<T> {
* Wrapped type `any[]`.
* @see _.contains
**/
contains(value: T): boolean;
contains(value: T, fromIndex? : number): boolean;
/**
* Alias for 'contains'.
* @see contains
**/
include(value: T): boolean;
include(value: T, fromIndex? : number): boolean;
/**
* Alias for 'contains'.
* @see contains
**/
includes(value: T, fromIndex? : number): boolean;
/**
* Wrapped type `any[]`.
@@ -4513,6 +4586,12 @@ interface Underscore<T> {
**/
range(): number[];
/**
* Wrapped type any[][].
* @see _.chunk
**/
chunk(): any[][];
/* ***********
* Functions *
************ */
@@ -4562,13 +4641,13 @@ interface Underscore<T> {
* Wrapped type `Function`.
* @see _.throttle
**/
throttle(wait: number, options?: _.ThrottleSettings): Function;
throttle(wait: number, options?: _.ThrottleSettings): Function & _.Cancelable;
/**
* Wrapped type `Function`.
* @see _.debounce
**/
debounce(wait: number, immediate?: boolean): Function;
debounce(wait: number, immediate?: boolean): Function & _.Cancelable;
/**
* Wrapped type `Function`.
@@ -4576,6 +4655,12 @@ interface Underscore<T> {
**/
once(): Function;
/**
* Wrapped type `Function`.
* @see _.once
**/
restArgs(starIndex?: number) : Function;
/**
* Wrapped type `number`.
* @see _.after
@@ -4657,6 +4742,12 @@ interface Underscore<T> {
**/
extend(...sources: any[]): any;
/**
* Wrapped type `object`.
* @see _.extend
**/
findKey(predicate: _.ObjectIterator<any, boolean>, context? : any): any
/**
* Wrapped type `object`.
* @see _.pick
@@ -4679,6 +4770,12 @@ interface Underscore<T> {
**/
defaults(...defaults: any[]): any;
/**
* Wrapped type `any`.
* @see _.create
**/
create(props?: Object): any;
/**
* Wrapped type `any[]`.
* @see _.clone
@@ -4703,6 +4800,12 @@ interface Underscore<T> {
**/
matches<TResult>(): _.ListIterator<T, TResult>;
/**
* Wrapped type `any[]`.
* @see _.matcher
**/
matcher<TResult>(): _.ListIterator<T, TResult>;
/**
* Wrapped type `string`.
* @see _.property
@@ -4745,6 +4848,12 @@ interface Underscore<T> {
**/
isArray(): boolean;
/**
* Wrapped type `object`.
* @see _.isSymbol
**/
isSymbol(): boolean;
/**
* Wrapped type `object`.
* @see _.isObject
@@ -4872,7 +4981,7 @@ interface Underscore<T> {
* Wrapped type `string|Function|Object`.
* @see _.iteratee
**/
iteratee(context?: any, argCount?: number): Function;
iteratee(context?: any): Function;
/**
* Wrapped type `string`.
@@ -5096,13 +5205,19 @@ interface _Chain<T> {
* Wrapped type `any[]`.
* @see _.contains
**/
contains(value: T): _ChainSingle<boolean>;
contains(value: T, fromIndex?: number): _ChainSingle<boolean>;
/**
* Alias for 'contains'.
* @see contains
**/
include(value: T): _ChainSingle<boolean>;
include(value: T, fromIndex?: number): _ChainSingle<boolean>;
/**
* Alias for 'contains'.
* @see contains
**/
includes(value: T, fromIndex?: number): _ChainSingle<boolean>;
/**
* Wrapped type `any[]`.
@@ -5431,6 +5546,12 @@ interface _Chain<T> {
**/
range(): _Chain<T>;
/**
* Wrapped type `any[][]`.
* @see _.chunk
**/
chunk(): _Chain<T>;
/* ***********
* Functions *
************ */
@@ -5494,6 +5615,12 @@ interface _Chain<T> {
**/
once(): _Chain<T>;
/**
* Wrapped type `Function`.
* @see _.once
**/
restArgs(startIndex? : number): _Chain<T>;
/**
* Wrapped type `number`.
* @see _.after
@@ -5575,6 +5702,12 @@ interface _Chain<T> {
**/
extend(...sources: any[]): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.extend
**/
findKey(predicate: _.ObjectIterator<any, boolean>, context? : any): _Chain<T>
/**
* Wrapped type `object`.
* @see _.pick
@@ -5597,6 +5730,12 @@ interface _Chain<T> {
**/
defaults(...defaults: any[]): _Chain<T>;
/**
* Wrapped type `any`.
* @see _.create
**/
create(props?: Object): _Chain<T>;
/**
* Wrapped type `any[]`.
* @see _.clone
@@ -5621,6 +5760,12 @@ interface _Chain<T> {
**/
matches<TResult>(): _Chain<T>;
/**
* Wrapped type `any[]`.
* @see _.matcher
**/
matcher<TResult>(): _Chain<T>;
/**
* Wrapped type `string`.
* @see _.property
@@ -5663,6 +5808,12 @@ interface _Chain<T> {
**/
isArray(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.isSymbol
**/
isSymbol(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.isObject
@@ -5790,7 +5941,7 @@ interface _Chain<T> {
* Wrapped type `string|Function|Object`.
* @see _.iteratee
**/
iteratee(context?: any, argCount?: number): _Chain<T>;
iteratee(context?: any): _Chain<T>;
/**
* Wrapped type `string`.