mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
This commit is contained in:
@@ -342,6 +342,8 @@ function getLangCode() {
|
||||
// -----------------------------------------------------------------------------
|
||||
// String utilities
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------
|
||||
function jsonSyntaxHighlight(json) {
|
||||
if (typeof json != 'string') {
|
||||
json = JSON.stringify(json, undefined, 2);
|
||||
@@ -364,6 +366,7 @@ function jsonSyntaxHighlight(json) {
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
function isValidBase64(str) {
|
||||
// Base64 characters set
|
||||
var base64CharacterSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
@@ -373,7 +376,7 @@ function isValidBase64(str) {
|
||||
return invalidCharacters === '';
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
function isValidJSON(jsonString) {
|
||||
try {
|
||||
JSON.parse(jsonString);
|
||||
@@ -383,6 +386,7 @@ function isValidJSON(jsonString) {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// method to sanitize input so that HTML and other things don't break
|
||||
function encodeSpecialChars(str) {
|
||||
return str
|
||||
@@ -392,7 +396,7 @@ function encodeSpecialChars(str) {
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
function decodeSpecialChars(str) {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
@@ -402,6 +406,16 @@ function decodeSpecialChars(str) {
|
||||
.replace(/'/g, '\'');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// base64 conversion of UTF8 chars
|
||||
function utf8ToBase64(str) {
|
||||
// Convert the string to a Uint8Array using TextEncoder
|
||||
const utf8Bytes = new TextEncoder().encode(str);
|
||||
|
||||
// Convert the Uint8Array to a base64-encoded string
|
||||
return btoa(String.fromCharCode(...utf8Bytes));
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// General utilities
|
||||
|
||||
Reference in New Issue
Block a user