lib/packages/core-classes.js
function(data, padding) {

		var tempResult = [],
			child_padding = padding + "\t",
			name,
			type,
			result,
			is_complex = false,
			only_key = null,
			is_empty = true;

		// this may be faster than using Object.keys(data), but I haven't done speed comparison yet.
		// Purpose of the following code:
		// 1) if object has something in it then 'is_empty' will be set to false
		// 2) if there is only one property in it, then 'only_key' will contain it's name
		for (name in data) {
			if (only_key !== null) { // strict comparison - in case the key is valid, but evaluates to false
				only_key = null;
				break;
			}
			is_empty = false;
			only_key = name;
		}

		if (only_key) {

			type = Firestorm.getType(data[only_key]);

			if (type in this._complex_types) {
				is_complex = true;
			}

		}

		if (is_empty) {

			result = '{}';

		} else if (only_key && !is_complex) {

			// simple values can be written in one line
			result = '{' + this._serializeObjectProperty(only_key, data[only_key], child_padding) + '}';

		} else {

			for (name in data) {

				tempResult.push(
					this._serializeObjectProperty(name, data[name], child_padding)
				);

			}

			result = '{' + "\n\t" + padding + tempResult.join(",\n\t" + padding) + "\n" + padding + '}';

		}

		return result;

	}
function(data, padding) {

		var tempResult = [],
			child_padding = padding + "\t",
			name,
			type,
			result,
			is_complex = false,
			only_key = null,
			is_empty = true;

		// this may be faster than using Object.keys(data), but I haven't done speed comparison yet.
		// Purpose of the following code:
		// 1) if object has something in it then 'is_empty' will be set to false
		// 2) if there is only one property in it, then 'only_key' will contain it's name
		for (name in data) {
			if (only_key !== null) { // strict comparison - in case the key is valid, but evaluates to false
				only_key = null;
				break;
			}
			is_empty = false;
			only_key = name;
		}

		if (only_key) {

			type = Firestorm.getType(data[only_key]);

			if (type in this._complex_types) {
				is_complex = true;
			}

		}

		if (is_empty) {

			result = '{}';

		} else if (only_key && !is_complex) {

			// simple values can be written in one line
			result = '{' + this._serializeObjectProperty(only_key, data[only_key], child_padding) + '}';

		} else {

			for (name in data) {

				tempResult.push(
					this._serializeObjectProperty(name, data[name], child_padding)
				);

			}

			result = '{' + "\n\t" + padding + tempResult.join(",\n\t" + padding) + "\n" + padding + '}';

		}

		return result;

	}
function ( data , padding ) { var tempResult = [ ] , child_padding = padding + "\t" , name , type , result , is_complex = false , only_key = null , is_empty = true ; // this may be faster than using Object.keys(data), but I haven't done speed comparison yet. // Purpose of the following code: // 1) if object has something in it then 'is_empty' will be set to false // 2) if there is only one property in it, then 'only_key' will contain it's name for ( name in data ) { if ( only_key !== null ) { // strict comparison - in case the key is valid, but evaluates to false only_key = null ; break ; } is_empty = false ; only_key = name ; } if ( only_key ) { type = Firestorm . getType ( data [ only_key ] ) ; if ( type in this . _complex_types ) { is_complex = true ; } } if ( is_empty ) { result = '{}' ; } else if ( only_key && ! is_complex ) { // simple values can be written in one line result = '{' + this . _serializeObjectProperty ( only_key , data [ only_key ] , child_padding ) + '}' ; } else { for ( name in data ) { tempResult . push ( this . _serializeObjectProperty ( name , data [ name ] , child_padding ) ) ; } result = '{' + "\n\t" + padding + tempResult . join ( ",\n\t" + padding ) + "\n" + padding + '}' ; } return result ; }
Serialize an object
@param {Object} data
@param {string} padding
@returns {string}
Serialize an object