diff --git a/public/scripts/variables.js b/public/scripts/variables.js index b06728359..0e18f404a 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -679,10 +679,17 @@ function parseNumericSeries(value, scope = null) { return [value]; } - const values = Array.isArray(value) ? value : value.split(' '); - const array = values.map(i => i.trim()) + /** @type {(string|number)[]} */ + let values = Array.isArray(value) ? value : value.split(' '); + + // If a JSON array was provided as the only value, convert it to an array + if (values.length === 1 && typeof values[0] === 'string' && values[0].startsWith('[')) { + values = convertValueType(values[0], 'array'); + } + + const array = values.map(i => typeof i === 'string' ? i.trim() : i) .filter(i => i !== '') - .map(i => isNaN(Number(i)) ? Number(resolveVariable(i, scope)) : Number(i)) + .map(i => isNaN(Number(i)) ? Number(resolveVariable(String(i), scope)) : Number(i)) .filter(i => !isNaN(i)); return array; @@ -1599,7 +1606,7 @@ export function registerVariableCommands() { unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'values to sum', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME], + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST], isRequired: true, acceptsMultiple: true, enumProvider: commonEnumProviders.numbersAndVariables, @@ -1610,7 +1617,9 @@ export function registerVariableCommands() { helpString: `
Performs an addition of the set of values and passes the result down the pipe. - Can use variable names. +
+
+ Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
Example: @@ -1618,6 +1627,9 @@ export function registerVariableCommands() {
  • /add 10 i 30 j
  • +
  • +
    /add ["count", 15, 2, "i"]
    +
  • `, @@ -1629,7 +1641,7 @@ export function registerVariableCommands() { unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'values to multiply', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME], + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST], isRequired: true, acceptsMultiple: true, enumProvider: commonEnumProviders.numbersAndVariables, @@ -1639,7 +1651,10 @@ export function registerVariableCommands() { splitUnnamedArgument: true, helpString: `
    - Performs a multiplication of the set of values and passes the result down the pipe. Can use variable names. + Performs a multiplication of the set of values and passes the result down the pipe. +
    +
    + Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
    Examples: @@ -1647,6 +1662,9 @@ export function registerVariableCommands() {
  • /mul 10 i 30 j
  • +
  • +
    /mul ["count", 15, 2, "i"]
    +
  • `, @@ -1658,7 +1676,7 @@ export function registerVariableCommands() { unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'values to find the max', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME], + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST], isRequired: true, acceptsMultiple: true, enumProvider: commonEnumProviders.numbersAndVariables, @@ -1668,7 +1686,10 @@ export function registerVariableCommands() { splitUnnamedArgument: true, helpString: `
    - Returns the maximum value of the set of values and passes the result down the pipe. Can use variable names. + Returns the maximum value of the set of values and passes the result down the pipe. +
    +
    + Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
    Examples: @@ -1676,6 +1697,9 @@ export function registerVariableCommands() {
  • /max 10 i 30 j
  • +
  • +
    /max ["count", 15, 2, "i"]
    +
  • `, @@ -1687,7 +1711,7 @@ export function registerVariableCommands() { unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'values to find the min', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME], + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST], isRequired: true, acceptsMultiple: true, enumProvider: commonEnumProviders.numbersAndVariables, @@ -1698,7 +1722,9 @@ export function registerVariableCommands() { helpString: `
    Returns the minimum value of the set of values and passes the result down the pipe. - Can use variable names. +
    +
    + Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
    Example: @@ -1706,6 +1732,9 @@ export function registerVariableCommands() {
  • /min 10 i 30 j
  • +
  • +
    /min ["count", 15, 2, "i"]
    +
  • `, @@ -1717,7 +1746,7 @@ export function registerVariableCommands() { unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'values to subtract, starting form the first provided value', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME], + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.LIST], isRequired: true, acceptsMultiple: true, enumProvider: commonEnumProviders.numbersAndVariables, @@ -1728,7 +1757,9 @@ export function registerVariableCommands() { helpString: `
    Performs a subtraction of the set of values and passes the result down the pipe. - Can use variable names. +
    +
    + Can use variable names, or a JSON array consisting of numbers and variables (with quotes).
    Example: @@ -1736,6 +1767,9 @@ export function registerVariableCommands() {
  • /sub i 5
  • +
  • +
    /sub ["count", 4, "i"]
    +
  • `,