mirror of
https://github.com/Snigdha-OS/documentation.git
synced 2025-09-10 19:54:57 +02:00
18 lines
352 B
JavaScript
18 lines
352 B
JavaScript
'use strict';
|
|
|
|
function valToNumber(v) {
|
|
if (typeof v === 'number') {
|
|
return v;
|
|
} else if (typeof v === 'string') {
|
|
return parseFloat(v);
|
|
} else if (Array.isArray(v)) {
|
|
return v.map(valToNumber);
|
|
}
|
|
|
|
throw new Error(
|
|
'The value should be a number, a parsable string or an array of those.'
|
|
);
|
|
}
|
|
|
|
module.exports = valToNumber;
|