From b6a426a10deeacbbaf067cfe45b099153127b9b7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 26 Feb 2017 23:07:13 -0800 Subject: [PATCH] Simplify `has` and `hasIn`. --- .internal/baseHas.js | 16 ---------------- .internal/baseHasIn.js | 13 ------------- has.js | 22 ++++++++-------------- hasIn.js | 19 +++++-------------- 4 files changed, 13 insertions(+), 57 deletions(-) delete mode 100644 .internal/baseHas.js delete mode 100644 .internal/baseHasIn.js diff --git a/.internal/baseHas.js b/.internal/baseHas.js deleted file mode 100644 index 3bd6d0603..000000000 --- a/.internal/baseHas.js +++ /dev/null @@ -1,16 +0,0 @@ -/** Used to check objects for own properties. */ -const hasOwnProperty = Object.prototype.hasOwnProperty - -/** - * The base implementation of `has` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ -function baseHas(object, key) { - return object != null && hasOwnProperty.call(object, key) -} - -export default baseHas diff --git a/.internal/baseHasIn.js b/.internal/baseHasIn.js deleted file mode 100644 index f98fd8c8a..000000000 --- a/.internal/baseHasIn.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * The base implementation of `hasIn` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ -function baseHasIn(object, key) { - return object != null && key in Object(object) -} - -export default baseHasIn diff --git a/has.js b/has.js index abb208bfa..9cec79d5a 100644 --- a/has.js +++ b/has.js @@ -1,15 +1,15 @@ -import baseHas from './.internal/baseHas.js' -import hasPath from './.internal/hasPath.js' +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty /** - * Checks if `path` is a direct property of `object`. + * Checks if `key` is a direct property of `object`. * * @since 0.1.0 * @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`. - * @see hasIn, set, get + * @param {string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + * @see hasIn, hasPath, hasPathIn * @example * * const object = { 'a': { 'b': 2 } } @@ -18,17 +18,11 @@ import hasPath from './.internal/hasPath.js' * has(object, 'a') * // => true * - * has(object, 'a.b') - * // => true - * - * has(object, ['a', 'b']) - * // => true - * * has(other, 'a') * // => false */ -function has(object, path) { - return object != null && hasPath(object, path, baseHas) +function has(object, key) { + return object != null && hasOwnProperty.call(object, key) } export default has diff --git a/hasIn.js b/hasIn.js index 32499ebb7..71d35d511 100644 --- a/hasIn.js +++ b/hasIn.js @@ -1,15 +1,12 @@ -import baseHasIn from './.internal/baseHasIn.js' -import hasPath from './.internal/hasPath.js' - /** * Checks if `path` is a direct or inherited property of `object`. * * @since 4.0.0 * @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`. - * @see has, get, set, unset + * @param {string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + * @see has, hasPath, hasPathIn * @example * * const object = create({ 'a': create({ 'b': 2 }) }) @@ -17,17 +14,11 @@ import hasPath from './.internal/hasPath.js' * hasIn(object, 'a') * // => true * - * hasIn(object, 'a.b') - * // => true - * - * hasIn(object, ['a', 'b']) - * // => true - * * hasIn(object, 'b') * // => false */ -function hasIn(object, path) { - return object != null && hasPath(object, path, baseHasIn) +function hasIn(object, key) { + return object != null && key in Object(object) } export default hasIn