blink/frontend/vanilla/js/utils.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-02-28 15:51:21 +01:00
function getCookie(name) {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
const [cookieName, cookieValue] = cookie.split('=');
if (cookieName === name) {
return decodeURIComponent(cookieValue);
}
}
return null;
2024-03-14 15:45:10 +01:00
}
2024-03-25 10:07:54 +01:00
/**
* Validates an e-mail using a RegExpression
*
* @param {*} email
2024-03-25 12:01:59 +01:00
* @returns true or false
2024-03-25 10:07:54 +01:00
*/
function validateEmail(email) {
return String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
}
2024-03-14 15:45:10 +01:00
function callbackErrors(errors, func) {
errors.forEach(error => func(error.msg));
2024-03-21 17:34:16 +01:00
}
function createHeaders(token) {
return {
"Content-type": "application/json; charset=UTF-8",
"Authorization": `Bearer ${token}`
}
2024-03-25 10:07:54 +01:00
}
function clearInputFields() {
var inputs = document.querySelectorAll('input');
inputs.forEach(function(input) {
input.value = '';
});
2024-02-28 15:51:21 +01:00
}