mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 04:38:28 +00:00
utils: modernize hex functions
Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -513,26 +513,19 @@ function parseQueryString() {
|
|||||||
return Object.fromEntries(params.entries());
|
return Object.fromEntries(params.entries());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/q/21647928
|
function hexEncode(text) {
|
||||||
function hexEncode(string) {
|
if (typeof text !== "string" || text.length === 0) return "";
|
||||||
let result = "";
|
|
||||||
for (let i = 0; i < string.length; i++) {
|
|
||||||
const hex = string.codePointAt(i).toString(16);
|
|
||||||
result += ("000" + hex).slice(-4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return [...text].map(char => char.codePointAt(0).toString(16).padStart(4, "0")).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/q/21647928
|
function hexDecode(text) {
|
||||||
function hexDecode(string) {
|
if (typeof text !== "string" || text.length === 0) return "";
|
||||||
const hexes = string.match(/.{1,4}/g) || [];
|
|
||||||
let back = "";
|
|
||||||
for (const hex of hexes) {
|
|
||||||
back += String.fromCodePoint(Number.parseInt(hex, 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
return back;
|
const hexes = text.match(/.{1,4}/g);
|
||||||
|
if (!hexes || hexes.length === 0) return "";
|
||||||
|
|
||||||
|
return hexes.map(hex => String.fromCodePoint(Number.parseInt(hex, 16))).join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function listsAlert(type, items, data) {
|
function listsAlert(type, items, data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user