fcf.module({
  name: "fcf:NTools/json.js",
  dependencies: [],
  module: function(){
    var Namespace = fcf.prepareObject(fcf, "packages/fcf/NTools");

    class Json {
      constructor(){
        this.maxDepth = 1000;
      }

      stringify(val, depth, replacer, space, onGetObjID) {
        depth = !depth ? 1000 : depth;
        var recursMap = new WeakMap();
        function _build(val, depth, o, a, r) { // (JSON.stringify() has it's own rules, which we respect here by using it for property iteration)
            return !val || typeof val != 'object' ? val
                : (r = recursMap.has(val), recursMap.set(val,true), a = Array.isArray(val),
                   r ? (o=onGetObjID&&onGetObjID(val)||null) : JSON.stringify(val, function(k,v){ if (a || depth > 0) { if (replacer) v=replacer(k,v); if (!k) return (a=Array.isArray(v),val=v); !o && (o=a?[]:{}); o[k] = _build(v, a?depth:depth-1); } }),
                   o===void 0 ? (a?[]:{}) : o);
        }
        return JSON.stringify(_build(val, depth), null, space);
      }
    };

    Namespace.json = new Json();

    return Namespace.json;
  }
});
