Skip to content

matchKey

matchKey<T>(keyOrKeys: undefined | T | T[], value: T): boolean

Defined in: match-filters.ts:75

Checks if a value matches a filter key or array of keys. Returns true if the value is included in the array or equals the key.

Type Parameter
T
ParameterTypeDescription
keyOrKeysundefined | T | T[]A single key, array of keys, or undefined.
valueTThe value to test.

boolean

True if the value matches the key(s) or if keyOrKeys is undefined.

This function is useful for matching values against filter keys or arrays, supporting flexible filter logic for data, events, or state transitions.

export function matchKey<T>(keyOrKeys: T | T[] | undefined, value: T) {
if (keyOrKeys === undefined) {
return true;
}
return Array.isArray(keyOrKeys)
? keyOrKeys.includes(value)
: keyOrKeys === value;
}
matchKey(["a", "b"], "a"); // true
matchKey("b", "a"); // false
matchKey(undefined, "a"); // true