function convertToText( obj, spaces ){

    if ( obj === window ) {
        // don't be cray-cray
        return false
    }

    var string = '',
        part = [],
        prop,
        len = 0,
        i = -1;

    // is string - skip all other tests
    if ( typeof obj == 'string' ) {
        string += obj;
    }
    // is object
    else if ( Object.prototype.toString.call(obj) === '[object Object]' ) {
        for ( prop in obj ) {
            // should we filter the properties?
            //if ( obj.hasOwnProperty(prop) ){
            part.push(prop + ': ' + convertToText(obj[prop], spaces));
            //}
        }
        string += ' { ' + part.join(', ') + ' } ';
    }
    // is array
    else if ( Array.isArray(obj) ) {
        len = obj.length;
        while ( ++i < len ) {
            part.push(convertToText(obj[i], spaces));
        }
        string += ' [ ' + part.join(', ') + ' ]';
    }
    // is function
    else if ( typeof obj == 'function' ) {
        string += obj.toString();
    }
    //all other values can be done with JSON.stringify
    else {
        string += JSON.stringify(obj);
    }

    // strip spaces by default and also if (spaces !== true)
    if ( typeof spaces == 'undefined' || spaces.toString().toLowerCase() !== 'true' ) {
        return string.replace(/\s/g, '');
    }
    // only keep spaces if (spaces === true)
    else {
        return string;
    }
}
/*!
 * Convert an object to a string, for whatever reason.
 * This can be useful for heavy-handed comparison
 * (as in compareByText() function below),
 * or printing out JavaScript objects or functions.
 *
 * Original source:
 * http://stackoverflow.com/questions/5612787/converting-an-object-to-a-string
 * ('extra' comma issue has been resolved in the code below)
 *
 * https://gist.github.com/Error601/d9623b836458b5b6fe86
 */
Convert an object to a string, for whatever reason.
This can be useful for heavy-handed comparison
(as in compareByText() function below),
or printing out JavaScript objects or functions.




Convert an object to a string for whatever reason . This can be useful for heavy - handed comparison ( as in compareByText () function below ) or printing out JavaScript objects or functions .
function convertToText( obj, spaces ){
    if ( obj === window ) {
        return false
    }
    var string = '',
        part = [],
        prop,
        len = 0,
        i = -1;
    if ( typeof obj == 'string' ) {
        string += obj;
    }
    else if ( Object.prototype.toString.call(obj) === '[object Object]' ) {
        for ( prop in obj ) {
            part.push(prop + ': ' + convertToText(obj[prop], spaces));
        }
        string += ' { ' + part.join(', ') + ' } ';
    }
    else if ( Array.isArray(obj) ) {
        len = obj.length;
        while ( ++i < len ) {
            part.push(convertToText(obj[i], spaces));
        }
        string += ' [ ' + part.join(', ') + ' ]';
    }
    else if ( typeof obj == 'function' ) {
        string += obj.toString();
    }
    else {
        string += JSON.stringify(obj);
    }
    if ( typeof spaces == 'undefined' || spaces.toString().toLowerCase() !== 'true' ) {
        return string.replace(/\s/g, '');
    }
    else {
        return string;
    }
}
function convertToText ( obj , spaces ) { if ( obj === window ) { return false } var string = '' , part = [ ] , prop , len = 0 , i = - 1 ; if ( typeof obj == 'string' ) { string += obj ; } else if ( Object . prototype . toString . call ( obj ) === '[object Object]' ) { for ( prop in obj ) { part . push ( prop + ': ' + convertToText ( obj [ prop ] , spaces ) ) ; } string += ' { ' + part . join ( ', ' ) + ' } ' ; } else if ( Array . isArray ( obj ) ) { len = obj . length ; while ( ++ i < len ) { part . push ( convertToText ( obj [ i ] , spaces ) ) ; } string += ' [ ' + part . join ( ', ' ) + ' ]' ; } else if ( typeof obj == 'function' ) { string += obj . toString ( ) ; } else { string += JSON . stringify ( obj ) ; } if ( typeof spaces == 'undefined' || spaces . toString ( ) . toLowerCase ( ) !== 'true' ) { return string . replace ( / \s / g , '' ) ; } else { return string ; } }
Convert an object to a string, for whatever reason.
Convert an object to a string for whatever reason .
// don't be cray-cray // is string - skip all other tests // is object // should we filter the properties? //if ( obj.hasOwnProperty(prop) ){ //} // is array // is function //all other values can be done with JSON.stringify // strip spaces by default and also if (spaces !== true) // only keep spaces if (spaces === true)