ngx-t-reports
Version:
Angular module for creating dynamic reports and dashboards. Supports various data sources, custom templates, and real-time updates.
1 lines • 5.83 kB
Source Map (JSON)
{"version":3,"file":"ngx-t-reports-format-Data.pipe-QDzIba5Q.mjs","sources":["../../../projects/ngx-t-reports/src/lib/pipes/format-Data.pipe.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\r\nimport { CurrencyPipe, DatePipe } from '@angular/common';\r\nimport { DocumentLitsLabelConfigInterfaceValueType, FormColumnInputs, InputDataTypes } from 'ngx-t-forms-types'; // Assuming this path is correct relative to your pipe file\r\n\r\n@Pipe({\r\n name: 'formatData',\r\n standalone: true, // For Angular 14+ standalone components/pipes. Remove if not applicable.\r\n})\r\nexport class FormatDataPipe implements PipeTransform {\r\n\r\n transform(\r\n value: any,\r\n dataType: DocumentLitsLabelConfigInterfaceValueType | InputDataTypes | undefined,\r\n pipeConfig?: FormColumnInputs['pipe'] | undefined\r\n ): any {\r\n try {\r\n switch (dataType) {\r\n case 'date':\r\n const datePipe = new DatePipe('en-US'); // You might want to inject this or make locale configurable\r\n return datePipe.transform(value, 'mediumDate');\r\n case 'currency':\r\n // The 'R' for ZAR is hardcoded here as per the original function.\r\n // Consider making the currency code and locale configurable if needed.\r\n const currencyPipeForCurrencyType = new CurrencyPipe('en-US', pipeConfig?.param || 'ZAR');\r\n const numberValueForCurrency = parseFloat(value);\r\n return currencyPipeForCurrencyType.transform(numberValueForCurrency, pipeConfig?.param);\r\n case 'number':\r\n if (pipeConfig?.pipeType === 'currency') {\r\n const currencyPipeForNumberType = new CurrencyPipe('en-US'); // Locale hardcoded\r\n const currencyCode = pipeConfig?.param;\r\n const numberValueForNumber = parseFloat(value);\r\n return currencyPipeForNumberType.transform(numberValueForNumber, currencyCode);\r\n } else {\r\n return value;\r\n }\r\n case 'daysAgo':\r\n if (value) {\r\n const seconds = Math.floor((+new Date() - +new Date(value)) / 1000);\r\n if (seconds < 15)\r\n // less than 30 seconds ago will show as 'Just now'\r\n return 'Just now';\r\n const intervals: any = {\r\n year: 31536000,\r\n month: 2592000,\r\n week: 604800,\r\n day: 86400,\r\n hr: 3600,\r\n min: 60,\r\n sec: 1,\r\n };\r\n let counter;\r\n for (const i in intervals) {\r\n counter = Math.floor(seconds / intervals[i]);\r\n if (counter > 0)\r\n if (counter === 1) {\r\n return counter + ' ' + i + ' ago'; // singular (1 day ago)\r\n } else {\r\n return counter + ' ' + i + 's ago'; // plural (2 days ago)\r\n }\r\n }\r\n }\r\n return value;\r\n default:\r\n return value;\r\n }\r\n } catch (error) {\r\n console.error('Error in FormatDataPipe:', error);\r\n return value; // Return original value in case of an error\r\n }\r\n }\r\n}"],"names":[],"mappings":";;;;MAQa,cAAc,CAAA;AAEvB,IAAA,SAAS,CACL,KAAU,EACV,QAAgF,EAChF,UAAiD,EAAA;AAEjD,QAAA,IAAI;YACA,QAAQ,QAAQ;AACZ,gBAAA,KAAK,MAAM;oBACP,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;oBACvC,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC;AAClD,gBAAA,KAAK,UAAU;;;AAGX,oBAAA,MAAM,2BAA2B,GAAG,IAAI,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,KAAK,CAAC;AACzF,oBAAA,MAAM,sBAAsB,GAAG,UAAU,CAAC,KAAK,CAAC;oBAChD,OAAO,2BAA2B,CAAC,SAAS,CAAC,sBAAsB,EAAE,UAAU,EAAE,KAAK,CAAC;AAC3F,gBAAA,KAAK,QAAQ;AACT,oBAAA,IAAI,UAAU,EAAE,QAAQ,KAAK,UAAU,EAAE;wBACrC,MAAM,yBAAyB,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;AAC5D,wBAAA,MAAM,YAAY,GAAG,UAAU,EAAE,KAAK;AACtC,wBAAA,MAAM,oBAAoB,GAAG,UAAU,CAAC,KAAK,CAAC;wBAC9C,OAAO,yBA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