predictype

predictype v0.13.0


predictype / predicates/queries/queryValue / queryValue

Function: queryValue()

queryValue(source, oper, value): boolean

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

Checks whether query parameters contain or lack a value.

Parameters

source

URL | URLSearchParams

The query source to inspect (URL or URLSearchParams).

oper

QueryValueOper

The value operation to perform (‘contains_value’ or ‘lacks_value’).

value

string

The value to check.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const source = new URLSearchParams('status=active&role=admin&role=editor');
const valueA = 'editor';
const valueB = 'guest';

queryValue(source, 'contains_value', valueA); // true
queryValue(source, 'lacks_value', valueB); // true

Remarks

Supported Operators: