lib/object.js
function flatten_object(obj, divider, level, flatten_arrays) {

		var divider_start,
		    divider_end,
		    new_key,
		    result = {},
		    temp,
		    key,
		    sub;

		if (level == null) {
			level = 0;
		}

		if (!divider) {
			divider_start = '.';
		} else if (typeof divider == 'string') {
			divider_start = divider;
		} else if (Array.isArray(divider)) {
			divider_start = divider[0];
			divider_end = divider[1];
		}

		if (flatten_arrays == null) {
			flatten_arrays = true;
		}

		for (key in obj) {

			// Only flatten own properties
			if (!obj.hasOwnProperty(key)) continue;

			if (Obj.isPlainObject(obj[key]) || (flatten_arrays && Array.isArray(obj[key]))) {
				temp = flatten_object(obj[key], divider, level + 1, flatten_arrays);

				// Inject the keys of the sub-object into the result
				for (sub in temp) {

					// Again: skip prototype properties
					if (!temp.hasOwnProperty(sub)) continue;

					if (divider_end) {
						new_key = key;

						// The root does not have an end divider:
						// For example: root[child]
						if (level) {
							new_key += divider_end;
						}

						new_key += divider_start + sub;

						// If we're back in the root,
						// make sure it has an ending divider
						if (!level) {
							new_key += divider_end;
						}

					} else {
						new_key = key + divider_start + sub;
					}

					result[new_key] = temp[sub];
				}
			} else if (Obj.isPrimitiveObject(obj[key])) {
				// Convert object form of primitives to their primitive values
				result[key] = obj[key].valueOf();
			} else {
				result[key] = obj[key];
			}
		}

		return result;
	}
function flatten_object(obj, divider, level, flatten_arrays) {

		var divider_start,
		    divider_end,
		    new_key,
		    result = {},
		    temp,
		    key,
		    sub;

		if (level == null) {
			level = 0;
		}

		if (!divider) {
			divider_start = '.';
		} else if (typeof divider == 'string') {
			divider_start = divider;
		} else if (Array.isArray(divider)) {
			divider_start = divider[0];
			divider_end = divider[1];
		}

		if (flatten_arrays == null) {
			flatten_arrays = true;
		}

		for (key in obj) {

			// Only flatten own properties
			if (!obj.hasOwnProperty(key)) continue;

			if (Obj.isPlainObject(obj[key]) || (flatten_arrays && Array.isArray(obj[key]))) {
				temp = flatten_object(obj[key], divider, level + 1, flatten_arrays);

				// Inject the keys of the sub-object into the result
				for (sub in temp) {

					// Again: skip prototype properties
					if (!temp.hasOwnProperty(sub)) continue;

					if (divider_end) {
						new_key = key;

						// The root does not have an end divider:
						// For example: root[child]
						if (level) {
							new_key += divider_end;
						}

						new_key += divider_start + sub;

						// If we're back in the root,
						// make sure it has an ending divider
						if (!level) {
							new_key += divider_end;
						}

					} else {
						new_key = key + divider_start + sub;
					}

					result[new_key] = temp[sub];
				}
			} else if (Obj.isPrimitiveObject(obj[key])) {
				// Convert object form of primitives to their primitive values
				result[key] = obj[key].valueOf();
			} else {
				result[key] = obj[key];
			}
		}

		return result;
	}
function flatten_object ( obj , divider , level , flatten_arrays ) { var divider_start , divider_end , new_key , result = { } , temp , key , sub ; if ( level == null ) { level = 0 ; } if ( ! divider ) { divider_start = '.' ; } else if ( typeof divider == 'string' ) { divider_start = divider ; } else if ( Array . isArray ( divider ) ) { divider_start = divider [ 0 ] ; divider_end = divider [ 1 ] ; } if ( flatten_arrays == null ) { flatten_arrays = true ; } for ( key in obj ) { // Only flatten own properties if ( ! obj . hasOwnProperty ( key ) ) continue ; if ( Obj . isPlainObject ( obj [ key ] ) || ( flatten_arrays && Array . isArray ( obj [ key ] ) ) ) { temp = flatten_object ( obj [ key ] , divider , level + 1 , flatten_arrays ) ; // Inject the keys of the sub-object into the result for ( sub in temp ) { // Again: skip prototype properties if ( ! temp . hasOwnProperty ( sub ) ) continue ; if ( divider_end ) { new_key = key ; // The root does not have an end divider: // For example: root[child] if ( level ) { new_key += divider_end ; } new_key += divider_start + sub ; // If we're back in the root, // make sure it has an ending divider if ( ! level ) { new_key += divider_end ; } } else { new_key = key + divider_start + sub ; } result [ new_key ] = temp [ sub ] ; } } else if ( Obj . isPrimitiveObject ( obj [ key ] ) ) { // Convert object form of primitives to their primitive values result [ key ] = obj [ key ] . valueOf ( ) ; } else { result [ key ] = obj [ key ] ; } } return result ; }
Flatten an object

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.2
@version  0.5.8

@param    {Object}         obj       The object to flatten
@param    {String|Array}   divider   The divider to use (.)
@param    {Number}         level
@param    {Boolean}        flatten_arrays   (true)

@return   {Object}
Flatten an object