Merge pull request #1487 from LenAnderson/st-object-vars

Better handling of array / object variables
This commit is contained in:
Cohee 2023-12-07 16:48:09 +02:00 committed by GitHub
commit bb1c278899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 2 deletions

View File

@ -11,7 +11,15 @@ function getLocalVariable(name, args = {}) {
if (args.index !== undefined) {
try {
localVariable = JSON.parse(localVariable);
localVariable = localVariable[Number(args.index)];
const numIndex = Number(args.index);
if (Number.isNaN(numIndex)) {
localVariable = localVariable[args.index];
} else {
localVariable = localVariable[Number(args.index)];
}
if (typeof localVariable == 'object') {
localVariable = JSON.stringify(localVariable);
}
} catch {
// that didn't work
}
@ -35,7 +43,15 @@ function getGlobalVariable(name, args = {}) {
if (args.index !== undefined) {
try {
globalVariable = JSON.parse(globalVariable);
globalVariable = globalVariable[Number(args.index)];
const numIndex = Number(args.index);
if (Number.isNaN(numIndex)) {
globalVariable = globalVariable[args.index];
} else {
globalVariable = globalVariable[Number(args.index)];
}
if (typeof globalVariable == 'object') {
globalVariable = JSON.stringify(globalVariable);
}
} catch {
// that didn't work
}