From d7f451a7d928cfd7479ab1cb1426eb2b846a9b3a Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Sat, 23 Apr 2022 19:42:40 +0200 Subject: [PATCH] CustomFieldStringTemplate regular expressions of format field now possible the new syntax is e.g.: ${regex:".(.*).", replace:"$1", flags:"i"} removes the first and last character and uses case-insensitive search. See also: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/RegExp --- client/components/cards/cardCustomFields.js | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/client/components/cards/cardCustomFields.js b/client/components/cards/cardCustomFields.js index c4559c3f0..d54e940fd 100644 --- a/client/components/cards/cardCustomFields.js +++ b/client/components/cards/cardCustomFields.js @@ -256,10 +256,28 @@ CardCustomField.register('cardCustomField'); } formattedValue() { - return (this.data().value ?? []) + const ret = (this.data().value ?? []) .filter(value => !!value.trim()) - .map(value => this.stringtemplateFormat.replace(/%\{value\}/gi, value)) + .map(value => { + let _ret = this.stringtemplateFormat.replace(/[%$]\{.+?\}/g, function(_match) { + let __ret; + if (_match.match(/%\{value\}/i)) { + __ret = value; + } else { + _match = _match.replace(/^\$/, ""); + try { + const _json = JSON.parse(_match); + __ret = value.replace(new RegExp(_json.regex, _json.flags), _json.replace); + } catch (err) { + console.error(err); + } + } + return __ret; + }); + return _ret; + }) .join(this.stringtemplateSeparator ?? ''); + return ret; } getItems() {