Accept JSON-serialized string arrays for /setentryfield. Return JSON lists in /getentryfield

This commit is contained in:
Cohee
2024-06-23 19:43:56 +03:00
parent 7c57132710
commit 59e1f9cca1
2 changed files with 24 additions and 5 deletions

View File

@ -623,6 +623,25 @@ export function isFalseBoolean(arg) {
return ['off', 'false', '0'].includes(arg?.trim()?.toLowerCase());
}
/**
* Parses an array either as a comma-separated string or as a JSON array.
* @param {string} value String to parse
* @returns {string[]} The parsed array.
*/
export function parseStringArray(value) {
if (!value || typeof value !== 'string') return [];
try {
const parsedValue = JSON.parse(value);
if (!Array.isArray(parsedValue)) {
throw new Error('Not an array');
}
return parsedValue.map(x => String(x));
} catch (e) {
return value.split(',').map(x => x.trim()).filter(x => x);
}
}
/**
* Checks if a number is odd.
* @param {number} number The number to check.
@ -1539,8 +1558,8 @@ export function flashHighlight(element, timespan = 2000) {
* @returns {boolean} Whether the control has an animation applied
*/
export function hasAnimation(control) {
const animatioName = getComputedStyle(control, null)["animation-name"];
return animatioName != "none";
const animatioName = getComputedStyle(control, null)['animation-name'];
return animatioName != 'none';
}
/**