Skip empty parts

This commit is contained in:
MareStare 2025-03-17 23:21:54 +00:00
parent a6ae4d9422
commit ba02e3f1c9
2 changed files with 30 additions and 0 deletions

View file

@ -34,4 +34,30 @@ describe('prefixMatchParts', () => {
]
`);
});
it(`should ignore case when matching`, () => {
expect(prefixMatchParts('FOObar', 'foo')).toMatchInlineSnapshot(`
[
{
"matched": "FOO",
},
"bar",
]
`);
});
it(`should skip empty parts`, () => {
expect(prefixMatchParts('foo', 'foo')).toMatchInlineSnapshot(`
[
{
"matched": "foo",
},
]
`);
expect(prefixMatchParts('foo', 'bar')).toMatchInlineSnapshot(`
[
"foo",
]
`);
});
});

View file

@ -51,6 +51,10 @@ export type TagSuggestion = CanonicalTagSuggestion | AliasTagSuggestion;
* contains the `prefix` after the namespace separator.
*/
export function prefixMatchParts(target: string, prefix: string): MatchPart[] {
return prefixMatchPartsImpl(target, prefix).filter(part => typeof part !== 'string' || part.length > 0);
}
function prefixMatchPartsImpl(target: string, prefix: string): MatchPart[] {
const targetLower = target.toLowerCase();
const prefixLower = prefix.toLowerCase();