export const parseClassName = (classNames) => { // Ajoute des espaces quand plusieurs classes return classNames.join(" "); }; export const isEmpty = (value) => { return ( value === undefined || value === null || (typeof value === "object" && Object.keys(value).length === 0) || (typeof value === "string" && value.trim().length === 0) ); }; export const parseTimer = (s) => { var min = parseInt(s / 60) var sec = s - (min * 60) sec = (String(sec).length == 1 ? '0': '') + sec min = (String(min).length == 1 ? '0': '') + min return `${min} : ${sec}` } export const colors = { primary: "#FCBF49", secondary: "#DF2935", red: "rgb(255, 79, 100)", }; function getCookie(name) { if (process.browser) { let cookieValue = null; if (document.cookie && document.cookie !== "") { const cookies = document.cookie.split(";"); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) === name + "=") { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } } export const csrftoken = getCookie("csrftoken"); export const color = [ // "blanc", "marron", "violet", "jaune", "orange", "bleu", "vert", "noir", "rouge", "rose", ]; export const colorCode = { //blanc: "rgb(255,255,255)", bleu: "rgb(51,123,255)", vert: "rgb(0,204,0)", rouge: "rgb(255,0,0)", marron: "rgb(153,76,0)", violet: "rgb(204,0,204)", jaune: "rgb(255,255,0)", orange: "rgb(255,128,0)", noir: "rgb(10,10,10)", rose: "rgb(255,102,255)", blanc: "rgb(240,240,240)", blanche: "rgb(240,240,240)", }; export const csvExtParse = (name) => { var nameSplited = name.split("."); if (nameSplited.length - 1 != 0) { var ext = nameSplited[nameSplited.length - 1] if (ext == 'csv') { return name } else return nameSplited.slice(0, nameSplited.length - 1).join('.') + '.csv' } else return name + '.csv' } export const filterInAnotherArray = (arr1, arr2) => { const filtered = arr1.filter((el) => { return arr2.indexOf(el) !== -1; }); return filtered; }; export const filterNotInAnotherArray = (arr1, arr2) => { const filtered = arr1.filter((el) => { return arr2.indexOf(el) === -1; }); return filtered; }; export function countOccurences(tab, value) { var result = 0; tab.forEach(function (elem) { if (elem == value) { result++; } }); return result; } export const isBrowser = typeof window !== "undefined"; export const parseDate = (date) => { return `${ (String(date.getDate()).length == 1 ? "0" : "") + date.getDate() }/${ (String(date.getMonth()).length == 1 ? "0" : "") + date.getMonth() }/${date.getFullYear()} à ${ (String(date.getHours()).length == 1 ? "0" : "") + date.getHours() }:${ (String(date.getMinutes()).length == 1 ? "0" : "") + date.getMinutes() }` }