toPairs.js 904 B

123456789101112131415161718192021222324252627282930313233343536
  1. import _curry1 from "./internal/_curry1.js";
  2. import _has from "./internal/_has.js";
  3. /**
  4. * Converts an object into an array of key, value arrays. Only the object's
  5. * own properties are used.
  6. * Note that the order of the output array is not guaranteed to be consistent
  7. * across different JS platforms.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.4.0
  12. * @category Object
  13. * @sig {String: *} -> [[String,*]]
  14. * @param {Object} obj The object to extract from
  15. * @return {Array} An array of key, value arrays from the object's own properties.
  16. * @see R.fromPairs, R.keys, R.values
  17. * @example
  18. *
  19. * R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]]
  20. */
  21. var toPairs =
  22. /*#__PURE__*/
  23. _curry1(function toPairs(obj) {
  24. var pairs = [];
  25. for (var prop in obj) {
  26. if (_has(prop, obj)) {
  27. pairs[pairs.length] = [prop, obj[prop]];
  28. }
  29. }
  30. return pairs;
  31. });
  32. export default toPairs;