utils.js 1003 B

123456789101112131415161718192021222324
  1. export function extractId(href) {
  2. return href.replace(/^[a-z-]+:\/+?[^\/]+/, '') // Remove protocol & domain
  3. .replace(/[\?\&]livereload=\w+/, '') // Remove LiveReload cachebuster
  4. .replace(/^\//, '') // Remove root /
  5. .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
  6. .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
  7. .replace(/\./g, ':'); // Replace dots with colons(for valid id)
  8. }
  9. export function addDataAttr(options, tag) {
  10. for (const opt in tag.dataset) {
  11. if (tag.dataset.hasOwnProperty(opt)) {
  12. if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
  13. options[opt] = tag.dataset[opt];
  14. } else {
  15. try {
  16. options[opt] = JSON.parse(tag.dataset[opt]);
  17. }
  18. catch (_) {}
  19. }
  20. }
  21. }
  22. }