refactoring + some tools

This commit is contained in:
Maxim Devaev
2024-09-22 05:20:01 +03:00
parent 842ddc91a1
commit 1217144ecd
6 changed files with 135 additions and 88 deletions

View File

@@ -64,6 +64,17 @@ export var tools = new function() {
/************************************************************************/
self.escape = function(text) {
return text.replace(
/[^0-9A-Za-z ]/g,
ch => "&#" + ch.charCodeAt(0) + ";"
);
};
self.makeClosure = function(func, ...args) {
return () => func(...args);
};
self.upperFirst = function(text) {
return text[0].toUpperCase() + text.slice(1);
};
@@ -87,6 +98,10 @@ export var tools = new function() {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
self.formatHex = function(value) {
return `0x${value.toString(16).toUpperCase()}`;
};
self.formatSize = function(size) {
if (size > 0) {
let index = Math.floor( Math.log(size) / Math.log(1024) );
@@ -283,9 +298,9 @@ export var tools = new function() {
option.className = "comment";
el.add(option);
},
"addSeparator": function(el) {
"addSeparator": function(el, repeat=30) {
if (!self.browser.is_mobile) {
self.selector.addComment(el, "\u2500".repeat(30));
self.selector.addComment(el, "\u2500".repeat(repeat));
}
},