- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
/**
|
|
* Utility functions for currency/decimal formatting and parsing
|
|
*/
|
|
|
|
/**
|
|
* Formats a decimal number for database storage (2 decimal places)
|
|
* @param value - The number to format
|
|
* @returns Formatted string with 2 decimal places, or null if input is null
|
|
*/
|
|
export function formatDecimalForDb(value: number | null): string | null {
|
|
if (value === null) {
|
|
return null;
|
|
}
|
|
|
|
return (Math.round(value * 100) / 100).toFixed(2);
|
|
}
|
|
|
|
/**
|
|
* Formats a decimal number for database storage (non-nullable version)
|
|
* @param value - The number to format
|
|
* @returns Formatted string with 2 decimal places
|
|
*/
|
|
export function formatDecimalForDbRequired(value: number): string {
|
|
return (Math.round(value * 100) / 100).toFixed(2);
|
|
}
|
|
|
|
/**
|
|
* Normalizes decimal input by replacing comma with period
|
|
* @param value - Input string
|
|
* @returns Normalized string with period as decimal separator
|
|
*/
|
|
export function normalizeDecimalInput(value: string): string {
|
|
return value.replace(/\s/g, "").replace(",", ".");
|
|
}
|
|
|
|
/**
|
|
* Formats a limit/balance input for display
|
|
* @param value - The number to format
|
|
* @returns Formatted string or empty string
|
|
*/
|
|
export function formatLimitInput(value?: number | null): string {
|
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
return "";
|
|
}
|
|
|
|
return (Math.round(value * 100) / 100).toFixed(2);
|
|
}
|
|
|
|
/**
|
|
* Formats an initial balance input for display (defaults to "0.00")
|
|
* @param value - The number to format
|
|
* @returns Formatted string with default "0.00"
|
|
*/
|
|
export function formatInitialBalanceInput(value?: number | null): string {
|
|
if (value === null || value === undefined || Number.isNaN(value)) {
|
|
return "0.00";
|
|
}
|
|
|
|
return (Math.round(value * 100) / 100).toFixed(2);
|
|
}
|