mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-12 08:38:10 +00:00
js/util: tweak toNumerical() to match JSDoc comment
This commit is contained in:
parent
581acf18aa
commit
a3829c016a
@ -259,22 +259,26 @@ export function toNumerical(obj)
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const convertToNumber = (input) =>
|
||||||
|
{
|
||||||
|
const n = Number.parseFloat(input);
|
||||||
|
|
||||||
|
if (Number.isNaN(n))
|
||||||
|
{
|
||||||
|
throw `unable to convert ${e} to a number`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof obj === 'string')
|
if (typeof obj === 'string')
|
||||||
{
|
{
|
||||||
obj = [obj];
|
return convertToNumber(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(obj))
|
if (Array.isArray(obj))
|
||||||
{
|
{
|
||||||
return obj.map(e =>
|
return obj.map(convertToNumber);
|
||||||
{
|
|
||||||
let n = Number.parseFloat(e);
|
|
||||||
if (Number.isNaN(n))
|
|
||||||
{
|
|
||||||
throw `unable to convert ${e} to a number`;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw 'unable to convert the object to a number';
|
throw 'unable to convert the object to a number';
|
||||||
|
Loading…
Reference in New Issue
Block a user