oidc-provider
Version:
OAuth 2.0 Authorization Server implementation for Node.js with OpenID Connect
26 lines (21 loc) • 624 B
JavaScript
/* eslint-disable no-param-reassign, no-continue */
import isPlainObject from './is_plain_object.js';
function merge(target, ...sources) {
for (const source of sources) {
if (!isPlainObject(source)) {
continue;
}
for (const [key, value] of Object.entries(source)) {
if (key === '__proto__' || key === 'constructor') {
continue;
}
if (isPlainObject(target[key]) && isPlainObject(value)) {
target[key] = merge(target[key], value);
} else if (typeof value !== 'undefined') {
target[key] = value;
}
}
}
return target;
}
export default merge;