lib/json-dry.js
function generateReviver(reviver, undry_paths) {

	return function dryReviver(key, value) {

		var val_type = typeof value,
		    constructor,
		    temp;

		if (val_type === 'string') {
			if (value[0] === special_char) {
				// This is actually a path that needs to be replaced.
				// Put in a String object for now
				return new String(value.slice(1));
			} else if (value[0] == '\\' && value[1] == 'x' && value[2] == '7' && value[3] == 'e') {
				value = special_char + value.slice(4);
			}
		} else if (value && value.dry != null) {

			switch (value.dry) {

				case 'date':
					if (value.value) {
						return new Date(value.value);
					}
					break;

				case 'regexp':
					if (value.value) {
						return RegExp.apply(undefined, get_regex.exec(value.value).slice(1));
					}
					break;

				case '+Infinity':
					return Infinity;

				case '-Infinity':
					return -Infinity;

				case 'toDry':
					constructor = findClass(value);

					// Undry this element, but don't put it in the parsed object yet
					if (constructor && typeof constructor.unDry === 'function') {
						value.unDryConstructor = constructor;
					} else {
						value.undried = value.value;
					}

					if (value.drypath) {
						undry_paths.set(value.drypath.join(special_char), value);
					} else {
						return value.undried;
					}
					break;

				default:
					if (typeof value.value !== 'undefined') {
						if (undriers[value.dry]) {
							value.unDryFunction = undriers[value.dry].fnc;

							if (!value.drypath) {
								// No path given? Then do the undrying right now
								value.undried = value.unDryFunction(this, key, value.value)
							}

						} else {
							value.undried = value.value;
						}

						if (value.drypath) {
							undry_paths.set(value.drypath.join(special_char), value);
						} else {
							return value.undried;
						}
					}
			}
		}

		if (reviver == null) {
			return value;
		}

		return reviver.call(this, key, value);
	};
}
function generateReviver(reviver, undry_paths) {

	return function dryReviver(key, value) {

		var val_type = typeof value,
		    constructor,
		    temp;

		if (val_type === 'string') {
			if (value[0] === special_char) {
				// This is actually a path that needs to be replaced.
				// Put in a String object for now
				return new String(value.slice(1));
			} else if (value[0] == '\\' && value[1] == 'x' && value[2] == '7' && value[3] == 'e') {
				value = special_char + value.slice(4);
			}
		} else if (value && value.dry != null) {

			switch (value.dry) {

				case 'date':
					if (value.value) {
						return new Date(value.value);
					}
					break;

				case 'regexp':
					if (value.value) {
						return RegExp.apply(undefined, get_regex.exec(value.value).slice(1));
					}
					break;

				case '+Infinity':
					return Infinity;

				case '-Infinity':
					return -Infinity;

				case 'toDry':
					constructor = findClass(value);

					// Undry this element, but don't put it in the parsed object yet
					if (constructor && typeof constructor.unDry === 'function') {
						value.unDryConstructor = constructor;
					} else {
						value.undried = value.value;
					}

					if (value.drypath) {
						undry_paths.set(value.drypath.join(special_char), value);
					} else {
						return value.undried;
					}
					break;

				default:
					if (typeof value.value !== 'undefined') {
						if (undriers[value.dry]) {
							value.unDryFunction = undriers[value.dry].fnc;

							if (!value.drypath) {
								// No path given? Then do the undrying right now
								value.undried = value.unDryFunction(this, key, value.value)
							}

						} else {
							value.undried = value.value;
						}

						if (value.drypath) {
							undry_paths.set(value.drypath.join(special_char), value);
						} else {
							return value.undried;
						}
					}
			}
		}

		if (reviver == null) {
			return value;
		}

		return reviver.call(this, key, value);
	};
}
function generateReviver ( reviver , undry_paths ) { return function dryReviver ( key , value ) { var val_type = typeof value , constructor , temp ; if ( val_type === 'string' ) { if ( value [ 0 ] === special_char ) { // This is actually a path that needs to be replaced. // Put in a String object for now return new String ( value . slice ( 1 ) ) ; } else if ( value [ 0 ] == '\\' && value [ 1 ] == 'x' && value [ 2 ] == '7' && value [ 3 ] == 'e' ) { value = special_char + value . slice ( 4 ) ; } } else if ( value && value . dry != null ) { switch ( value . dry ) { case 'date' : if ( value . value ) { return new Date ( value . value ) ; } break ; case 'regexp' : if ( value . value ) { return RegExp . apply ( undefined , get_regex . exec ( value . value ) . slice ( 1 ) ) ; } break ; case '+Infinity' : return Infinity ; case '-Infinity' : return - Infinity ; case 'toDry' : constructor = findClass ( value ) ; // Undry this element, but don't put it in the parsed object yet if ( constructor && typeof constructor . unDry === 'function' ) { value . unDryConstructor = constructor ; } else { value . undried = value . value ; } if ( value . drypath ) { undry_paths . set ( value . drypath . join ( special_char ) , value ) ; } else { return value . undried ; } break ; default : if ( typeof value . value !== 'undefined' ) { if ( undriers [ value . dry ] ) { value . unDryFunction = undriers [ value . dry ] . fnc ; if ( ! value . drypath ) { // No path given? Then do the undrying right now value . undried = value . unDryFunction ( this , key , value . value ) } } else { value . undried = value . value ; } if ( value . drypath ) { undry_paths . set ( value . drypath . join ( special_char ) , value ) ; } else { return value . undried ; } } } } if ( reviver == null ) { return value ; } return reviver . call ( this , key , value ) ; } ; }
Generate reviver function

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.0
@version  1.0.2

@param    {Function}   reviver
@param    {Map}        undry_paths

@return   {Function}
Generate reviver function