
"use strict";

var debug = require('nor-debug');
var ARRAY = require('nor-array');
var scan = require('./scan.js');
var merge = require('./merge.js');

/** Scan document for same partial objects and merge them
 * @param doc {object} The document to expand
 * @returns {object} The expanded copy of document
 */
module.exports = function expand_objects(doc) {
	debug.assert(doc).is('object');
	doc = JSON.parse(JSON.stringify(doc));
	var cache = scan(doc);
	ARRAY(Object.keys(cache)).forEach(function(key) {
		merge(cache[key]);
	});
	return doc;
};

/* EOF */

@@ -250,16 +250,144 @@
  expand%0A
+ * @param opts %7Bobject%7D The options (optional)%0A * @param opts.inplace %7Bobject%7D Expand document inplace. Does not make new copy.%0A
  * @retu
@@ -477,16 +477,22 @@
 ects(doc
+, opts
 ) %7B%0A%09deb
@@ -520,16 +520,135 @@
 ject');%0A
+%09opts = opts %7C%7C %7B%7D;%0A%09debug.assert(opts).is('object');%0A%0A%09var _inplace = opts.inplace ? true : false;%0A%0A%09if(!_inplace) %7B%0A%09
 %09doc = J
@@ -679,16 +679,20 @@
 (doc));%0A
+%09%7D%0A%0A
 %09var cac

Support for inplace expanding