lib/record-patch-builder.js
function buildMergeLevel(basePtr, levelMergePatch, jsonPatch) {

	for (let propName in levelMergePatch) {
		const mergeVal = levelMergePatch[propName];
		const path = basePtr + '/' + propName;
		if (mergeVal === null) {
			jsonPatch.push({
				op: 'remove',
				path: path
			});
		} else if (Array.isArray(mergeVal)) {
			jsonPatch.push({
				op: 'replace',
				path: path,
				value: mergeVal
			});
		} else if ((typeof mergeVal) === 'object') {
			const nestedPatch = new Array();
			buildMergeLevel(path, mergeVal, nestedPatch);
			jsonPatch.push({
				op: 'merge',
				path: path,
				value: mergeVal,
				patch: nestedPatch
			});
		} else {
			jsonPatch.push({
				op: 'replace',
				path: path,
				value: mergeVal
			});
		}
	}
}
function buildMergeLevel(basePtr, levelMergePatch, jsonPatch) {

	for (let propName in levelMergePatch) {
		const mergeVal = levelMergePatch[propName];
		const path = basePtr + '/' + propName;
		if (mergeVal === null) {
			jsonPatch.push({
				op: 'remove',
				path: path
			});
		} else if (Array.isArray(mergeVal)) {
			jsonPatch.push({
				op: 'replace',
				path: path,
				value: mergeVal
			});
		} else if ((typeof mergeVal) === 'object') {
			const nestedPatch = new Array();
			buildMergeLevel(path, mergeVal, nestedPatch);
			jsonPatch.push({
				op: 'merge',
				path: path,
				value: mergeVal,
				patch: nestedPatch
			});
		} else {
			jsonPatch.push({
				op: 'replace',
				path: path,
				value: mergeVal
			});
		}
	}
}
function buildMergeLevel ( basePtr , levelMergePatch , jsonPatch ) { for ( let propName in levelMergePatch ) { const mergeVal = levelMergePatch [ propName ] ; const path = basePtr + '/' + propName ; if ( mergeVal === null ) { jsonPatch . push ( { op : 'remove' , path : path } ) ; } else if ( Array . isArray ( mergeVal ) ) { jsonPatch . push ( { op : 'replace' , path : path , value : mergeVal } ) ; } else if ( ( typeof mergeVal ) === 'object' ) { const nestedPatch = new Array ( ) ; buildMergeLevel ( path , mergeVal , nestedPatch ) ; jsonPatch . push ( { op : 'merge' , path : path , value : mergeVal , patch : nestedPatch } ) ; } else { jsonPatch . push ( { op : 'replace' , path : path , value : mergeVal } ) ; } } }
Recusrively build JSON patch from Merge patch's nesting level.

@private
@param {string} basePtr Base JSON pointer for the nesting level.
@param {Object} levelMergePatch Nested Merge patch for the level.
@param {Array.<Object>} jsonPatch Resulting JSON patch specification array.
Recusrively build JSON patch from Merge patch s nesting level .