UNPKG

@drieam/common

Version:

Default Drieam api wrapper

55 lines (45 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.debug = void 0; function bytesToSize(bytes) { var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; if (bytes === 0) return "0 Byte"; var i = Math.floor(Math.log(bytes) / Math.log(1024)); return "".concat(Math.round(bytes / Math.pow(1024, i)), " ").concat(sizes[i]); } function parseData(data) { var re = /!\*{3}\s(.*)?\s\*{3}!/g; var m = null; var sb = []; // eslint-disable-next-line no-cond-assign while (m = re.exec(data)) { sb.push(m[1]); } return sb.join("<br />"); } var onSuccess = function onSuccess(url) { return function (data) { document.body.insertAdjacentHTML("beforeend", "<div>\n <h3>".concat(url, "</h3>\n <h4>").concat(bytesToSize(new Blob([data]).size), "</h4>\n <code>\n ").concat(parseData(data), "\n </code>\n</div>")); }; }; function visualizeDependencies() { var collection = document.getElementsByTagName("script"); var urls = []; for (var i = 0; i < collection.length; i += 1) { urls.push(collection[i].getAttribute("src")); } urls.forEach(function (url) { fetch(url, { headers: { "Content-Type": " text/plain" } }).then(function (response) { return response.text(); }).then(onSuccess(url)); }); } var debug = { visualizeDependencies: visualizeDependencies }; exports.debug = debug;