Files
Investidor-V2/resources/js/lib/public-offer.ts
T

24 lines
830 B
TypeScript

export type PublicOffer = {
id: number;
title: string;
summary: string;
category: string;
location: { id: string; name: string; level: string }[];
price: {
mode: 'amount' | 'negotiable';
amount: string | null;
currency: string | null;
};
status: 'published';
published_at: string;
expires_at?: string | null;
revision: number;
url: string;
};
/** Display exact decimal text, including large amounts; never converts currency. */
export function offerPrice(price: PublicOffer['price']): string {
if (price.mode === 'negotiable') return 'A negociar';
const [whole, fraction = ''] = (price.amount ?? '').split('.');
return `${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')}${fraction ? `,${fraction.padEnd(2, '0')}` : ',00'} ${price.currency ?? ''}`;
}