Change return to empty string on no single match

6cb1eb3fe69cfebd2c71138c6b0971007007acc4

Crow <bismuthglass@protonmail.com>

1 files changed, +5 -4Ignore whitespace
public/scripts/slash-commands.js+5 -4
@@ -2177,14 +2177,15 @@ export function initDefaultSlashCommands() {
21772177 if (!pattern) {
21782178 throw new Error('Argument of \'pattern=\' cannot be empty');
21792179 }
21802180 letconst re = regexFromString(pattern.toString());
21812181 if (!re) {
21822182 throw new Error('The value of \'pattern\' argument is not a valid regular expression.');
21832183 }
21842184 if (re.flags.includes('g')) {
21852185 return JSON.stringify([...text.toString().matchAll(re)]);
21862186 } else {
21872187 returnconst JSON.stringify(match = text.toString().match(re));
2188+ return match ? JSON.stringify(match) : '';
21882189 }
21892190 }),
21902191 returns: 'group array for each match',
@@ -2205,7 +2206,7 @@ export function initDefaultSlashCommands() {
22052206 <div>
22062207 Returns an array of groups (with the first group being the full match). If the regex contains the global flag (i.e. <code>/g</code>),
22072208 multiple nested arrays are returned for each match. If the regex is global, returns <code>[]</code> if no matches are found,
22082209 otherwise it returns nullan empty string.
22092210 </div>
22102211 <div>
22112212 <strong>Example:</strong>
@@ -2213,7 +2214,7 @@ export function initDefaultSlashCommands() {
22132214 <pre><code class="language-stscript">/match pattern="green" {{var::x}} | /echo |/# [ "green" ] ||</code></pre>
22142215 <pre><code class="language-stscript">/match pattern="color_(\\w+)" {{var::x}} | /echo |/# [ "color_green", "green" ] ||</code></pre>
22152216 <pre><code class="language-stscript">/match pattern="/color_(\\w+)/g" {{var::x}} | /echo |/# [ [ "color_green", "green" ], [ "color_blue", "blue" ] ] ||</code></pre>
22162217 <pre><code class="language-stscript">/match pattern="orange" {{var::x}} | /echo |/# null ||</code></pre>
22172218 <pre><code class="language-stscript">/match pattern="/orange/g" {{var::x}} | /echo |/# [] ||</code></pre>
22182219 </div>
22192220 `,