• Filters the provided data by excluding the specified keys. This method will create a new object that contains all properties from the original data object except for those keys that are provided to be excluded. Additionally, it can also exclude properties with values of null or undefined if 'excludeNullUndefined' is set to true.

    Type Parameters

    • T extends object

      The type of the data object to filter, must be an object.

    Parameters

    • data: Readonly<T>

      The data object to be filtered.

    • keys: readonly (keyof T)[]

      The array of keys to exclude from the data object. (Can be empty)

    • excludeNullUndefined: boolean = false

      Flag to determine if properties with null or undefined values should be excluded.

    Returns T

    The filtered data object with the specified keys excluded. (T)

    (BasaltError) - Throws an error if the data is null or undefined. (CORE_DATA_KEY_ERROR.DATA_IS_NULL)

    (BasaltError) - Throws an error if the data is not a plain object. (CORE_DATA_KEY_ERROR.DATA_MUST_BE_OBJECT)

    const object = { test: 'test', exclude: 'exclude' };
    const filtered = filterByKeyExclusion(object, ['exclude']);
    console.log(filtered); // { test: 'test' }
    const object = { test: 'test', exclude: null };
    const filtered = filterByKeyExclusion(object, [], true);
    console.log(filtered); // { test: 'test' }