Add more docs, add more checks, add more tests

This commit is contained in:
Pieter Vander Vennet 2021-03-14 01:40:35 +01:00
parent a50b9fba59
commit 2c3c110624
7 changed files with 162 additions and 13 deletions

View file

@ -1,5 +1,4 @@
import {Utils} from "../Utils";
import {type} from "os";
export abstract class TagsFilter {
abstract matches(tags: { k: string, v: string }[]): boolean
@ -26,12 +25,14 @@ export class RegexTag extends TagsFilter {
private readonly key: RegExp | string;
private readonly value: RegExp | string;
private readonly invert: boolean;
private readonly matchesEmpty: boolean
constructor(key: string | RegExp, value: RegExp | string, invert: boolean = false) {
super();
this.key = key;
this.value = value;
this.invert = invert;
this.matchesEmpty = RegexTag.doesMatch("", this.value);
}
private static doesMatch(fromTag: string, possibleRegex: string | RegExp): boolean {
@ -65,6 +66,10 @@ export class RegexTag extends TagsFilter {
return RegexTag.doesMatch(tag.v, this.value) != this.invert;
}
}
if(this.matchesEmpty){
// The value is 'empty'
return !this.invert;
}
// The matching key was not found
return this.invert;
}
@ -244,7 +249,7 @@ export class Or extends TagsFilter {
}
usedKeys(): string[] {
return [].concat(this.or.map(subkeys => subkeys.usedKeys()));
return [].concat(...this.or.map(subkeys => subkeys.usedKeys()));
}
}
@ -363,7 +368,7 @@ export class And extends TagsFilter {
}
usedKeys(): string[] {
return [].concat(this.and.map(subkeys => subkeys.usedKeys()));
return [].concat(...this.and.map(subkeys => subkeys.usedKeys()));
}
}