{"version":3,"file":"useHelper.36d1353a.js","sources":["../../../../composables/useHelper.ts"],"sourcesContent":["import { useDisplay } from \"vuetify/lib/framework.mjs\";\nexport const useHelper = () => {\n /**\n * Secure the string to avoid injecting HTML and replace carriage return by a
tag.\n * @param str The string to secure\n * @returns The secured string.\n */\n const secureStringAndReplaceNewLineToBr = function (str: string) {\n return str\n ? str\n .replace(\"<\", \"<\")\n .replace(\">\", \">\")\n .replace(/(?:\\r\\n|\\r|\\n)/g, \"
\")\n : \"\";\n };\n\n /**\n * Get the default Vuetify field density according to screen width\n * @returns\n */\n const defaultFieldDensity = function ():\n | null\n | \"default\"\n | \"comfortable\"\n | \"compact\" {\n // input field are smaller on mobile\n\n return useDisplay()?.smAndDown?.value ? \"compact\" : \"default\";\n };\n\n /**\n * Get the default Vuetify button size according to screen width\n * @returns\n */\n const defaultButtonSize = function (): string | number {\n // buttons are bigger on mobile\n return useDisplay()?.smAndDown?.value ? \"large\" : \"default\";\n };\n\n /**\n * Convert a Date to the fr-CH format\n * @param date - The date to convert\n * @returns The formatted date or an empty string if the Date is not valid\n * @example 15.01.2023\n */\n const convertDateToString = function (\n date: Date,\n displayTime: boolean = false\n ): string {\n if (!checkDateIsValid(date)) return \"\";\n\n const format = displayTime ? \"DD.MM.YYYY HH:mm\" : \"DD.MM.YYYY\";\n\n return useDateFormat(date, format).value;\n };\n\n /**\n * Convert a Date to a technical string format for Date type inputs\n * @param date - The date to convert\n * @returns The formatted date or an empty string if the Date is not valid\n * @example 2023-01-15\n */\n const convertDateToTechnicalString = function (date: Date): string {\n if (!checkDateIsValid(date)) return \"\";\n\n return useDateFormat(date, \"YYYY-MM-DD\").value;\n };\n\n /**\n * Check if the object in parameter is a valid Javascript Date\n * @param date\n * @returns\n */\n const checkDateIsValid = function (date: Date) {\n if (Object.prototype.toString.call(date) === \"[object Date]\") {\n if (isNaN(date.getTime())) {\n return false;\n } else {\n return true;\n }\n } else {\n return false;\n }\n };\n\n const checkDateStringIsValid = function (\n date: string,\n minValue = new Date(\"1900-01-01\"),\n maxValue = new Date(\"2999-12-31\")\n ) {\n const d = new Date(date);\n if (!checkDateIsValid(d)) return false;\n\n if (minValue <= d && d <= maxValue) return true;\n\n return false;\n };\n\n /**\n * Download a file from the browser and open or download it.\n * @param file The file in Blob object\n * @param filename The name of the file to save\n * @param openFileInBrowser true if open the file in a new tab rather than downloading it\n */\n const downloadFile = function (\n file: Blob,\n filename: string,\n openFileInBrowser: boolean\n ) {\n // IE10+\n if (navigator.msSaveBlob) {\n navigator.msSaveBlob(new Blob([data], { type: fileType }), fileName);\n return;\n }\n\n var isIos =\n window.navigator && // /Macintosh/.test(navigator.userAgent) ||\n (/iPhone/.test(navigator.userAgent) || /iPad/.test(navigator.userAgent));\n\n var isChromeIOS = /CriOS\\/[\\d]+/.test(navigator.userAgent);\n\n const link = document.createElement(\"a\");\n document.body.appendChild(link);\n const URL = window.URL || window.webkitURL;\n link.href = URL.createObjectURL(file);\n link.setAttribute(\"target\", \"_blank\");\n // Download file rather than opening it in the browser\n // Force download on Safari mobile because opening in new tab doesn't work\n if (!openFileInBrowser || (isIos && !isChromeIOS)) {\n link.download = filename;\n }\n link.click();\n setTimeout(() => {\n URL.revokeObjectURL(link.href);\n document.body.removeChild(link);\n }, 1000);\n };\n\n /**\n * Vuetify validation rule to allow only valid chars.\n * @param input The input string to validate\n * @param errorMessage The error message to display if invalid\n * @returns\n */\n const ruleValidationOnlyChars = function (\n input: string,\n errorMessage: string\n ): string | boolean {\n if (!input) return true;\n const result = input.match(\n /[0-9A-Za-z-.,/\\\\^'ยจ~& \\u00C0-\\u00D6\\u00D8-\\u00f6\\u00f8-\\u00ff]+/g\n );\n return (result && result.length > 0 && result[0] === input) || errorMessage;\n };\n\n const ruleValidationEmail = function (input: string): boolean {\n return /^(([^<>()[\\]\\\\.,;:\\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,}))$/.test(\n input\n );\n };\n\n const ruleValidationPhoneNumber = function (input: string): boolean {\n return /[+][0-9]{8,20}$/g.test(input);\n };\n\n const isValidGUID = function (value?: string): boolean {\n if (!value) return false;\n\n return /^(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}(\\}){0,1}$/.test(\n value\n );\n };\n\n return {\n secureStringAndReplaceNewLineToBr,\n defaultFieldDensity,\n defaultButtonSize,\n convertDateToString,\n convertDateToTechnicalString,\n checkDateIsValid,\n checkDateStringIsValid,\n downloadFile,\n ruleValidationOnlyChars,\n ruleValidationEmail,\n ruleValidationPhoneNumber,\n isValidGUID,\n };\n};\n"],"names":["useHelper","secureStringAndReplaceNewLineToBr","str","defaultFieldDensity","_b","_a","useDisplay","defaultButtonSize","convertDateToString","date","displayTime","checkDateIsValid","useDateFormat","convertDateToTechnicalString","minValue","maxValue","d","file","filename","openFileInBrowser","isIos","isChromeIOS","link","URL","input","errorMessage","result","value"],"mappings":"iDACO,MAAAA,EAAA,IAAA,CAML,MAAAC,EAAA,SAAAC,EAAA,CACE,OAAAA,EAAAA,EAAA,QAAA,IAAA,MAAA,EAAA,QAAA,IAAA,MAAA,EAAA,QAAA,kBAAA,QAAA,EAAA,EAKI,EAONC,EAAA,UAAA,SAOE,OAAAC,GAAAC,EAAAC,EAAA,IAAA,YAAAD,EAAA,YAAA,MAAAD,EAAA,MAAA,UAAA,SAAoD,EAOtDG,EAAA,UAAA,SAEE,OAAAH,GAAAC,EAAAC,EAAA,IAAA,YAAAD,EAAA,YAAA,MAAAD,EAAA,MAAA,QAAA,SAAkD,EASpDI,EAAA,SAAAC,EAAAC,EAAA,GAAA,CAIE,OAAAC,EAAAF,CAAA,EAIAG,EAAAH,EAFAC,EAAA,mBAAA,YAEA,EAAA,MAJ6B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