collectype / factory/strings/stringComparison / stringComparisonFactory
stringComparisonFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/strings/stringComparison.ts:40
Creates a predicate filter for string comparison using PredicType.string.comparison.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
StringComparisonOper
The string comparison operation to perform (see PredicType.string.comparison).
Returns a function that takes a field (of type string on T) and a target string, and applies the string comparison predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
string
C
// Example: Composing a string comparison filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { stringComparisonFactory } from 'collectype';
type Person = { name: string; city: string };
class PersonFunctions extends BaseFunctions<Person> {
stringEquals = stringComparisonFactory<Person, this>(this, 'eq');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', city: 'Paris' },
{ name: 'Bob', city: 'Lyon' },
{ name: 'Eve', city: 'Paris' }
];
const fn = new PersonFunctions(people);
const filtered = fn.stringEquals('city', 'Paris');
// filtered contains the items where 'city' is equal to 'Paris'
PredicType.string.comparison for string comparison on string fields.