Skip to content

Commit

Permalink
Simplify has and hasIn.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Feb 27, 2017
1 parent d1d8681 commit b6a426a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 57 deletions.
16 changes: 0 additions & 16 deletions .internal/baseHas.js

This file was deleted.

13 changes: 0 additions & 13 deletions .internal/baseHasIn.js

This file was deleted.

22 changes: 8 additions & 14 deletions 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 } }
Expand All @@ -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
19 changes: 5 additions & 14 deletions hasIn.js
@@ -1,33 +1,24 @@
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 }) })
*
* 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

4 comments on commit b6a426a

@falsyvalues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty big change in functionality 😲

@jdalton
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's splitting the functionality out into two modules (has and hasPath).

@falsyvalues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, somehow I missed next commit 😆

@jdalton
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so folks don't have to pay the byte cost when they don't need the extra functionality.

Please sign in to comment.