Path.js 569 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.addPath = addPath;
  6. exports.pathToArray = pathToArray;
  7. /**
  8. * Given a Path and a key, return a new Path containing the new key.
  9. */
  10. function addPath(prev, key, typename) {
  11. return {
  12. prev: prev,
  13. key: key,
  14. typename: typename
  15. };
  16. }
  17. /**
  18. * Given a Path, return an Array of the path keys.
  19. */
  20. function pathToArray(path) {
  21. var flattened = [];
  22. var curr = path;
  23. while (curr) {
  24. flattened.push(curr.key);
  25. curr = curr.prev;
  26. }
  27. return flattened.reverse();
  28. }