vevet
Version:
Vevet is a JavaScript library for creative development that simplifies crafting rich interactions like split text animations, carousels, marquees, preloading, and more.
21 lines (18 loc) • 468 B
text/typescript
export function mergeWithNoUndefined<
S extends Record<string, any>,
A extends Record<string, any>,
>(source: S, add: A) {
const addKeys = Object.keys(add) as (keyof A)[];
const addNonUndefinedKeys = addKeys.filter((key) => add[key] !== undefined);
const newAdd = addNonUndefinedKeys.reduce(
(acc, key) => {
acc[key] = add[key];
return acc;
},
{} as Record<keyof A, A[keyof A]>,
);
return {
...source,
...newAdd,
};
}