mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Remove baseForOwn from several modules.
This commit is contained in:
16
findKey.js
16
findKey.js
@@ -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
|
* This method is like `find` except that it returns the key of the first
|
||||||
* element `predicate` returns truthy for instead of the element itself.
|
* 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)
|
* // => 'barney' (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function findKey(object, predicate) {
|
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
|
export default findKey
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import baseForOwn from './.internal/baseForOwn.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterates over own enumerable string keyed properties of an object and
|
* Iterates over own enumerable string keyed properties of an object and
|
||||||
* invokes `iteratee` for each property. The iteratee is invoked with three
|
* invokes `iteratee` for each property. The iteratee is invoked with three
|
||||||
@@ -10,7 +8,6 @@ import baseForOwn from './.internal/baseForOwn.js'
|
|||||||
* @category Object
|
* @category Object
|
||||||
* @param {Object} object The object to iterate over.
|
* @param {Object} object The object to iterate over.
|
||||||
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @returns {Object} Returns `object`.
|
|
||||||
* @see forEach, forEachRight, forIn, forInRight, forOwnRight
|
* @see forEach, forEachRight, forIn, forInRight, forOwnRight
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -27,7 +24,9 @@ import baseForOwn from './.internal/baseForOwn.js'
|
|||||||
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
||||||
*/
|
*/
|
||||||
function forOwn(object, iteratee) {
|
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
|
export default forOwn
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import baseForOwnRight from './.internal/baseForOwnRight.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `forOwn` except that it iterates over properties of
|
* This method is like `forOwn` except that it iterates over properties of
|
||||||
* `object` in the opposite order.
|
* `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'.
|
* // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'.
|
||||||
*/
|
*/
|
||||||
function forOwnRight(object, iteratee) {
|
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
|
export default forOwnRight
|
||||||
|
|||||||
10
functions.js
10
functions.js
@@ -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
|
* Creates an array of function property names from own enumerable properties
|
||||||
* of `object`.
|
* of `object`.
|
||||||
@@ -23,9 +20,10 @@ import keys from './keys.js'
|
|||||||
* // => ['a', 'b']
|
* // => ['a', 'b']
|
||||||
*/
|
*/
|
||||||
function functions(object) {
|
function functions(object) {
|
||||||
return object == null
|
if (object == null) {
|
||||||
? []
|
return []
|
||||||
: arrayFilter(keys(object), key => typeof object[key] == 'function')
|
}
|
||||||
|
return Object.keys(object).filter((key) => typeof object[key] == 'function')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default functions
|
export default functions
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import baseForOwn from './.internal/baseForOwn.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an object composed of the inverted keys and values of `object`.
|
* Creates an object composed of the inverted keys and values of `object`.
|
||||||
* If `object` contains duplicate values, subsequent values overwrite
|
* If `object` contains duplicate values, subsequent values overwrite
|
||||||
@@ -18,7 +16,7 @@ import baseForOwn from './.internal/baseForOwn.js'
|
|||||||
*/
|
*/
|
||||||
function invert(object) {
|
function invert(object) {
|
||||||
const result = {}
|
const result = {}
|
||||||
baseForOwn(object, (value, key) => {
|
Object.keys(object).forEach((value, key) => {
|
||||||
result[value] = key
|
result[value] = key
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import baseForOwn from './.internal/baseForOwn.js'
|
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
/** Used to check objects for own properties. */
|
||||||
const hasOwnProperty = Object.prototype.hasOwnProperty
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||||
|
|
||||||
@@ -24,8 +22,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
|
|||||||
*/
|
*/
|
||||||
function invertBy(object, iteratee) {
|
function invertBy(object, iteratee) {
|
||||||
const result = {}
|
const result = {}
|
||||||
baseForOwn(object, (value, key) => {
|
Object.keys(object).forEach((value, key) => {
|
||||||
|
|
||||||
value = iteratee(value)
|
value = iteratee(value)
|
||||||
if (hasOwnProperty.call(result, value)) {
|
if (hasOwnProperty.call(result, value)) {
|
||||||
result[value].push(key)
|
result[value].push(key)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseAssignValue from './.internal/baseAssignValue.js'
|
import baseAssignValue from './.internal/baseAssignValue.js'
|
||||||
import baseForOwn from './.internal/baseForOwn.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The opposite of `mapValues` this method creates an object with the
|
* 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) {
|
function mapKeys(object, iteratee) {
|
||||||
const result = {}
|
const result = {}
|
||||||
baseForOwn(object, (value, key, object) => {
|
Object.keys(object).forEach((value, key, object) => {
|
||||||
baseAssignValue(result, iteratee(value, key, object), value)
|
baseAssignValue(result, iteratee(value, key, object), value)
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseAssignValue from './.internal/baseAssignValue.js'
|
import baseAssignValue from './.internal/baseAssignValue.js'
|
||||||
import baseForOwn from './.internal/baseForOwn.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an object with the same keys as `object` and values generated
|
* 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) {
|
function mapValues(object, iteratee) {
|
||||||
const result = {}
|
const result = {}
|
||||||
baseForOwn(object, (value, key, object) => {
|
Object.keys(object).forEach((value, key, object) => {
|
||||||
baseAssignValue(result, key, iteratee(value, key, object))
|
baseAssignValue(result, key, iteratee(value, key, object))
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user