Merge pull request #14288 from Sheeo/lodash-add-conforms

lodash: Add _.conforms and _.conformsTo
This commit is contained in:
Daniel Rosenwasser
2017-01-30 10:21:25 -08:00
committed by GitHub
2 changed files with 42 additions and 2 deletions
+30 -2
View File
@@ -69,7 +69,7 @@ added 23 array methods:
- [x] _.xorBy
- [x] _.xorWith
added 18 lang methods:
added 20 lang methods:
- [x] _.cloneDeepWith
- [x] _.cloneWith
- [x] _.eq
@@ -88,6 +88,8 @@ added 18 lang methods:
- [x] _.toNumber
- [x] _.toSafeInteger
- [x] _.toString
- [X] _.conforms
- [X] _.conformsTo
added 13 object methods:
- [x] _.assignIn
@@ -226,7 +228,6 @@ Methods:
- [ ] _.split
- [ ] _.cond
- [ ] _.conforms
- [ ] _.nthArg
- [ ] _.over
- [ ] _.overEvery
@@ -11436,6 +11437,33 @@ declare namespace _ {
): LoDashExplicitObjectWrapper<TResult>;
}
/**
* An object containing predicate functions for each property of T
*/
type ConformsPredicateObject<T> = {
[P in keyof T]: (val: T[P]) => boolean;
};
//_.conforms
interface LoDashStatic {
/**
* Creates a function that invokes the predicate properties of `source` with the corresponding
* property values of a given object, returning true if all predicates return truthy, else false.
*/
conforms<T>(source: ConformsPredicateObject<T>): (Target: T) => boolean;
}
//_.conformsTo
interface LoDashStatic {
/**
* Checks if object conforms to source by invoking the predicate properties of source with the
* corresponding property values of object.
*
* Note: This method is equivalent to _.conforms when source is partially applied.
*/
conformsTo<T>(object: T, source: ConformsPredicateObject<T>): boolean;
}
//_.eq
interface LoDashStatic {
/**
+12
View File
@@ -6488,6 +6488,18 @@ namespace TestCloneWith {
}
}
// _.conforms
namespace TestConforms {
let result: boolean = _.conforms({foo: (v: string) => false})({foo: "foo"});
let result2: boolean = _.conforms({})({foo: "foo"});
}
// _.conformsTo
namespace TestConformsTo {
let result: boolean = _.conformsTo({foo: "foo"}, {foo: (v: string) => false});
let result2: boolean = _.conformsTo({}, {foo: (v: string) => false});
}
// _.eq
namespace TestEq {
let customizer: (value: any, other: any, indexOrKey?: number|string) => boolean;