lib/json-dry.js
function createDryReplacer(root, replacer) {

	var value_paths = new WeakMap(),
	    seen_path,
	    flags = {is_root: true},
	    chain = [],
	    path = [],
	    temp,
	    last,
	    len;

	return function dryReplacer(holder, key, value) {

		// Process the value to a possible given replacer function
		if (replacer != null) {
			value = replacer.call(holder, key, value);
		}

		// All falsy values can be returned as-is
		if (!value) {
			return value;
		}

		let is_wrap;

		// An explicitly false key means this dryReplaced was
		// recursively called with a replacement object
		if (key === false) {
			key = '';
			is_wrap = true;

			// Wrappers get added to the object chain, but not the path
			// We need to be able to identify them later on
			holder.__is_wrap = true;

			// See if the wrapped value is an object
			if (holder[''] != null && typeof holder[''] === 'object') {
				holder.__is_object = true;
			}
		}

		switch (typeof value) {

			case 'function':
				// If no drier is created, return now.
				// Else: fall through
				if (!driers.Function) {
					return;
				}

			case 'object':
				value = replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key);
				break;

			case 'string':
				// Make sure regular strings don't start with the path delimiter
				if (!flags.is_root && value[0] == '~') {
					value = safe_special_char + value.slice(1);
				}

				break;

			case 'number':
				// Allow infinite values
				if (value && !isFinite(value)) {
					if (value > 0) {
						value = {dry: '+Infinity'};
					} else {
						value = {dry: '-Infinity'};
					}
				}
				break;
		}

		return value;
	}
}
function createDryReplacer(root, replacer) {

	var value_paths = new WeakMap(),
	    seen_path,
	    flags = {is_root: true},
	    chain = [],
	    path = [],
	    temp,
	    last,
	    len;

	return function dryReplacer(holder, key, value) {

		// Process the value to a possible given replacer function
		if (replacer != null) {
			value = replacer.call(holder, key, value);
		}

		// All falsy values can be returned as-is
		if (!value) {
			return value;
		}

		let is_wrap;

		// An explicitly false key means this dryReplaced was
		// recursively called with a replacement object
		if (key === false) {
			key = '';
			is_wrap = true;

			// Wrappers get added to the object chain, but not the path
			// We need to be able to identify them later on
			holder.__is_wrap = true;

			// See if the wrapped value is an object
			if (holder[''] != null && typeof holder[''] === 'object') {
				holder.__is_object = true;
			}
		}

		switch (typeof value) {

			case 'function':
				// If no drier is created, return now.
				// Else: fall through
				if (!driers.Function) {
					return;
				}

			case 'object':
				value = replaceObject(dryReplacer, value, chain, flags, is_wrap, holder, path, value_paths, key);
				break;

			case 'string':
				// Make sure regular strings don't start with the path delimiter
				if (!flags.is_root && value[0] == '~') {
					value = safe_special_char + value.slice(1);
				}

				break;

			case 'number':
				// Allow infinite values
				if (value && !isFinite(value)) {
					if (value > 0) {
						value = {dry: '+Infinity'};
					} else {
						value = {dry: '-Infinity'};
					}
				}
				break;
		}

		return value;
	}
}
function createDryReplacer ( root , replacer ) { var value_paths = new WeakMap ( ) , seen_path , flags = { is_root : true } , chain = [ ] , path = [ ] , temp , last , len ; return function dryReplacer ( holder , key , value ) { // Process the value to a possible given replacer function if ( replacer != null ) { value = replacer . call ( holder , key , value ) ; } // All falsy values can be returned as-is if ( ! value ) { return value ; } let is_wrap ; // An explicitly false key means this dryReplaced was // recursively called with a replacement object if ( key === false ) { key = '' ; is_wrap = true ; // Wrappers get added to the object chain, but not the path // We need to be able to identify them later on holder . __is_wrap = true ; // See if the wrapped value is an object if ( holder [ '' ] != null && typeof holder [ '' ] === 'object' ) { holder . __is_object = true ; } } switch ( typeof value ) { case 'function' : // If no drier is created, return now. // Else: fall through if ( ! driers . Function ) { return ; } case 'object' : value = replaceObject ( dryReplacer , value , chain , flags , is_wrap , holder , path , value_paths , key ) ; break ; case 'string' : // Make sure regular strings don't start with the path delimiter if ( ! flags . is_root && value [ 0 ] == '~' ) { value = safe_special_char + value . slice ( 1 ) ; } break ; case 'number' : // Allow infinite values if ( value && ! isFinite ( value ) ) { if ( value > 0 ) { value = { dry : '+Infinity' } ; } else { value = { dry : '-Infinity' } ; } } break ; } return value ; } }
Generate a replacer function

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

@param    {Object}   root
@param    {Function} replacer

@return   {Function}
Generate a replacer function