collectype / factory/objects/objectKeys / objectKeysFactory
objectKeysFactory<
T,C>(ctx,oper): <K>(field,keys) =>C
Defined in: factory/objects/objectKeys.ts:40
Creates a predicate filter for object keys using PredicType.object.keys.
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.
ObjectKeysOper
The object keys operation (e.g., ‘containsAllKeys’, ‘containsAnyKey’, etc.).
Returns a function that takes a field (of type object on T) and a list of keys, and applies the object keys predicate to filter the context.
<
K>(field,keys):C
K extends string | number | symbol
K
string[] |
symbol[] |
C
// Example: Composing an object keys filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { objectKeysFactory } from 'collectype';
type Person = { name: string; meta: { country: string; city?: string } };
class PersonFunctions extends BaseFunctions<Person> {
objectContainsAllKeys = objectKeysFactory<Person, this>(this, 'containsAllKeys');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', meta: { country: 'FR', city: 'Paris' } },
{ name: 'Bob', meta: { country: 'US' } }
];
const fn = new PersonFunctions(people);
const filtered = fn.objectContainsAllKeys('meta', ['country', 'city']);
// filtered contains the items where 'meta' has all the keys ['country', 'city']