SYNC: test for parseName + fix

This commit is contained in:
SPRINX0\prochazka
2025-03-28 15:42:14 +01:00
committed by Diflow
parent d3d97b5924
commit 0dd0125e9f
5 changed files with 39 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
const { tokenizeBySearchFilter } = require('./filterName');
test('tokenize single token', () => {
const tokenized = tokenizeBySearchFilter('Album', 'al');
// console.log(JSON.stringify(tokenized, null, 2));
expect(tokenized).toEqual([
{ text: 'Al', isMatch: true },
{ text: 'bum', isMatch: false },
]);
});
test('tokenize two tokens', () => {
const tokenized = tokenizeBySearchFilter('Album', 'al,um');
// console.log(JSON.stringify(tokenized, null, 2));
expect(tokenized).toEqual([
{ text: 'Al', isMatch: true },
{ text: 'b', isMatch: false },
{ text: 'um', isMatch: true },
]);
});

View File

@@ -118,7 +118,10 @@ export function filterNameCompoud(
export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] {
const camelTokens = [];
const stdTokens = [];
for (const token of filter.split(/ ,/).map(x => x.trim())) {
for (const token of filter
.split(/[ ,]/)
.map(x => x.trim())
.filter(x => x.length > 0)) {
if (token.replace(/[A-Z]/g, '').length == 0) {
camelTokens.push(token);
} else {