lib/json-dry.js
function regenerate(root, holder, current, seen, retrieve, undry_paths, old, current_path) {

	var temp;

	if (current && typeof current == 'object') {
		// Remember this object has been regenerated already
		seen.set(current, true);

		if (current instanceof Array) {
			return regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path);
		}

		if (current instanceof String) {

			if (current.length > -1) {
				current = current.toString();

				if (temp = undry_paths.get(current)) {
					if (typeof temp.undried != 'undefined') {
						return temp.undried;
					}

					if (!holder) {
						throw new Error('Unable to resolve recursive reference');
					}

					undry_paths.extra_pass.push([holder, temp, current_path]);

					return temp;
				}

				if (retrieve.hasOwnProperty(current)) {
					temp = retrieve[current];
				} else {
					temp = retrieve[current] = retrieveFromPath(root, current.split(special_char));

					if (typeof temp == 'undefined') {
						temp = retrieve[current] = getFromOld(old, current.split(special_char));
					}
				}

				// Because we always regenerate parsed objects first
				// (JSON-dry parsing goes from string » object » regenerated object)
				// keys of regular objects can appear out-of-order, so we need to parse them
				if (temp && temp instanceof String) {
					// Unset the String as a valid result
					retrieve[current] = null;

					// Regenerate the string again
					// (We have to create a new instance, because it's already been "seen")
					temp = retrieve[current] = regenerate(root, holder, new String(temp), seen, retrieve, undry_paths, old, current_path);
				}

				return temp;
			} else {
				return root;
			}
		}

		return regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path);
	}

	return current;
}
function regenerate(root, holder, current, seen, retrieve, undry_paths, old, current_path) {

	var temp;

	if (current && typeof current == 'object') {
		// Remember this object has been regenerated already
		seen.set(current, true);

		if (current instanceof Array) {
			return regenerateArray(root, holder, current, seen, retrieve, undry_paths, old, current_path);
		}

		if (current instanceof String) {

			if (current.length > -1) {
				current = current.toString();

				if (temp = undry_paths.get(current)) {
					if (typeof temp.undried != 'undefined') {
						return temp.undried;
					}

					if (!holder) {
						throw new Error('Unable to resolve recursive reference');
					}

					undry_paths.extra_pass.push([holder, temp, current_path]);

					return temp;
				}

				if (retrieve.hasOwnProperty(current)) {
					temp = retrieve[current];
				} else {
					temp = retrieve[current] = retrieveFromPath(root, current.split(special_char));

					if (typeof temp == 'undefined') {
						temp = retrieve[current] = getFromOld(old, current.split(special_char));
					}
				}

				// Because we always regenerate parsed objects first
				// (JSON-dry parsing goes from string » object » regenerated object)
				// keys of regular objects can appear out-of-order, so we need to parse them
				if (temp && temp instanceof String) {
					// Unset the String as a valid result
					retrieve[current] = null;

					// Regenerate the string again
					// (We have to create a new instance, because it's already been "seen")
					temp = retrieve[current] = regenerate(root, holder, new String(temp), seen, retrieve, undry_paths, old, current_path);
				}

				return temp;
			} else {
				return root;
			}
		}

		return regenerateObject(root, holder, current, seen, retrieve, undry_paths, old, current_path);
	}

	return current;
}
function regenerate ( root , holder , current , seen , retrieve , undry_paths , old , current_path ) { var temp ; if ( current && typeof current == 'object' ) { // Remember this object has been regenerated already seen . set ( current , true ) ; if ( current instanceof Array ) { return regenerateArray ( root , holder , current , seen , retrieve , undry_paths , old , current_path ) ; } if ( current instanceof String ) { if ( current . length > - 1 ) { current = current . toString ( ) ; if ( temp = undry_paths . get ( current ) ) { if ( typeof temp . undried != 'undefined' ) { return temp . undried ; } if ( ! holder ) { throw new Error ( 'Unable to resolve recursive reference' ) ; } undry_paths . extra_pass . push ( [ holder , temp , current_path ] ) ; return temp ; } if ( retrieve . hasOwnProperty ( current ) ) { temp = retrieve [ current ] ; } else { temp = retrieve [ current ] = retrieveFromPath ( root , current . split ( special_char ) ) ; if ( typeof temp == 'undefined' ) { temp = retrieve [ current ] = getFromOld ( old , current . split ( special_char ) ) ; } } // Because we always regenerate parsed objects first // (JSON-dry parsing goes from string » object » regenerated object) // keys of regular objects can appear out-of-order, so we need to parse them if ( temp && temp instanceof String ) { // Unset the String as a valid result retrieve [ current ] = null ; // Regenerate the string again // (We have to create a new instance, because it's already been "seen") temp = retrieve [ current ] = regenerate ( root , holder , new String ( temp ) , seen , retrieve , undry_paths , old , current_path ) ; } return temp ; } else { return root ; } } return regenerateObject ( root , holder , current , seen , retrieve , undry_paths , old , current_path ) ; } return current ; }
Regenerate a value

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.4
@version  1.0.8

@return   {Mixed}
Regenerate a value