Accept arbitrarily formatted numbers as the amount input
This commit is contained in:
parent
2bb7902c3b
commit
896163470d
1 changed files with 7 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue