function jsonStringify(object, spaces, depth) {
    if (typeof spaces === 'undefined') {
      // primitive types
      return _stringify(object);
    }

    depth = depth || 1;
    var space = spaces * depth;
    var str = Array.isArray(object) ? '[' : '{';
    var end = Array.isArray(object) ? ']' : '}';
    var length =
      typeof object.length === 'number'
        ? object.length
        : Object.keys(object).length;
    // `.repeat()` polyfill
    function repeat(s, n) {
      return new Array(n).join(s);
    }

    function _stringify(val) {
      switch (canonicalType(val)) {
        case 'null':
        case 'undefined':
          val = '[' + val + ']';
          break;
        case 'array':
        case 'object':
          val = jsonStringify(val, spaces, depth + 1);
          break;
        case 'boolean':
        case 'regexp':
        case 'symbol':
        case 'number':
          val =
            val === 0 && 1 / val === -Infinity // `-0`
              ? '-0'
              : val.toString();
          break;
        case 'bigint':
          val = val.toString() + 'n';
          break;
        case 'date':
          var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
          val = '[Date: ' + sDate + ']';
          break;
        case 'buffer':
          var json = val.toJSON();
          // Based on the toJSON result
          json = json.data && json.type ? json.data : json;
          val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
          break;
        default:
          val =
            val === '[Function]' || val === '[Circular]'
              ? val
              : JSON.stringify(val); // string
      }
      return val;
    }

    for (var i in object) {
      if (!Object.prototype.hasOwnProperty.call(object, i)) {
        continue; // not my business
      }
      --length;
      str +=
        '\n ' +
        repeat(' ', space) +
        (Array.isArray(object) ? '' : '"' + i + '": ') + // key
        _stringify(object[i]) + // value
        (length ? ',' : ''); // comma
    }

    return (
      str +
      // [], {}
      (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end)
    );
  }
like JSON.stringify but more sense.

@private
@param {Object}  object
@param {number=} spaces
@param {number=} depth
@returns {*}