diff --git a/packages/core/src/formatters/base.ts b/packages/core/src/formatters/base.ts index 22698f943..da9350c16 100644 --- a/packages/core/src/formatters/base.ts +++ b/packages/core/src/formatters/base.ts @@ -892,13 +892,24 @@ export abstract class BaseFormatter { return variable.replaceAll(key, replaceKey); } case mod.startsWith('remove(') && mod.endsWith(')'): { - const findStartChar = mod.charAt(7); // either " or ' - const findEndChar = mod.charAt(mod.length - 2); // either " or ' - - // Extract the content from remove(['"]...['"]) - const content = _mod.substring(8, _mod.length - 2); + const content = _mod.substring(7, _mod.length - 1); + + // Extract options from remove("...", "...", ...) + const regex = /"([^"]*)"|'([^']*)'/g; + const args: string[] = []; + + let match; + while ((match = regex.exec(content)) !== null) { + args.push(match[1] ?? match[2] ?? ''); + } - if (content) return variable.replaceAll(content, ''); + if (args.length === 0) return undefined; + + let result = variable; + for (const arg of args) { + if (arg) result = result.replaceAll(arg, ''); + } + return result; } case mod.startsWith('truncate(') && mod.endsWith(')'): { // Extract N from truncate(N) @@ -946,13 +957,20 @@ export abstract class BaseFormatter { return variable.join(separator); } case mod.startsWith('remove(') && mod.endsWith(')'): { - const findStartChar = mod.charAt(7); // either " or ' - const findEndChar = mod.charAt(mod.length - 2); // either " or ' + const content = _mod.substring(7, _mod.length - 1); + + // Extract options from remove("...", "...", ...) + const regex = /"([^"]*)"|'([^']*)'/g; + const args: string[] = []; + + let match; + while ((match = regex.exec(content)) !== null) { + args.push(match[1] ?? match[2] ?? ''); + } - // Extract the content from remove(['"]...['"]) - const content = _mod.substring(8, _mod.length - 2); + if (args.length === 0) return undefined; - if (content) return variable.filter((v) => v !== content); + return variable.filter((v) => !args.includes(v)); } } } @@ -1201,12 +1219,11 @@ class ModifierConstants { }; static hardcodedModifiersForRegexMatching = { + 'remove(.*?)': null, "replace('.*?'\\s*?,\\s*?'.*?')": null, 'replace(".*?"\\s*?,\\s*?\'.*?\')': null, 'replace(\'.*?\'\\s*?,\\s*?".*?")': null, 'replace(".*?"\\s*?,\\s*?\".*?\")': null, - "remove('.*?')": null, - 'remove(".*?")': null, "join('.*?')": null, 'join(".*?")': null, 'truncate(\\d+)': null,