Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/core/src/format.ts
Original file line number Diff line number Diff line change
@@ -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}`;
};
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ export {
buildInvoiceScheduleFormValues,
} from './domains/invoice-schedule/utils';
export type { ContractorInvoicePreview } from './domains/invoice-schedule/types';
export { clearBase64Data, formatCurrency } from './format';
42 changes: 2 additions & 40 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError, 'type' | 'errors'> & {
inner: Record<string, YupError>[];
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -432,3 +392,5 @@ export function setFormFieldErrors(
}

export { getNestedValue };

export { clearBase64Data, formatCurrency } from '@remoteoss/remote-flows-core';
Loading