mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-11 16:18:10 +00:00
util/Util: make turnSquareBracketsIntoArrays() easier to consume
This commit is contained in:
parent
32f4b83926
commit
8ad1387084
@ -278,9 +278,9 @@ export function toNumerical(obj)
|
||||
|
||||
const arrayMaybe = turnSquareBracketsIntoArrays(obj);
|
||||
|
||||
if (Array.isArray(arrayMaybe) && arrayMaybe.length)
|
||||
if (Array.isArray(arrayMaybe))
|
||||
{
|
||||
return arrayMaybe.map(v => v.map(convertToNumber));
|
||||
return arrayMaybe.map(convertToNumber);
|
||||
}
|
||||
|
||||
if (typeof obj === 'string')
|
||||
@ -975,9 +975,10 @@ export function offerDataForDownload(filename, data, type)
|
||||
* @function
|
||||
* @public
|
||||
* @param {string} input - string containing lists in square brackets
|
||||
* @param {string} max - how many matches to return, unwrap resulting array if less than two
|
||||
* @returns {array} an array of arrays found
|
||||
*/
|
||||
export function turnSquareBracketsIntoArrays(input)
|
||||
export function turnSquareBracketsIntoArrays(input, max = 1)
|
||||
{
|
||||
// Only interested in strings
|
||||
// https://stackoverflow.com/questions/4059147
|
||||
@ -1007,6 +1008,11 @@ export function turnSquareBracketsIntoArrays(input)
|
||||
}
|
||||
);
|
||||
|
||||
if (max < 2)
|
||||
{
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user