Function filterWithKey

  • The same concept as Array.filter(), but for object keys

    Example

    import * as P from "flurp/pojo";

    const moreThanTwoChars = P.filterWithKey<Record<string, string>>((s: string) => s.length > 2);
    moreThanTwoChars({ x: 3, yy: -4, zzz: 5 }); // { zzz: 5 }

    const keyEqualsValue = P.filterWithKey<Record<string, string>>((k: string, v: string) => k === v);
    keyEqualsValue({ x: "x", y: "weasel", z: "z" }) // { x: "x", z: "z" }

    Type Parameters

    • T extends Readonly<Record<string, unknown>>

    Parameters

    • condition: ((k: string, v: T[keyof T]) => boolean)
        • (k: string, v: T[keyof T]): boolean
        • Parameters

          • k: string
          • v: T[keyof T]

          Returns boolean

    Returns ((obj: T) => Record<string, unknown>)

      • (obj: T): Record<string, unknown>
      • Parameters

        • obj: T

        Returns Record<string, unknown>