diff options
Diffstat (limited to 'web/share/js/tools.js')
-rw-r--r-- | web/share/js/tools.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/web/share/js/tools.js b/web/share/js/tools.js index fbf712de..48f5b420 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -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)); } }, |