collectype

collectype v0.13.0


collectype / factory/urls/urlHref / urlHrefFactory

Function: urlHrefFactory()

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

Defined in: factory/urls/urlHref.ts:34

Creates a predicate filter for URL href comparison using PredicType.url.href.

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

UrlHrefOper

The URL href operation to perform.

Returns

Returns a function that takes a URL field on T, compares its href, and filters the context.

<K>(field, target) => C

Example

// Example based on sample/models/Person and sample/data/person
import { BaseFunctions, urlHrefFactory } from 'collectype';
import { Person } from '../../../sample/models/Person';
import { people } from '../../../sample/data/person';

class PersonFunctions extends BaseFunctions<Person> {
  urlHrefIncludes = urlHrefFactory<Person, this>(this, 'includes');
}

const fn = new PersonFunctions(people);
const filtered = fn.urlHrefIncludes('website', 'example.test/people');
// filtered contains people whose website href includes the expected path segment

Remarks