forked from git.gladyson/openmonetis
Remove 6 componentes não utilizados (dashboard-grid, expenses/income by category widgets, installment analysis panels, fatura-warning-dialog). Remove funções/tipos não utilizados: successResult, generateApiToken, validateApiToken, getTodayUTC/Local, formatDateForDb, getDateInfo, calculatePercentage, roundToDecimals, safeParseInt/Float, isPeriodValid, getLastPeriods, normalizeWhitespace, formatCurrency wrapper, InboxItemInput, InboxBatchInput, ProcessInboxInput, DiscardInboxInput, LancamentosColumnId, 5 funções de anticipation-helpers. Redireciona imports de formatCurrency para lib/lancamentos/formatting-helpers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
28 lines
669 B
TypeScript
28 lines
669 B
TypeScript
/**
|
|
* Utility functions for safe number conversions
|
|
*/
|
|
|
|
/**
|
|
* Safely converts unknown value to number
|
|
* @param value - Value to convert
|
|
* @param defaultValue - Default value if conversion fails
|
|
* @returns Converted number or default value
|
|
*/
|
|
export function safeToNumber(value: unknown, defaultValue: number = 0): number {
|
|
if (typeof value === "number") {
|
|
return value;
|
|
}
|
|
|
|
if (typeof value === "string") {
|
|
const parsed = Number(value);
|
|
return Number.isNaN(parsed) ? defaultValue : parsed;
|
|
}
|
|
|
|
if (value === null || value === undefined) {
|
|
return defaultValue;
|
|
}
|
|
|
|
const parsed = Number(value);
|
|
return Number.isNaN(parsed) ? defaultValue : parsed;
|
|
}
|