From 13999f81b4596899f7dd2d262a42fbe56ad2c7c9 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Fri, 17 Dec 2021 18:07:36 -0800 Subject: [PATCH] config: Add support for substring filters --- src/config/device.ts | 1 + src/config/filters.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/config/device.ts b/src/config/device.ts index 5e17546..387348a 100644 --- a/src/config/device.ts +++ b/src/config/device.ts @@ -66,6 +66,7 @@ export const EMPTY_FILTERS = { match: [], prefix: [], suffix: [], + substring: [], regex: [], } as SerializedFilters // Same, but defaults to inclusion list diff --git a/src/config/filters.ts b/src/config/filters.ts index 40854cf..76f08ef 100644 --- a/src/config/filters.ts +++ b/src/config/filters.ts @@ -11,6 +11,7 @@ export interface SerializedFilters { match: string[] prefix: string[] suffix: string[] + substring: string[] regex: string[] } @@ -21,6 +22,7 @@ export interface Filters { match: Set prefix: string[] suffix: string[] + substring: string[] regex: RegExp[] } @@ -33,6 +35,7 @@ export function parseFilters(src: SerializedFilters) { match: new Set(src.match), prefix: src.prefix, suffix: src.suffix, + substring: src.substring, regex: src.regex.map(pat => new RegExp(pat)), } as Filters } @@ -41,6 +44,7 @@ function _matchFilters(filters: Filters, value: string) { return filters.match.has(value) || filters.prefix.find(prefix => value.startsWith(prefix)) != undefined || filters.suffix.find(suffix => value.endsWith(suffix)) != undefined || + filters.substring.find(substring => value.includes(substring)) != undefined || filters.regex.find(regex => value.match(regex)) != null }