From 0bbcfcfffca381dd8c02d7f932f7f8bdbf600752 Mon Sep 17 00:00:00 2001 From: Sheeo Date: Fri, 27 Jan 2017 08:48:50 +0100 Subject: [PATCH] Add _.conforms and _.conformsTo --- lodash/index.d.ts | 32 ++++++++++++++++++++++++++++++-- lodash/lodash-tests.ts | 12 ++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lodash/index.d.ts b/lodash/index.d.ts index 678e0c58b9..95d6a83c8e 100644 --- a/lodash/index.d.ts +++ b/lodash/index.d.ts @@ -68,7 +68,7 @@ added 23 array methods: - [x] _.xorBy - [x] _.xorWith -added 18 lang methods: +added 20 lang methods: - [x] _.cloneDeepWith - [x] _.cloneWith - [x] _.eq @@ -87,6 +87,8 @@ added 18 lang methods: - [x] _.toNumber - [x] _.toSafeInteger - [x] _.toString +- [X] _.conforms +- [X] _.conformsTo added 13 object methods: - [x] _.assignIn @@ -225,7 +227,6 @@ Methods: - [ ] _.split - [ ] _.cond -- [ ] _.conforms - [ ] _.nthArg - [ ] _.over - [ ] _.overEvery @@ -11432,6 +11433,33 @@ declare namespace _ { ): LoDashExplicitObjectWrapper; } + /** + * An object containing predicate functions for each property of T + */ + type ConformsPredicateObject = { + [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(source: ConformsPredicateObject): (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(object: T, source: ConformsPredicateObject): boolean; + } + //_.eq interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c1a5ca3e64..7d4d22d387 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -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;