wishthis/node_modules/less/lib/less-browser/utils.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addDataAttr = exports.extractId = void 0;
function extractId(href) {
2023-08-17 09:47:40 +00:00
return href.replace(/^[a-z-]+:\/+?[^/]+/, '') // Remove protocol & domain
.replace(/[?&]livereload=\w+/, '') // Remove LiveReload cachebuster
2022-01-21 08:28:41 +00:00
.replace(/^\//, '') // Remove root /
.replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
2023-08-17 09:47:40 +00:00
.replace(/[^.\w-]+/g, '-') // Replace illegal characters
2022-01-21 08:28:41 +00:00
.replace(/\./g, ':'); // Replace dots with colons(for valid id)
}
exports.extractId = extractId;
function addDataAttr(options, tag) {
2022-06-16 11:46:53 +00:00
if (!tag) {
return;
} // in case of tag is null or undefined
2022-01-21 08:28:41 +00:00
for (var opt in tag.dataset) {
2023-08-17 09:47:40 +00:00
if (Object.prototype.hasOwnProperty.call(tag.dataset, opt)) {
2022-01-21 08:28:41 +00:00
if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
options[opt] = tag.dataset[opt];
}
else {
try {
options[opt] = JSON.parse(tag.dataset[opt]);
}
catch (_) { }
}
}
}
}
exports.addDataAttr = addDataAttr;
//# sourceMappingURL=utils.js.map