diff --git a/packages/core/src/format.ts b/packages/core/src/format.ts new file mode 100644 index 000000000..ad12080c5 --- /dev/null +++ b/packages/core/src/format.ts @@ -0,0 +1,39 @@ +export function formatCurrency( + amount: number | undefined | null, + currencyCode = 'EUR', +): string { + if (amount == null) { + return '-'; + } + + const value = amount / 100; + + return new Intl.NumberFormat('en', { + style: 'currency', + currency: currencyCode, + currencyDisplay: 'symbol', + }).format(value); +} + +/** + * Ensures base64 data has the correct data URI prefix for PDF content + * @param base64Data - The base64 data string + * @returns The base64 data with proper data URI prefix + */ +export const clearBase64Data = (base64Data: string) => { + if (!base64Data) { + return ''; + } + + const cleanedData = base64Data.trim(); + + if (cleanedData.startsWith('data:application/pdf;base64,')) { + return cleanedData; + } + + if (cleanedData.startsWith('data:')) { + return cleanedData; + } + + return `data:application/pdf;base64,${cleanedData}`; +}; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 423352a78..1db922ffe 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -45,3 +45,4 @@ export { buildInvoiceScheduleFormValues, } from './domains/invoice-schedule/utils'; export type { ContractorInvoicePreview } from './domains/invoice-schedule/types'; +export { clearBase64Data, formatCurrency } from './format'; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 4e75ca0d8..3ae5b6ed4 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -12,23 +12,6 @@ export function cn(...inputs: ClassValue[]) { return mergeClasses(...inputs); } -export function formatCurrency( - amount: number | undefined | null, - currencyCode = 'EUR', -): string { - if (amount == null) { - return '-'; - } - - const value = amount / 100; - - return new Intl.NumberFormat('en', { - style: 'currency', - currency: currencyCode, - currencyDisplay: 'symbol', - }).format(value); -} - type YupError = Pick & { inner: Record[]; }; @@ -142,29 +125,6 @@ export const stripHtml = ( return doc.body.textContent || ''; }; -/** - * Ensures base64 data has the correct data URI prefix for PDF content - * @param base64Data - The base64 data string - * @returns The base64 data with proper data URI prefix - */ -export const clearBase64Data = (base64Data: string) => { - if (!base64Data) { - return ''; - } - - const cleanedData = base64Data.trim(); - - if (cleanedData.startsWith('data:application/pdf;base64,')) { - return cleanedData; - } - - if (cleanedData.startsWith('data:')) { - return cleanedData; - } - - return `data:application/pdf;base64,${cleanedData}`; -}; - /** * Function to prettify form values. Returns a pretty value and label for each field. * @param values - Form values to prettify @@ -432,3 +392,5 @@ export function setFormFieldErrors( } export { getNestedValue }; + +export { clearBase64Data, formatCurrency } from '@remoteoss/remote-flows-core';