moviebox/src/helpers/formater/index.ts

28 lines
730 B
TypeScript

export const formatter = {
formatDate: (dateString: string) => {
const date = new Date(dateString);
return date.toLocaleDateString("pl-PL", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
},
formatCurrency: (amount: number) => {
return new Intl.NumberFormat("pl-PL", {
style: "currency",
currency: "PLN",
}).format(amount);
},
formatPopularity: (popularity: number) => {
return Math.round(popularity);
},
formatVoteAverage: (voteAverage: number) => {
return voteAverage.toFixed(1);
},
formatRuntime: (runtime: number) => {
const hours = Math.floor(runtime / 60);
const minutes = runtime % 60;
return `${hours}h ${minutes}m`;
},
};