export interface ParseNumberOptions { /** * If true, requires exact match (no commas, no extra whitespace) * * @default false */ strict?: boolean | undefined } /** * Parses a string value into a number, with optional strict mode. * * @param value - The string value to parse. * @param options - Parsing options. * @returns The parsed number, or null if parsing fails. */ export function parseNumber(value: string, options?: ParseNumberOptions) { const { strict = false } = options ?? {} const cleanedValue = value.replace(/,/g, '').trim() if (cleanedValue === '' || (cleanedValue !== value && strict)) return null const number = Number(cleanedValue) if (!Number.isFinite(number) || (String(number) !== cleanedValue && strict)) return null return number }