parse-path.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { each, isArray, isString } from 'lodash-es';
  2. var regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/gi;
  3. var regexDot = /[^\s\,]+/gi;
  4. function parsePath(p) {
  5. var path = p || [];
  6. if (isArray(path)) {
  7. return path;
  8. }
  9. if (isString(path)) {
  10. path = path.match(regexTags);
  11. each(path, function (item, index) {
  12. // @ts-ignore
  13. item = item.match(regexDot);
  14. if (item[0].length > 1) {
  15. var tag = item[0].charAt(0);
  16. // @ts-ignore
  17. item.splice(1, 0, item[0].substr(1));
  18. // @ts-ignore
  19. item[0] = tag;
  20. }
  21. // @ts-ignore
  22. each(item, function (sub, i) {
  23. // @ts-ignore
  24. if (!isNaN(sub)) {
  25. // @ts-ignore
  26. item[i] = +sub;
  27. }
  28. });
  29. // @ts-ignore
  30. path[index] = item;
  31. });
  32. return path;
  33. }
  34. }
  35. export default parsePath;
  36. //# sourceMappingURL=parse-path.js.map