@wesjet/function.js
Version:
wesjet javascript library
31 lines (30 loc) • 913 B
JavaScript
/**
* Copyright (c) Wesbitty, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
export * from './omit.js';
export * from './pick.js';
export const mapObjectValues = (obj, mapValue) => {
const mappedEntries = Object.entries(obj).map(([key, val]) => [key, mapValue(key, val)]);
return Object.fromEntries(mappedEntries);
};
export const mergeDeep = (...objs) => {
const result = {};
for (const obj of objs) {
for (const [key, val] of Object.entries(obj)) {
if (val && typeof val === 'object' && !Array.isArray(val)) {
// @ts-expect-error TODO
result[key] = mergeDeep(result[key] || {}, val);
}
else {
// @ts-expect-error TODO
result[key] = val;
}
}
}
return result;
};