2026-04-12 09:17:23 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
|
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract the first number from a string like "1.234 €" or "70 m²".
|
|
|
|
|
* Removes dots/commas before parsing. Returns null on invalid input.
|
|
|
|
|
* @param {string|undefined|null} str
|
|
|
|
|
* @returns {number|null}
|
|
|
|
|
*/
|
|
|
|
|
export const extractNumber = (str) => {
|
2026-04-21 13:37:00 +02:00
|
|
|
if (str == null) return 0;
|
2026-04-12 09:17:23 +02:00
|
|
|
if (typeof str === 'number') return str;
|
|
|
|
|
const cleaned = str.replace(/\./g, '').replace(',', '.');
|
|
|
|
|
const num = parseFloat(cleaned);
|
|
|
|
|
return isNaN(num) ? null : num;
|
|
|
|
|
};
|