lib/stringify.js
function stringifyObject(object, replacer, space, indent) {
  let childIndent = space ? (indent + space) : undefined;
  let first = true;
  let str = space ? '{\n' : '{';

  if (typeof object.toJSON === 'function') {
    return stringify(object.toJSON(), replacer, space);
  }

  // check for circular reference
  if (isCircular(object)) {
    return stringifyCircular(object, replacer, space, indent);
  }

  // add this object to the stack
  const stackIndex = stack.length;
  stack[stackIndex] = object;

  for (let key in object) {
    if (object.hasOwnProperty(key)) {
      let value = (typeof replacer === 'function')
          ? replacer.call(object, key, object[key])
          : object[key];

      if (includeProperty(key, value, replacer)) {
        if (first) {
          first = false;
        }
        else {
          str += space ? ',\n' : ',';
        }

        str += space
            ? (childIndent + '"' + key + '": ')
            : ('"' + key + '":');

        path[stackIndex] = key;
        str += stringifyValue(value, replacer, space, childIndent);
      }
    }
  }

  // remove current entry from the stack
  stack.length = stackIndex;
  path.length = stackIndex;

  str += space ? ('\n' + indent + '}') : '}';
  return str;
}
function stringifyObject(object, replacer, space, indent) {
  let childIndent = space ? (indent + space) : undefined;
  let first = true;
  let str = space ? '{\n' : '{';

  if (typeof object.toJSON === 'function') {
    return stringify(object.toJSON(), replacer, space);
  }

  // check for circular reference
  if (isCircular(object)) {
    return stringifyCircular(object, replacer, space, indent);
  }

  // add this object to the stack
  const stackIndex = stack.length;
  stack[stackIndex] = object;

  for (let key in object) {
    if (object.hasOwnProperty(key)) {
      let value = (typeof replacer === 'function')
          ? replacer.call(object, key, object[key])
          : object[key];

      if (includeProperty(key, value, replacer)) {
        if (first) {
          first = false;
        }
        else {
          str += space ? ',\n' : ',';
        }

        str += space
            ? (childIndent + '"' + key + '": ')
            : ('"' + key + '":');

        path[stackIndex] = key;
        str += stringifyValue(value, replacer, space, childIndent);
      }
    }
  }

  // remove current entry from the stack
  stack.length = stackIndex;
  path.length = stackIndex;

  str += space ? ('\n' + indent + '}') : '}';
  return str;
}
function stringifyObject ( object , replacer , space , indent ) { let childIndent = space ? ( indent + space ) : undefined ; let first = true ; let str = space ? '{\n' : '{' ; if ( typeof object . toJSON === 'function' ) { return stringify ( object . toJSON ( ) , replacer , space ) ; } // check for circular reference if ( isCircular ( object ) ) { return stringifyCircular ( object , replacer , space , indent ) ; } // add this object to the stack const stackIndex = stack . length ; stack [ stackIndex ] = object ; for ( let key in object ) { if ( object . hasOwnProperty ( key ) ) { let value = ( typeof replacer === 'function' ) ? replacer . call ( object , key , object [ key ] ) : object [ key ] ; if ( includeProperty ( key , value , replacer ) ) { if ( first ) { first = false ; } else { str += space ? ',\n' : ',' ; } str += space ? ( childIndent + '"' + key + '": ' ) : ( '"' + key + '":' ) ; path [ stackIndex ] = key ; str += stringifyValue ( value , replacer , space , childIndent ) ; } } } // remove current entry from the stack stack . length = stackIndex ; path . length = stackIndex ; str += space ? ( '\n' + indent + '}' ) : '}' ; return str ; }
Stringify an object
@param {Object} object
@param {function | Array.<string | number>} [replacer]
@param {string} [space]
@param {string} [indent]
@return {string}
Stringify an object