utils.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.addDataAttr = exports.extractId = void 0;
  4. function extractId(href) {
  5. return href.replace(/^[a-z-]+:\/+?[^/]+/, '') // Remove protocol & domain
  6. .replace(/[?&]livereload=\w+/, '') // Remove LiveReload cachebuster
  7. .replace(/^\//, '') // Remove root /
  8. .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
  9. .replace(/[^.\w-]+/g, '-') // Replace illegal characters
  10. .replace(/\./g, ':'); // Replace dots with colons(for valid id)
  11. }
  12. exports.extractId = extractId;
  13. function addDataAttr(options, tag) {
  14. if (!tag) {
  15. return;
  16. } // in case of tag is null or undefined
  17. for (var opt in tag.dataset) {
  18. if (Object.prototype.hasOwnProperty.call(tag.dataset, opt)) {
  19. if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
  20. options[opt] = tag.dataset[opt];
  21. }
  22. else {
  23. try {
  24. options[opt] = JSON.parse(tag.dataset[opt]);
  25. }
  26. catch (_) { }
  27. }
  28. }
  29. }
  30. }
  31. exports.addDataAttr = addDataAttr;
  32. //# sourceMappingURL=utils.js.map