3
0
Fork 0
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:
Dragory 2021-09-05 23:46:40 +03:00
parent 70fb0b5baa
commit 82ca94e8c9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
6 changed files with 64 additions and 13 deletions

View file

@ -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>;
}