From 242f39f73508ec72ade4e7144b142c2d66dbabe8 Mon Sep 17 00:00:00 2001 From: DomiR Date: Fri, 15 Jan 2016 02:55:49 +0100 Subject: [PATCH] (feature) Add _.hasIn --- lodash/lodash-tests.ts | 30 ++++++++++++++++ lodash/lodash.d.ts | 78 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 102 insertions(+), 6 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 7db984bcc..2e95b756d 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -8222,6 +8222,36 @@ module TestHas { } } +// _.hasIn +module TestHasIn { + type SampleObject = {a: number; b: string; c: boolean;}; + + let object: SampleObject; + + { + let result: boolean; + + result = _.hasIn(object, ''); + result = _.hasIn(object, 42); + result = _.hasIn(object, true); + result = _.hasIn(object, ['', 42, true]); + + result = _(object).hasIn(''); + result = _(object).hasIn(42); + result = _(object).hasIn(true); + result = _(object).hasIn(['', 42, true]); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(object).chain().hasIn(''); + result = _(object).chain().hasIn(42); + result = _(object).chain().hasIn(true); + result = _(object).chain().hasIn(['', 42, true]); + } +} + // _.invert module TestInvert { { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index e27022b9c..14b0f7246 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -102,8 +102,8 @@ added 13 object methods: - [x] _.assignIn - [x] _.assignInWith - [x] _.assignWith -- [ ] _.functionsIn -- [ ] _.hasIn +- [x] _.functionsIn +- [x] _.hasIn - [ ] _.invoke - [ ] _.mergeWith - [x] _.omitBy @@ -13114,11 +13114,30 @@ declare module _ { //_.has interface LoDashStatic { /** - * Checks if path is a direct property. + * Checks if `path` is a direct property of `object`. * - * @param object The object to query. - * @param path The path to check. - * @return Returns true if path is a direct property, else false. + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = { 'a': { 'b': { 'c': 3 } } }; + * var other = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) }); + * + * _.has(object, 'a'); + * // => true + * + * _.has(object, 'a.b.c'); + * // => true + * + * _.has(object, ['a', 'b', 'c']); + * // => true + * + * _.has(other, 'a'); + * // => false */ has( object: T, @@ -13140,6 +13159,53 @@ declare module _ { has(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper; } + //_.hasIn + interface LoDashStatic { + /** + * Checks if `path` is a direct or inherited property of `object`. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = _.create({ 'a': _.create({ 'b': _.create({ 'c': 3 }) }) }); + * + * _.hasIn(object, 'a'); + * // => true + * + * _.hasIn(object, 'a.b.c'); + * // => true + * + * _.hasIn(object, ['a', 'b', 'c']); + * // => true + * + * _.hasIn(object, 'b'); + * // => false + */ + hasIn( + object: T, + path: StringRepresentable|StringRepresentable[] + ): boolean; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.hasIn + */ + hasIn(path: StringRepresentable|StringRepresentable[]): boolean; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.hasIn + */ + hasIn(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper; + } + //_.invert interface LoDashStatic { /**