private static tojsonObject = function()

in src/Common/MongoUtility.ts [74:125]


  private static tojsonObject = function (x: any, indent: string, nolint: boolean) {
    var lineEnding = nolint ? " " : "\n";
    var tabSpace = nolint ? "" : "\t";
    indent = indent || "";

    if (typeof x.tojson === "function" && x.tojson !== MongoUtility.tojson) {
      return x.tojson(indent, nolint);
    }

    if (x.constructor && typeof x.constructor.tojson === "function" && x.constructor.tojson !== MongoUtility.tojson) {
      return x.constructor.tojson(x, indent, nolint);
    }

    if (MongoUtility.hasDefinedProperty(x, "toString") && !$.isArray(x)) {
      return x.toString();
    }

    if (x instanceof Error) {
      return x.toString();
    }

    if (MongoUtility.isObjectId(x)) {
      return 'ObjectId("' + x.$oid + '")';
    }

    // push one level of indent
    indent += tabSpace;
    var s = "{";

    var pairs = [];
    for (var k in x) {
      if (x.hasOwnProperty(k)) {
        var val = x[k];
        var pair = '"' + k + '" : ' + MongoUtility.tojson(val, indent, nolint);

        if (k === "_id") {
          pairs.unshift(pair);
        } else {
          pairs.push(pair);
        }
      }
    }
    // Add proper line endings, indents, and commas to each line
    s += $.map(pairs, function (pair) {
      return lineEnding + indent + pair;
    }).join(",");
    s += lineEnding;

    // pop one level of indent
    indent = indent.substring(1);
    return s + indent + "}";
  };