templateUtils.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseUrl = exports.isDataUrl = exports.isExternalUrl = exports.isRelativeUrl = void 0;
  4. const url_1 = require("url");
  5. const shared_1 = require("@vue/shared");
  6. function isRelativeUrl(url) {
  7. const firstChar = url.charAt(0);
  8. return firstChar === '.' || firstChar === '~' || firstChar === '@';
  9. }
  10. exports.isRelativeUrl = isRelativeUrl;
  11. const externalRE = /^(https?:)?\/\//;
  12. function isExternalUrl(url) {
  13. return externalRE.test(url);
  14. }
  15. exports.isExternalUrl = isExternalUrl;
  16. const dataUrlRE = /^\s*data:/i;
  17. function isDataUrl(url) {
  18. return dataUrlRE.test(url);
  19. }
  20. exports.isDataUrl = isDataUrl;
  21. /**
  22. * Parses string url into URL object.
  23. */
  24. function parseUrl(url) {
  25. const firstChar = url.charAt(0);
  26. if (firstChar === '~') {
  27. const secondChar = url.charAt(1);
  28. url = url.slice(secondChar === '/' ? 2 : 1);
  29. }
  30. return parseUriParts(url);
  31. }
  32. exports.parseUrl = parseUrl;
  33. /**
  34. * vuejs/component-compiler-utils#22 Support uri fragment in transformed require
  35. * @param urlString an url as a string
  36. */
  37. function parseUriParts(urlString) {
  38. // A TypeError is thrown if urlString is not a string
  39. // @see https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost
  40. return (0, url_1.parse)((0, shared_1.isString)(urlString) ? urlString : '', false, true);
  41. }