UNPKG

for-each-safe

Version:

Recursively loop through the elements of a 'collection' (an array, an array-like object, or a plain object) and invoke 'callbackFn' for each element while protected against circular references.

32 lines (29 loc) 1.03 kB
const isPrototype = require('./isPrototype') /** * Creates an array of the own enumerable property names of `object`. * * **Note:** Non-object values are coerced to objects. See the * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) * for more details. * * This method was extracted from the lodash library where is was a private * method. * * Reference: * [baseKeys](https://github.com/lodash/lodash/blob/165572022d58d3e39e928b33ff9b9589cc60b67b/lodash.js#L3486-L3504) * [nativeKeys](https://github.com/lodash/lodash/blob/165572022d58d3e39e928b33ff9b9589cc60b67b/lodash.js#L1516) * [overArg](https://github.com/lodash/lodash/blob/165572022d58d3e39e928b33ff9b9589cc60b67b/lodash.js#L1209-L1221) */ function baseKeys(object) { if (!isPrototype(object)) { return Object.keys(Object(object)) } var result = [] for (var key in Object(object)) { if (object.hasOwnProperty(key) && key !== 'constructor') { result.push(key) } } return result } module.exports = baseKeys