all files / src/ merge.ts

100% Statements 14/14
100% Branches 7/7
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14  29× 49× 25× 25× 31× 29× 20×     24×    
// a simple object merge function implementation
const isobj = x => typeof x === 'object' && !Array.isArray(x) && x !== null
function merge(obj1: object, ...objs: object[]) {
	for (const obj2 of objs) {
		for (const k in obj2) {
			if (!obj2.hasOwnProperty(k)) continue
			if (isobj(obj2[k])) merge(obj1[k], obj2[k])
			else obj1[k] = obj2[k]
		}
	}
	return obj1
}
export default merge