@leanix/components 0.3.41 → 0.3.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1368,20 +1368,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImpor
1368
1368
  */
1369
1369
  const STANDARD_TOKENIZER_SEPERATORS = /[^a-zA-Z\d\s]/g;
1370
1370
  class HighlightTermPipe {
1371
- transform(text, search) {
1371
+ /**
1372
+ * Transforms the input text with highlighted text according to the provided search term.
1373
+ * @param text The input text.
1374
+ * @param search The search term to highlight.
1375
+ * @param options The highlight term search options.
1376
+ * @returns The transformed text with highlighted search term.
1377
+ */
1378
+ transform(text, search, options = { exactMatch: false }) {
1372
1379
  if (search && text) {
1373
- let pattern = search
1374
- .replace(STANDARD_TOKENIZER_SEPERATORS, ' ')
1375
- // replace special chars for a backslash for RegExp
1376
- .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
1377
- pattern = pattern
1378
- .split(' ')
1379
- .filter((t) => {
1380
- return t.length > 0;
1381
- })
1382
- .join('|');
1380
+ let pattern = options.exactMatch
1381
+ ? search.trim()
1382
+ : search
1383
+ .replace(STANDARD_TOKENIZER_SEPERATORS, ' ')
1384
+ // replace special chars for a backslash for RegExp
1385
+ .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
1386
+ pattern = options.exactMatch
1387
+ ? escape(pattern)
1388
+ : pattern
1389
+ .split(' ')
1390
+ .filter((t) => {
1391
+ return t.length > 0;
1392
+ })
1393
+ .join('|');
1383
1394
  const regex = new RegExp(pattern, 'gi');
1384
- text = _.escape(text);
1395
+ text = escape(text);
1385
1396
  return text.replace(regex, (match) => `<span class="termHighlight">${match}</span>`); // add highlighting to matched regex pattern
1386
1397
  }
1387
1398
  else {