Accept arbitrarily formatted numbers as the amount input

This commit is contained in:
Campbell Alden 2026-03-22 00:23:02 +09:00
parent 2bb7902c3b
commit 896163470d

View file

@ -21,10 +21,16 @@ function parse(data) {
throw new Error('Bad Title');
}
if (typeof data.amount !== 'number') {
if (typeof data.amount !== 'number' || typeof data.amount !== 'string') {
throw new Error('Bad amount');
}
if (typeof data.amount === 'string') {
const value = Number(data.amount.replaceAll(/[^\d]/g, ''));
data.amount = Number.isNaN(value) ? 0 : value;
}
return data;
}