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