import Vue from "vue"; /* eslint-disable no-useless-escape */ export const uniqueStringGenerator = () => { let result = ""; const now = new Date().getTime(); const characters = "abcdefghijklmnopqrstuvwxyz"; const charactersLength = now.toString(); for (let i = 0; i < 10; i++) { const c = characters.charAt( Math.floor(Math.random() * charactersLength.length) ); if (c && c !== undefined) { result += c; } } return result; }; // export const removeOwnSelfRelatedLocalStorage = () => { // if (localStorage) { // const title = settings.title.toLowerCase().replace(/[ ]/g, ""); // for (const a in localStorage) { // if (a.includes(title)) { // localStorage.removeItem(a); // } // } // } // }; // export const getDecryptedData = (id: any, body?: any) => { // const ls = localStorage.getItem(id); // if (ls) { // return decryption(ls); // } // return body || ""; // }; // export const encryption = (response: any, string = false) => { // try { // if (!response) { // return ""; // } // if (string === true) { // response = response.toString(); // } else { // response = JSON.stringify(response); // } // let encryptData = (Vue as any).CryptoJS.AES.encrypt( // response, // settings.secret // ).toString(); // encryptData = encryptData // .replace(/\+/g, "xMl3Jk") // .replace(/\//g, "Por21Ld") // .replace(/\=/g, "Ml32"); // return encryptData; // } catch (err) { // alert(err); // // this.endercyrptionError() // } // }; // export const decryption = (response: any, string = false) => { // try { // if (!response) { // return ""; // } // response = response // .replace(/\xMl3Jk/g, "+") // .replace(/\Por21Ld/g, "/") // .replace(/\Ml32/g, "="); // const bytes = (Vue as any).CryptoJS.AES.decrypt(response, settings.secret); // let decryptedData = bytes.toString((Vue as any).CryptoJS.enc.Utf8); // if (string !== true) { // decryptedData = JSON.parse(decryptedData); // } // return decryptedData; // } catch (err) { // alert(err); // // this.endercyrptionError() // } // }; export const toTitleCase = (str: string) => { return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase(); }); }; export const toFirstLowerCase = (str: string) => { return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toLowerCase() + txt.substring(1); }); }; export const toFirstUpperCase = (str: string) => { return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1); }); }; export const toSentenceCase = (str: string) => { if (str === str.toUpperCase()) { return str; } const result = str.replace(/([A-Z])/g, "$1"); return (result.charAt(0).toUpperCase() + result.slice(1)).trim(); }; export const toAcronym = (str: string) => { let matches: any = str.match(/\b(\w)/g); if (matches) { matches = matches.join(""); if (matches.length > 1) { matches = matches.charAt(0) + matches.slice(-1); } matches = matches.toUpperCase(); } return matches; }; export const camelize = (str: string) => { return str .replace(/(?:^\w|[A-Z]|\b\w)/g, (word: string, index: number) => { return index === 0 ? word.toLowerCase() : word.toUpperCase(); }) .replace(/\s+/g, ""); }; export const booleanConverter = ( value: any, type: "boolean" | "number" = "number" ) => { if (type === "number") { if (value === true) { return 1; } else { return 0; } } else { if (value === 0) { return true; } else { return false; } } }; export const isMobile = () => { const rect = document.body.getBoundingClientRect(); return rect.width - 1 < 992; }; export const convertText = (text: string) => { return text.replace(/\n/g, "
"); };