mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-19 10:17:14 +01:00
Skip empty parts
This commit is contained in:
parent
a6ae4d9422
commit
ba02e3f1c9
2 changed files with 30 additions and 0 deletions
|
@ -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",
|
||||||
|
]
|
||||||
|
`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,6 +51,10 @@ export type TagSuggestion = CanonicalTagSuggestion | AliasTagSuggestion;
|
||||||
* contains the `prefix` after the namespace separator.
|
* contains the `prefix` after the namespace separator.
|
||||||
*/
|
*/
|
||||||
export function prefixMatchParts(target: string, prefix: string): MatchPart[] {
|
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 targetLower = target.toLowerCase();
|
||||||
const prefixLower = prefix.toLowerCase();
|
const prefixLower = prefix.toLowerCase();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue