Path.js 535 B

123456789101112131415161718192021222324252627282930313233
  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) {
  11. return {
  12. prev: prev,
  13. key: key
  14. };
  15. }
  16. /**
  17. * Given a Path, return an Array of the path keys.
  18. */
  19. function pathToArray(path) {
  20. var flattened = [];
  21. var curr = path;
  22. while (curr) {
  23. flattened.push(curr.key);
  24. curr = curr.prev;
  25. }
  26. return flattened.reverse();
  27. }