diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index d3eb87f6a..64c45a478 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -67,6 +67,17 @@ _.shuffle([1, 2, 3, 4, 5, 6]); _.size({ one: 1, two: 2, three: 3 }); +_.partition([0, 1, 2, 3, 4, 5], (num)=>{return num % 2 ==0}); + +interface Family { + name: string; + relation : string; +} +var isUncleMoe = _.matches({name : 'moe', relation : 'uncle'}); +_.filter([{name: 'larry', relation : 'father'}, {name : 'moe', relation : 'uncle'}], isUncleMoe); + + + /////////////////////////////////////////////////////////////////////////////////////// _.first([5, 4, 3, 2, 1]); @@ -204,6 +215,8 @@ _.isArray([1, 2, 3]); _.isObject({}); _.isObject(1); +_.property('name')(moe); + // (() => { return _.isArguments(arguments); })(1, 2, 3); _.isArguments([1, 2, 3]); @@ -235,6 +248,11 @@ _.isUndefined((window).missingVariable); /////////////////////////////////////////////////////////////////////////////////////// +var UncleMoe = {name: 'moe'}; +_.constant(UncleMoe)(); + +typeof _.now() === "number"; + var underscore = _.noConflict(); var moe2 = { name: 'moe' }; diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 9e44c0c63..7e4bd99e1 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Underscore 1.5.2 +// Type definitions for Underscore 1.6.0 // Project: http://underscorejs.org/ // Definitions by: Boris Yankov // Definitions by: Josh Baldwin @@ -543,6 +543,19 @@ interface UnderscoreStatic { * @return Number of values in `list`. **/ size(list: _.Collection): number; + + /** + * Split array into two arrays: + * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate. + * @param array Array to split in two + * @param iterator Filter iterator function for each element in `array`. + * @param context `this` object in `iterator`, optional. + * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not. + **/ + partition( + array: Array, + iterator: _.ListIterator, + context?: any): T[][]; /********* * Arrays * @@ -1134,6 +1147,20 @@ interface UnderscoreStatic { **/ has(object: any, key: string): boolean; + /** + * Returns a function that will itself return the key property of any passed-in object + * @param key Property of the object + * @return Function which accept an object an returns the value of key in that object + **/ + property(key: string): (object: Object)=> any; + + /** + * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. + * @param attrs Object with key values pair + * @return Predicate function + **/ + matches(attrs: T): _.ListIterator; + /** * Performs an optimized deep comparison between the two objects, * to determine if they should be considered equal. @@ -1270,6 +1297,13 @@ interface UnderscoreStatic { **/ identity(value: T): T; + /** + * Creates a function that returns the same value that is used as the argument of _.constant + * @param value Identity of this object. + * @return Function that return value. + **/ + constant(value: T): () => T; + /** * Invokes the given iterator function n times. * Each invocation of iterator is called with an index argument @@ -1353,6 +1387,11 @@ interface UnderscoreStatic { **/ templateSettings: _.TemplateSettings; + /** + * Returns an integer timestamp for the current time, using the fastest method available in the runtime. Useful for implementing timing/animation functions. + **/ + now(): number; + /* ********** * Chaining * *********** */