{"version":3,"file":"formatting.service-Bns6oBNM.js","sources":["../../../../SPAs/POCViteVue/src/services/formatting.service.ts"],"sourcesContent":["export const getPriceFormatter = (currency: string) => {\r\n return new Intl.NumberFormat(document.documentElement.lang, {\r\n style: \"currency\",\r\n currency: currency,\r\n\r\n });\r\n }\r\n\r\nexport const formatPrice = (value: number, currency: string, maximumFractionDigits = 0) => {\r\n if (value == -1) return \"\";\r\n const formatter = new Intl.NumberFormat(document.documentElement.lang, {\r\n style: \"currency\",\r\n currency: currency,\r\n maximumFractionDigits: maximumFractionDigits\r\n });\r\n return formatter.format(value);\r\n}\r\n\r\n\r\nexport const formatPriceEmptyIfUndefined = (value: number | undefined, currency: string | undefined,\r\n maximumFractionDigits = 0, minimumFractionDigits: number | undefined = undefined) => {\r\n if (value == -1 || value == undefined || currency == undefined) return \"\";\r\n const formatter = new Intl.NumberFormat(document.documentElement.lang, {\r\n style: \"currency\",\r\n currency: currency,\r\n maximumFractionDigits: maximumFractionDigits,\r\n minimumFractionDigits: minimumFractionDigits\r\n });\r\n return formatter.format(value);\r\n}\r\n\r\nexport const formatPriceRange = (from: number, to: number, currency: string, maximumFractionDigits = 0) => {\r\n if (from == -1 || to == -1) return \"\";\r\n const formatter = new Intl.NumberFormat(document.documentElement.lang, {\r\n style: \"currency\",\r\n currency: currency,\r\n maximumFractionDigits: maximumFractionDigits\r\n });\r\n //@ts-ignore\r\n return formatter.formatRange(from, to);\r\n}\r\n\r\nexport const formatPriceRangeEmptyIfUndefined = (from: number | undefined, to: number | undefined, currency: string | undefined, maximumFractionDigits = 0) => {\r\n if (from == -1 || to == -1 || from == undefined || to == undefined || currency == undefined) return \"\";\r\n const formatter = new Intl.NumberFormat(document.documentElement.lang, {\r\n style: \"currency\",\r\n currency: currency,\r\n maximumFractionDigits: maximumFractionDigits\r\n });\r\n //@ts-ignore\r\n return formatter.formatRange(from, to);\r\n}\r\n\r\n\r\nexport const formatDate = (value: Date,\r\n dateStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = \"medium\",\r\n timeStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = undefined) => {\r\n const formatter = new Intl.DateTimeFormat(document.documentElement.lang, {\r\n dateStyle: dateStyle,\r\n timeStyle: timeStyle,\r\n });\r\n return formatter.format(value);\r\n}\r\n\r\nexport const formatDateRange = (fromDate: Date | undefined, toDate: Date | undefined,\r\n dateStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = \"medium\",\r\n timeStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = undefined) => {\r\n \r\n if (fromDate == undefined || toDate == undefined) return \"\";\r\n \r\n const formatter = new Intl.DateTimeFormat(document.documentElement.lang, {\r\n dateStyle: dateStyle,\r\n timeStyle: timeStyle,\r\n });\r\n //@ts-ignore\r\n return formatter.formatRange(fromDate, toDate);\r\n}\r\n\r\nexport const formatDateRangeOrYear = (fromDate: Date, toDate: Date,\r\n dateStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = \"medium\",\r\n timeStyle: \"short\" | \"full\" | \"long\" | \"medium\" | undefined = undefined) => {\r\n\r\n const year = getYearFromDateRange(fromDate, toDate);\r\n\r\n if (year != undefined) return year.toString();\r\n\r\n const formatter = new Intl.DateTimeFormat(document.documentElement.lang, {\r\n dateStyle: dateStyle,\r\n timeStyle: timeStyle,\r\n });\r\n //@ts-ignore\r\n return formatter.formatRange(fromDate, toDate);\r\n}\r\n\r\nconst getYearFromDateRange = (fromDate: Date, toDate: Date) => {\r\n const expectedYear = fromDate.getFullYear();\r\n const expectedRange = {\r\n from: new Date(expectedYear, 0, 1),\r\n to: new Date(expectedYear + 1, 0, 1)\r\n };\r\n if (fromDate.getTime() == expectedRange.from.getTime() &&\r\n toDate.getTime() == expectedRange.to.getTime()) {\r\n return expectedYear;\r\n }\r\n return undefined;\r\n}\r\n\r\nexport const getMonthName = (month: number, style: \"short\" | \"long\" | \"numeric\" | \"2-digit\" | \"narrow\" | undefined = \"long\") => {\r\n const formatter = new Intl.DateTimeFormat(document.documentElement.lang, {\r\n month: style\r\n });\r\n\r\n return formatter.format(new Date(2024, month))\r\n}\r\n\r\nexport const getMonthNameWithYear = (firstYear: number, month: number, style: \"short\" | \"long\" | \"numeric\" | \"2-digit\" | \"narrow\" | undefined = \"long\") => {\r\n return getMonthName(month % 12) + \" \" + (firstYear + Math.floor(month/12))\r\n}\r\n\r\nexport function capitalizeFirstLetter(string: string) {\r\n return string.charAt(0).toUpperCase() + string.slice(1);\r\n}\r\n\r\n\r\nexport const formatNumber = (number: number | undefined, formatOptions?: Intl.NumberFormatOptions) => {\r\n if (number == undefined) return \"\";\r\n const formatter = new Intl.NumberFormat(document.documentElement.lang, formatOptions);\r\n return formatter.format(number);\r\n}\r\n"],"names":["formatPrice","value","currency","maximumFractionDigits","formatPriceEmptyIfUndefined","minimumFractionDigits","formatPriceRange","from","to","formatPriceRangeEmptyIfUndefined","formatDate","dateStyle","timeStyle","formatDateRange","fromDate","toDate","formatNumber","number","formatOptions"],"mappings":"AAQO,MAAMA,EAAc,CAACC,EAAeC,EAAkBC,EAAwB,IAC7EF,GAAS,GAAW,GACN,IAAI,KAAK,aAAa,SAAS,gBAAgB,KAAM,CACnE,MAAO,WACP,SAAAC,EACA,sBAAAC,CAAA,CACH,EACgB,OAAOF,CAAK,EAIpBG,EAA8B,CAACH,EAA2BC,EACnEC,EAAwB,EAAGE,EAA4C,SACnEJ,GAAS,IAAMA,GAAS,MAAaC,GAAY,KAAkB,GACrD,IAAI,KAAK,aAAa,SAAS,gBAAgB,KAAM,CACnE,MAAO,WACP,SAAAA,EACA,sBAAAC,EACA,sBAAAE,CAAA,CACH,EACgB,OAAOJ,CAAK,EAGpBK,EAAmB,CAACC,EAAcC,EAAYN,EAAkBC,EAAwB,IAC7FI,GAAQ,IAAMC,GAAM,GAAW,GACjB,IAAI,KAAK,aAAa,SAAS,gBAAgB,KAAM,CACnE,MAAO,WACP,SAAAN,EACA,sBAAAC,CAAA,CACH,EAEgB,YAAYI,EAAMC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