predictype

predictype v0.13.0


predictype / predicates/queries/queryKey / queryKey

Function: queryKey()

queryKey(source, oper, key): boolean

Defined in: predicates/queries/queryKey.ts:26

Checks whether query parameters contain or lack a key.

Parameters

source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryKeyOper

The key operation to perform (‘contains_key’ or ‘lacks_key’).

key

string

The key to check.

Returns

boolean

True if the key check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const source = new URLSearchParams('q=predicates&page=2');
const keyA = 'q';
const keyB = 'lang';

queryKey(source, 'contains_key', keyA); // true
queryKey(source, 'lacks_key', keyB); // true

Remarks

Supported Operators: