packages/astro/test/test-utils.js
/**
 * Basic object merge utility. Returns new copy of merged Object.
 * @param {Object} a
 * @param {Object} b
 * @returns {Object}
 */
Basic object merge utility. Returns new copy of merged Object.
Basic object merge utility . Returns new copy of merged Object .
function merge(a, b) {
	const allKeys = new Set([...Object.keys(a), ...Object.keys(b)]);
	const c = {};
	for (const k of allKeys) {
		const needsObjectMerge =
			typeof a[k] === 'object' &&
			typeof b[k] === 'object' &&
			(Object.keys(a[k]).length || Object.keys(b[k]).length) &&
			!Array.isArray(a[k]) &&
			!Array.isArray(b[k]);
		if (needsObjectMerge) {
			c[k] = merge(a[k] || {}, b[k] || {});
			continue;
		}
		c[k] = a[k];
		if (b[k] !== undefined) c[k] = b[k];
	}
	return c;
}
function merge ( a , b ) { const allKeys = new Set ( [ ... Object . keys ( a ) , ... Object . keys ( b ) ] ) ; const c = { } ; for ( const k of allKeys ) { const needsObjectMerge = typeof a [ k ] === 'object' && typeof b [ k ] === 'object' && ( Object . keys ( a [ k ] ) . length || Object . keys ( b [ k ] ) . length ) && ! Array . isArray ( a [ k ] ) && ! Array . isArray ( b [ k ] ) ; if ( needsObjectMerge ) { c [ k ] = merge ( a [ k ] || { } , b [ k ] || { } ) ; continue ; } c [ k ] = a [ k ] ; if ( b [ k ] !== undefined ) c [ k ] = b [ k ] ; } return c ; }
Basic object merge utility.
Basic object merge utility .