mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
Limit which changed props are included in update logs
This commit is contained in:
parent
70fb0b5baa
commit
82ca94e8c9
6 changed files with 64 additions and 13 deletions
|
@ -1,13 +1,16 @@
|
|||
type FilterResult<T> = {
|
||||
[K in keyof T]?: T[K];
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter an object's properties based on its values and keys
|
||||
* @return New object with filtered properties
|
||||
*/
|
||||
export function filterObject<T extends Record<string | number | symbol, unknown>>(
|
||||
export function filterObject<T>(
|
||||
object: T,
|
||||
filterFn: <K extends keyof T>(value: T[K], key: K) => boolean,
|
||||
): Record<keyof T, T[keyof T]> {
|
||||
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filterFn(value as any, key))) as Record<
|
||||
keyof T,
|
||||
T[keyof T]
|
||||
>;
|
||||
): FilterResult<T> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(object).filter(([key, value]) => filterFn(value as any, key as keyof T)),
|
||||
) as FilterResult<T>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue