mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Fix object coercion.
This commit is contained in:
@@ -11,11 +11,12 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
* @returns {Array} Returns the array of property names.
|
||||
*/
|
||||
function baseKeys(object) {
|
||||
object = Object(object)
|
||||
if (!isPrototype(object)) {
|
||||
return Object.keys(Object(object))
|
||||
return Object.keys(object)
|
||||
}
|
||||
const result = []
|
||||
for (const key in Object(object)) {
|
||||
for (const key in object) {
|
||||
if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
||||
result.push(key)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
* // => false
|
||||
*/
|
||||
function everyValue(object, predicate) {
|
||||
const props = Object.keys(Object(object))
|
||||
object = Object(object)
|
||||
const props = Object.keys(object)
|
||||
|
||||
for (const key of props) {
|
||||
if (!predicate(object[key], key, object)) {
|
||||
return false
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
* // => [5, 10]
|
||||
*/
|
||||
function filterObject(object, predicate) {
|
||||
object = Object(object)
|
||||
const result = []
|
||||
Object.keys(Object(object)).forEach((key) => {
|
||||
|
||||
Object.keys(object).forEach((key) => {
|
||||
const value = object[key]
|
||||
if (predicate(value, key, object)) {
|
||||
result.push(value)
|
||||
|
||||
@@ -24,9 +24,8 @@
|
||||
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
|
||||
*/
|
||||
function forOwn(object, iteratee) {
|
||||
if (object != null) {
|
||||
Object.keys(Object(object)).forEach((key) => iteratee(object[key], key, object))
|
||||
}
|
||||
object = Object(object)
|
||||
Object.keys(object).forEach((key) => iteratee(object[key], key, object))
|
||||
}
|
||||
|
||||
export default forOwn
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
* // => { 'a1': 1, 'b2': 2 }
|
||||
*/
|
||||
function mapKey(object, iteratee) {
|
||||
object = Object(object)
|
||||
const result = {}
|
||||
Object.keys(Object(object)).forEach((key) => {
|
||||
|
||||
Object.keys(object).forEach((key) => {
|
||||
const value = object[key]
|
||||
result[iteratee(value, key, object)] = value
|
||||
})
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||||
*/
|
||||
function mapValue(object, iteratee) {
|
||||
object = Object(object)
|
||||
const result = {}
|
||||
Object.keys(Object(object)).forEach((key) => {
|
||||
|
||||
Object.keys(object).forEach((key) => {
|
||||
result[key] = iteratee(object[key], key, object)
|
||||
})
|
||||
return result
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
* // => true
|
||||
*/
|
||||
function someValues(object, predicate) {
|
||||
const props = Object.keys(Object(object))
|
||||
object = Object(object)
|
||||
const props = Object.keys(object)
|
||||
|
||||
for (const key of props) {
|
||||
if (predicate(object[key], key, object)) {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user