collectype

collectype v0.13.0


collectype / factory/queries/queryValue / queryValueFactory

Function: queryValueFactory()

queryValueFactory<T, C>(ctx, oper): <K>(field, target) => C

Defined in: factory/queries/queryValue.ts:39

Creates a predicate filter for query value checks using PredicType.query.value.

Type Parameters

T

T

The item type in the collection.

C

C extends Wherable<T, C>

The Wherable context type (must extend Wherable<T, C>).

Parameters

ctx

C

The context (usually a collection) supporting the where method.

oper

QueryValueOper

The query value operation to perform.

Returns

Returns a function that takes a query field on T, checks a value, and filters the context.

<K>(field, target) => C

Example

// Example: query value filter with URLSearchParams
import { BaseFunctions, queryValueFactory } from 'collectype';

type Post = { id: number; query: URLSearchParams };

class PostFunctions extends BaseFunctions<Post> {
  queryContainsValue = queryValueFactory<Post, this>(this, 'contains_value');
}

const posts: Post[] = [
  { id: 1, query: new URLSearchParams('tag=ts&tag=ai') },
  { id: 2, query: new URLSearchParams('q=docs') }
];

const fn = new PostFunctions(posts);
const filtered = fn.queryContainsValue('query', 'ai');
// filtered contains items whose query contains the value 'ai'

Remarks