Function filterKeys

  • Filters the keys of an object based on provided options. Supports presets:

    Type Parameters

    • T extends IndexSignatureObject

      The type of the object.

    Parameters

    • obj: T

      The object to filter.

    • options: FilterOptions

      The options for filtering. Available presets: no-falsy, no-empty, no-null, no-undefined

    Returns Partial<T>

    • The filtered object.

    Example

    filterKeys({ a: 1, b: 2, c: 3 }, { filter: (key, value) => value === 2 })
    // returns { b: 2 }
    filterKeys({ a: 1, b: 2, c: 3 }, { filter: (key, value) => key === 'a' })
    // returns { a: 2 }
    filterKeys({ a: 1, b: 2, c: null }, { preset: 'no-null' })
    // returns { a: 2, b: 2 }