Files
cfw-autumn/frontend/src/utils/formatUtils/formatTextUtils.ts
2025-01-21 11:18:42 +00:00

22 lines
634 B
TypeScript

export const keyToTitle = (key: string) => {
return key.replace(/_/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
};
export const keyToTitleFirstCaps = (key: string) => {
// Capitalize first char
const res = key.replace(/^\w/, (char) => char.toUpperCase());
// Replace underscores with spaces
return res.replace(/_/g, " ");
};
export const slugify = (text: string) => {
return text.toLowerCase().replace(/ /g, "-");
};
export const formatCurrency = (amount: number, currency: string = "USD") => {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: currency,
}).format(amount);
};