bugfixes and improvements

This commit is contained in:
orangecoding
2026-06-13 14:02:42 +02:00
parent 94384df36d
commit 9207280ab4
12 changed files with 32 additions and 21 deletions

View File

@@ -5,12 +5,13 @@
/**
* Extract the first number from a string like "1.234 €" or "70 m²".
* Removes dots/commas before parsing. Returns null on invalid input.
* Removes dots/commas before parsing. Returns null when the input is
* null/undefined or cannot be parsed into a number.
* @param {string|undefined|null} str
* @returns {number|null}
*/
export const extractNumber = (str) => {
if (str == null) return 0;
if (str == null) return null;
if (typeof str === 'number') return str;
const cleaned = str.replace(/\./g, '').replace(',', '.');
const num = parseFloat(cleaned);