public static tojson = function()

in src/Common/MongoUtility.ts [17:72]


  public static tojson = function (x: any, indent: string, nolint: boolean) {
    if (x === null || x === undefined) {
      return String(x);
    }
    indent = indent || "";

    switch (typeof x) {
      case "string":
        var out = new Array(x.length + 1);
        out[0] = '"';
        for (var i = 0; i < x.length; i++) {
          if (x[i] === '"') {
            out[out.length] = '\\"';
          } else if (x[i] === "\\") {
            out[out.length] = "\\\\";
          } else if (x[i] === "\b") {
            out[out.length] = "\\b";
          } else if (x[i] === "\f") {
            out[out.length] = "\\f";
          } else if (x[i] === "\n") {
            out[out.length] = "\\n";
          } else if (x[i] === "\r") {
            out[out.length] = "\\r";
          } else if (x[i] === "\t") {
            out[out.length] = "\\t";
          } else {
            var code = x.charCodeAt(i);
            if (code < 0x20) {
              out[out.length] = (code < 0x10 ? "\\u000" : "\\u00") + code.toString(16);
            } else {
              out[out.length] = x[i];
            }
          }
        }
        return out.join("") + '"';
      case "number":
      /* falls through */
      case "boolean":
        return "" + x;
      case "object":
        var func = $.isArray(x) ? MongoUtility.tojsonArray : MongoUtility.tojsonObject;
        var s = func(x, indent, nolint);
        if (
          (nolint === null || nolint === undefined || nolint === true) &&
          s.length < 80 &&
          (indent === null || indent.length === 0)
        ) {
          s = s.replace(/[\t\r\n]+/gm, " ");
        }
        return s;
      case "function":
        return x.toString();
      default:
        throw new Error("tojson can't handle type " + typeof x);
    }
  };