Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / shimKeys.js
1 var isArguments = require('../lang/isArguments'),
2     isArray = require('../lang/isArray'),
3     isIndex = require('./isIndex'),
4     isLength = require('./isLength'),
5     keysIn = require('../object/keysIn');
6
7 /** Used for native method references. */
8 var objectProto = Object.prototype;
9
10 /** Used to check objects for own properties. */
11 var hasOwnProperty = objectProto.hasOwnProperty;
12
13 /**
14  * A fallback implementation of `Object.keys` which creates an array of the
15  * own enumerable property names of `object`.
16  *
17  * @private
18  * @param {Object} object The object to query.
19  * @returns {Array} Returns the array of property names.
20  */
21 function shimKeys(object) {
22   var props = keysIn(object),
23       propsLength = props.length,
24       length = propsLength && object.length;
25
26   var allowIndexes = !!length && isLength(length) &&
27     (isArray(object) || isArguments(object));
28
29   var index = -1,
30       result = [];
31
32   while (++index < propsLength) {
33     var key = props[index];
34     if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
35       result.push(key);
36     }
37   }
38   return result;
39 }
40
41 module.exports = shimKeys;