Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

_arrayLikeKeys.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var baseTimes = require('./_baseTimes'),
  2. isArguments = require('./isArguments'),
  3. isArray = require('./isArray'),
  4. isBuffer = require('./isBuffer'),
  5. isIndex = require('./_isIndex'),
  6. isTypedArray = require('./isTypedArray');
  7. /** Used for built-in method references. */
  8. var objectProto = Object.prototype;
  9. /** Used to check objects for own properties. */
  10. var hasOwnProperty = objectProto.hasOwnProperty;
  11. /**
  12. * Creates an array of the enumerable property names of the array-like `value`.
  13. *
  14. * @private
  15. * @param {*} value The value to query.
  16. * @param {boolean} inherited Specify returning inherited property names.
  17. * @returns {Array} Returns the array of property names.
  18. */
  19. function arrayLikeKeys(value, inherited) {
  20. var isArr = isArray(value),
  21. isArg = !isArr && isArguments(value),
  22. isBuff = !isArr && !isArg && isBuffer(value),
  23. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  24. skipIndexes = isArr || isArg || isBuff || isType,
  25. result = skipIndexes ? baseTimes(value.length, String) : [],
  26. length = result.length;
  27. for (var key in value) {
  28. if ((inherited || hasOwnProperty.call(value, key)) &&
  29. !(skipIndexes && (
  30. // Safari 9 has enumerable `arguments.length` in strict mode.
  31. key == 'length' ||
  32. // Node.js 0.10 has enumerable non-index properties on buffers.
  33. (isBuff && (key == 'offset' || key == 'parent')) ||
  34. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  35. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  36. // Skip index properties.
  37. isIndex(key, length)
  38. ))) {
  39. result.push(key);
  40. }
  41. }
  42. return result;
  43. }
  44. module.exports = arrayLikeKeys;