Remove baseForOwn from several modules.

This commit is contained in:
John-David Dalton
2017-03-04 23:26:27 -08:00
parent 17f7069d07
commit 3c2795b816
8 changed files with 31 additions and 28 deletions

View File

@@ -1,6 +1,3 @@
import baseFindKey from './.internal/baseFindKey.js'
import baseForOwn from './.internal/baseForOwn.js'
/**
* This method is like `find` except that it returns the key of the first
* element `predicate` returns truthy for instead of the element itself.
@@ -24,7 +21,18 @@ import baseForOwn from './.internal/baseForOwn.js'
* // => 'barney' (iteration order is not guaranteed)
*/
function findKey(object, predicate) {
return baseFindKey(object, predicate, baseForOwn)
let result
if (object == null) {
return result
}
Object.keys(object).some((key) => {
const value = object[key]
if (predicate(value, key, object)) {
result = value
return true
}
})
return result
}
export default findKey

View File

@@ -1,5 +1,3 @@
import baseForOwn from './.internal/baseForOwn.js'
/**
* Iterates over own enumerable string keyed properties of an object and
* invokes `iteratee` for each property. The iteratee is invoked with three
@@ -10,7 +8,6 @@ import baseForOwn from './.internal/baseForOwn.js'
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see forEach, forEachRight, forIn, forInRight, forOwnRight
* @example
*
@@ -27,7 +24,9 @@ import baseForOwn from './.internal/baseForOwn.js'
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee) {
return object && baseForOwn(object, iteratee)
if (object != null) {
Object.keys(Object(object)).forEach((key) => iteratee(object[key], key, object))
}
}
export default forOwn

View File

@@ -1,5 +1,3 @@
import baseForOwnRight from './.internal/baseForOwnRight.js'
/**
* This method is like `forOwn` except that it iterates over properties of
* `object` in the opposite order.
@@ -25,7 +23,14 @@ import baseForOwnRight from './.internal/baseForOwnRight.js'
* // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'.
*/
function forOwnRight(object, iteratee) {
return object && baseForOwnRight(object, iteratee)
if (object == null) {
return
}
const props = Object.keys(object)
const length = props.length
while (length--) {
iteratee(object[props[length]], iteratee, object)
}
}
export default forOwnRight

View File

@@ -1,6 +1,3 @@
import arrayFilter from './arrayFilter.js'
import keys from './keys.js'
/**
* Creates an array of function property names from own enumerable properties
* of `object`.
@@ -23,9 +20,10 @@ import keys from './keys.js'
* // => ['a', 'b']
*/
function functions(object) {
return object == null
? []
: arrayFilter(keys(object), key => typeof object[key] == 'function')
if (object == null) {
return []
}
return Object.keys(object).filter((key) => typeof object[key] == 'function')
}
export default functions

View File

@@ -1,5 +1,3 @@
import baseForOwn from './.internal/baseForOwn.js'
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite
@@ -18,7 +16,7 @@ import baseForOwn from './.internal/baseForOwn.js'
*/
function invert(object) {
const result = {}
baseForOwn(object, (value, key) => {
Object.keys(object).forEach((value, key) => {
result[value] = key
})
return result

View File

@@ -1,5 +1,3 @@
import baseForOwn from './.internal/baseForOwn.js'
/** Used to check objects for own properties. */
const hasOwnProperty = Object.prototype.hasOwnProperty
@@ -24,8 +22,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
*/
function invertBy(object, iteratee) {
const result = {}
baseForOwn(object, (value, key) => {
Object.keys(object).forEach((value, key) => {
value = iteratee(value)
if (hasOwnProperty.call(result, value)) {
result[value].push(key)

View File

@@ -1,5 +1,4 @@
import baseAssignValue from './.internal/baseAssignValue.js'
import baseForOwn from './.internal/baseForOwn.js'
/**
* The opposite of `mapValues` this method creates an object with the
@@ -22,7 +21,7 @@ import baseForOwn from './.internal/baseForOwn.js'
*/
function mapKeys(object, iteratee) {
const result = {}
baseForOwn(object, (value, key, object) => {
Object.keys(object).forEach((value, key, object) => {
baseAssignValue(result, iteratee(value, key, object), value)
})
return result

View File

@@ -1,5 +1,4 @@
import baseAssignValue from './.internal/baseAssignValue.js'
import baseForOwn from './.internal/baseForOwn.js'
/**
* Creates an object with the same keys as `object` and values generated
@@ -25,7 +24,7 @@ import baseForOwn from './.internal/baseForOwn.js'
*/
function mapValues(object, iteratee) {
const result = {}
baseForOwn(object, (value, key, object) => {
Object.keys(object).forEach((value, key, object) => {
baseAssignValue(result, key, iteratee(value, key, object))
})
return result