From 6419a25ae9a741e5b6c1901b71ab70b6758244d0 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 27 Sep 2015 12:32:11 +0500 Subject: [PATCH] lodash: added _.matchesProperty() method --- lodash/lodash-tests.ts | 18 ++++++++++++++++++ lodash/lodash.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 6733f77d4..89c5736fa 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -2696,6 +2696,24 @@ module TestMatches { } } +// _.matchesProperty +module TestMatches { + let path: {toString(): string;}|{toString(): string;}[]; + let source: TResult; + + { + let result: (value: any) => boolean; + result = _.matchesProperty(path, source); + result = _(path).matchesProperty(source).value(); + } + + { + let result: (value: TResult) => boolean; + result = _.matchesProperty(path, source); + result = _(path).matchesProperty(source).value(); + } +} + // _.method class TestMethod { a = { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e7411f3a9..4d83c7942 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8654,6 +8654,48 @@ declare module _ { matches(): LoDashObjectWrapper<(value: V) => boolean>; } + //_.matchesProperty + interface LoDashStatic { + /** + * Creates a function that compares the property value of path on a given object to value. + * + * Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and + * strings. Objects are compared by their own, not inherited, enumerable properties. + * + * @param path The path of the property to get. + * @param srcValue The value to match. + * @return Returns the new function. + */ + matchesProperty( + path: StringRepresentable|StringRepresentable[], + srcValue: T + ): (value: any) => boolean; + + /** + * @see _.matchesProperty + */ + matchesProperty( + path: StringRepresentable|StringRepresentable[], + srcValue: T + ): (value: V) => boolean; + } + + interface LoDashWrapperBase { + /** + * @see _.matchesProperty + */ + matchesProperty( + srcValue: SrcValue + ): LoDashObjectWrapper<(value: any) => boolean>; + + /** + * @see _.matchesProperty + */ + matchesProperty( + srcValue: SrcValue + ): LoDashObjectWrapper<(value: Value) => boolean>; + } + //_.method interface LoDashStatic { /**