⬇CSV Import work #808
Some checks are pending
docker / docker_dev (push) Waiting to run

This commit is contained in:
jokob-sk
2024-09-30 10:30:09 +10:00
parent e5d835cfa9
commit 044de61ab5
6 changed files with 45 additions and 12 deletions

View File

@@ -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