object-to-array.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var DESCRIPTORS = require('../internals/descriptors');
  2. var uncurryThis = require('../internals/function-uncurry-this');
  3. var objectKeys = require('../internals/object-keys');
  4. var toIndexedObject = require('../internals/to-indexed-object');
  5. var $propertyIsEnumerable = require('../internals/object-property-is-enumerable').f;
  6. var propertyIsEnumerable = uncurryThis($propertyIsEnumerable);
  7. var push = uncurryThis([].push);
  8. // `Object.{ entries, values }` methods implementation
  9. var createMethod = function (TO_ENTRIES) {
  10. return function (it) {
  11. var O = toIndexedObject(it);
  12. var keys = objectKeys(O);
  13. var length = keys.length;
  14. var i = 0;
  15. var result = [];
  16. var key;
  17. while (length > i) {
  18. key = keys[i++];
  19. if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
  20. push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
  21. }
  22. }
  23. return result;
  24. };
  25. };
  26. module.exports = {
  27. // `Object.entries` method
  28. // https://tc39.es/ecma262/#sec-object.entries
  29. entries: createMethod(true),
  30. // `Object.values` method
  31. // https://tc39.es/ecma262/#sec-object.values
  32. values: createMethod(false)
  33. };