archive/v1/format.js
function formatValue(value) {
		
		var out;
		var type = util.sType(value);
		
		// if there is a type, check all sub items for types
		if (_.has(value, 'attributes.type') && _.has(value, '$value') && _.keys(value).length === 2) {
			out = util.moRef(value);
		}
		else if (type) {
			if (util.isArray(value)) {
				out = [];
				
				var subtype = type;
				
				if (subtype.match(/^ArrayOf/)) {
					subtype = subtype.replace(/^ArrayOf/, '');

					if (!Array.isArray(_.get(value, subtype)) && value[subtype]) {
						value[subtype] = [value[subtype]];
					}
				}
				
				_.forEach(value[_.keys(value)[1]], function(obj) {
					out.push(formatValue(obj));
				});
			}
			else if (util.isBoolean(value)) {
				
				// check for valid true values, otherwise false
				if (_.includes(['1', 'true'], _.lowerCase(value.$value))) {
					out = true;
				}
				else {
					out = false;
				}
			}
			else if (util.isInt(value)) {
				out = Number(value.$value);
			}
			else if (_.has(value, '$value')) {
				out = value.$value;
			}
			else {
				out = formatValue(_.omit(value, 'attributes'));
			}
			
		}
		else if (Array.isArray(value)) {
			out = [];
			_.forEach(value, function(val) {
				if (util.sType(val) || util.isArray(val) || util.hasKeys(val)) {
					out.push(formatValue(val));
				}
				else {
					out.push(cast(val));
				}
			});
		}
		else if (util.hasKeys(value)) {
			out = {};
			_.forEach(value, function(val, key) {
				if (util.sType(val) || util.isArray(val) || util.hasKeys(val)) {
					out[key] = formatValue(val);
				}
				else {
					out[key] = cast(val);
				}
			});
		}
		else {
			out = cast(value);
		}
		return out;
	}
function formatValue(value) {
		
		var out;
		var type = util.sType(value);
		
		// if there is a type, check all sub items for types
		if (_.has(value, 'attributes.type') && _.has(value, '$value') && _.keys(value).length === 2) {
			out = util.moRef(value);
		}
		else if (type) {
			if (util.isArray(value)) {
				out = [];
				
				var subtype = type;
				
				if (subtype.match(/^ArrayOf/)) {
					subtype = subtype.replace(/^ArrayOf/, '');

					if (!Array.isArray(_.get(value, subtype)) && value[subtype]) {
						value[subtype] = [value[subtype]];
					}
				}
				
				_.forEach(value[_.keys(value)[1]], function(obj) {
					out.push(formatValue(obj));
				});
			}
			else if (util.isBoolean(value)) {
				
				// check for valid true values, otherwise false
				if (_.includes(['1', 'true'], _.lowerCase(value.$value))) {
					out = true;
				}
				else {
					out = false;
				}
			}
			else if (util.isInt(value)) {
				out = Number(value.$value);
			}
			else if (_.has(value, '$value')) {
				out = value.$value;
			}
			else {
				out = formatValue(_.omit(value, 'attributes'));
			}
			
		}
		else if (Array.isArray(value)) {
			out = [];
			_.forEach(value, function(val) {
				if (util.sType(val) || util.isArray(val) || util.hasKeys(val)) {
					out.push(formatValue(val));
				}
				else {
					out.push(cast(val));
				}
			});
		}
		else if (util.hasKeys(value)) {
			out = {};
			_.forEach(value, function(val, key) {
				if (util.sType(val) || util.isArray(val) || util.hasKeys(val)) {
					out[key] = formatValue(val);
				}
				else {
					out[key] = cast(val);
				}
			});
		}
		else {
			out = cast(value);
		}
		return out;
	}
function formatValue ( value ) { var out ; var type = util . sType ( value ) ; // if there is a type, check all sub items for types if ( _ . has ( value , 'attributes.type' ) && _ . has ( value , '$value' ) && _ . keys ( value ) . length === 2 ) { out = util . moRef ( value ) ; } else if ( type ) { if ( util . isArray ( value ) ) { out = [ ] ; var subtype = type ; if ( subtype . match ( / ^ArrayOf / ) ) { subtype = subtype . replace ( / ^ArrayOf / , '' ) ; if ( ! Array . isArray ( _ . get ( value , subtype ) ) && value [ subtype ] ) { value [ subtype ] = [ value [ subtype ] ] ; } } _ . forEach ( value [ _ . keys ( value ) [ 1 ] ] , function ( obj ) { out . push ( formatValue ( obj ) ) ; } ) ; } else if ( util . isBoolean ( value ) ) { // check for valid true values, otherwise false if ( _ . includes ( [ '1' , 'true' ] , _ . lowerCase ( value . $value ) ) ) { out = true ; } else { out = false ; } } else if ( util . isInt ( value ) ) { out = Number ( value . $value ) ; } else if ( _ . has ( value , '$value' ) ) { out = value . $value ; } else { out = formatValue ( _ . omit ( value , 'attributes' ) ) ; } } else if ( Array . isArray ( value ) ) { out = [ ] ; _ . forEach ( value , function ( val ) { if ( util . sType ( val ) || util . isArray ( val ) || util . hasKeys ( val ) ) { out . push ( formatValue ( val ) ) ; } else { out . push ( cast ( val ) ) ; } } ) ; } else if ( util . hasKeys ( value ) ) { out = { } ; _ . forEach ( value , function ( val , key ) { if ( util . sType ( val ) || util . isArray ( val ) || util . hasKeys ( val ) ) { out [ key ] = formatValue ( val ) ; } else { out [ key ] = cast ( val ) ; } } ) ; } else { out = cast ( value ) ; } return out ; }
recursive formatting function
recursive formatting function