1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-12 16:48:10 +00:00

data/TrialHandler: tweak numerical string typecasting

This commit is contained in:
Sotiri Bakagiannis 2021-02-19 14:11:08 +00:00
parent a603a58521
commit a2db2f2851

View File

@ -482,11 +482,18 @@ export class TrialHandler extends PsychObject
if (typeof value === 'string') if (typeof value === 'string')
{ {
// Parse doubly escaped line feeds const numberMaybe = Number.parseFloat(value);
value = value.replace(/(\\n)/g, '\n');
// if value is a numerical string, convert it to a number: // if value is a numerical string, convert it to a number:
value = isNaN(value) ? value : Number.parseFloat(value); if (!isNaN(numberMaybe) && numberMaybe.toString().length === value.length)
{
value = numberMaybe;
}
else
{
// Parse doubly escaped line feeds
value = value.replace(/(\n)/g, '\n');
}
} }
trial[fields[l]] = value; trial[fields[l]] = value;