refactor(web): move util js functions into a separate file

This commit is contained in:
2025-01-07 15:15:04 +03:00
parent eeb4b52192
commit 3bfc54e407
5 changed files with 46 additions and 47 deletions
+42
View File
@@ -0,0 +1,42 @@
function datetimeToLocalISO(datetime) {
var options = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
timeZoneName: "longOffset",
};
var formatter = new Intl.DateTimeFormat("sv-SE", options);
var date = new Date(datetime);
return formatter
.formatToParts(date)
.map(({ type, value }) => {
if (type === "timeZoneName") {
return value.slice(3);
} else {
return value;
}
})
.join("")
.replace(" ", "T")
.replace(" ", "");
}
function escapedString(str) {
return str
.replace("&", "&")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\n", "<br>");
}
function formToJSON(form) {
formdata = form.serializeArray();
data = {};
$(formdata).each(function (index, obj) {
data[obj.name] = obj.value;
});
return data;
}