API reference@evolu/commonObject › filterObjectKeys

function filterObjectKeys<T>(
  source: T,
  predicate: (key: string) => boolean,
): Readonly<Partial<Pick<T, Exclude<keyof T, symbol>>>>;

Defined in: packages/common/src/Object.ts:277

Selects own string-keyed properties while preserving their descriptors.

Visits enumerable and non-enumerable properties, ignoring inherited and symbol properties. The predicate receives only the key; property values and getters are never read. The result is a new ordinary object with matching descriptors, including accessor functions and property flags. Declared properties are optional because the predicate may exclude any of them. Numeric property names are visited as strings.

Example

import { assertEqual, assertType, filterObjectKeys } from "@evolu/common";

const source = { APP_PORT: "4000", HOME: "/home/evolu" };
const selected = filterObjectKeys(source, (key) => key.startsWith("APP_"));

assertEqual(selected, { APP_PORT: "4000" });
assertType<
  typeof selected,
  { readonly APP_PORT?: string; readonly HOME?: string }
>();