feat(slash-commands): add stringify option to /array-wrap command for JSON primitive handling

963786758bd4c3dc7e150289ee32c0dbf9729d83

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +16 -1Ignore whitespace
public/scripts/slash-commands.js+16 -1
@@ -3645,6 +3645,15 @@ export function initDefaultSlashCommands() {
3645 aliases: ['list-wrap'],3645 aliases: ['list-wrap'],
3646 returns: t`unnamed argument value wrapped into an array`,3646 returns: t`unnamed argument value wrapped into an array`,
3647 helpString: t`Wraps a single unnamed argument into an array if it's not already an array. If the value is an empty string, returns an empty array.`,3647 helpString: t`Wraps a single unnamed argument into an array if it's not already an array. If the value is an empty string, returns an empty array.`,
3648 namedArgumentList: [
3649 SlashCommandNamedArgument.fromProps({
3650 name: 'stringify',
3651 description: t`Whether JSON primitives (numbers, booleans, nulls) should be treated as strings, i.e. ["null"] when stringify=true vs. [null] when stringify=false.`,
3652 typeList: [ARGUMENT_TYPE.BOOLEAN],
3653 defaultValue: 'true',
3654 enumList: commonEnumProviders.boolean('trueFalse')(),
3655 }),
3656 ],
3648 unnamedArgumentList: [3657 unnamedArgumentList: [
3649 SlashCommandArgument.fromProps({3658 SlashCommandArgument.fromProps({
3650 description: t`value`,3659 description: t`value`,
@@ -3653,7 +3662,7 @@ export function initDefaultSlashCommands() {
3653 typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.DICTIONARY, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.LIST],3662 typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.DICTIONARY, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.LIST],
3654 }),3663 }),
3655 ],3664 ],
3656 callback: (_args, value) => {3665 callback: (args, value) => {
3657 // Closures are not supported3666 // Closures are not supported
3658 if (value instanceof SlashCommandClosure) {3667 if (value instanceof SlashCommandClosure) {
3659 throw new SlashCommandExecutionError(t`Closures are not supported as unnamed arguments for /array-wrap. Did you forget to call the closure with parentheses?`);3668 throw new SlashCommandExecutionError(t`Closures are not supported as unnamed arguments for /array-wrap. Did you forget to call the closure with parentheses?`);
@@ -3683,6 +3692,12 @@ export function initDefaultSlashCommands() {
3683 return JSON.stringify([parsedValue]);3692 return JSON.stringify([parsedValue]);
3684 }3693 }
36853694
3695 // For primitive values, check if we should take the parsed or original value based on the stringify argument
3696 const isJsonPrimitive = parsedValue === null || ['string', 'number', 'boolean'].includes(typeof parsedValue);
3697 if (isJsonPrimitive && isFalseBoolean(String(args?.stringify?.toString()))) {
3698 return JSON.stringify([parsedValue]);
3699 }
3700
3686 // Wrap the original value (string, number, boolean) into an array, preserving quotes for strings3701 // Wrap the original value (string, number, boolean) into an array, preserving quotes for strings
3687 return JSON.stringify([value]);3702 return JSON.stringify([value]);
3688 } catch {3703 } catch {