(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.jsonExt = factory()); }(typeof globalThis != 'undefined' ? globalThis : typeof window != 'undefined' ? window : typeof global != 'undefined' ? global : typeof self != 'undefined' ? self : this, (function () { var exports=(()=>{var L=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var K=(e,t)=>{for(var n in t)L(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of V(t))!W.call(e,i)&&i!==n&&L(e,i,{get:()=>t[i],enumerable:!(r=M(t,i))||r.enumerable});return e};var $=e=>_(L({},"__esModule",{value:!0}),e);var it={};K(it,{createStringifyWebStream:()=>z,parseChunked:()=>I,parseFromWebStream:()=>J,stringifyChunked:()=>m,stringifyInfo:()=>q});function O(e){return typeof e=="object"&&e!==null&&(typeof e[Symbol.iterator]=="function"||typeof e[Symbol.asyncIterator]=="function")}function F(e,t,n,r){switch(n&&typeof n.toJSON=="function"&&(n=n.toJSON()),r!==null&&(n=r.call(e,String(t),n)),typeof n){case"function":case"symbol":n=void 0;break;case"object":if(n!==null){let i=n.constructor;(i===String||i===Number||i===Boolean)&&(n=n.valueOf())}break}return n}function B(e){return typeof e=="function"?e:Array.isArray(e)?[...new Set(e.map(n=>{let r=n&&n.constructor;return r===String||r===Number?String(n):null}).filter(n=>typeof n=="string"))]:null}function N(e){return typeof e=="number"?!Number.isFinite(e)||e<1?!1:" ".repeat(Math.min(e,10)):typeof e=="string"&&e.slice(0,10)||!1}var C=1,U=2,Y=new TextDecoder;function G(e,t){return e.name==="SyntaxError"&&t.jsonParseOffset&&(e.message=e.message.replace(/at position (\d+)/,(n,r)=>"at position "+(Number(r)+t.jsonParseOffset))),e}function H(e,t){let n=e.length;e.length+=t.length;for(let r=0;r0?this.parseAndAppend(this.prepareAddition(i),!0):(this.value=JSON.parse(i),this.valueStack={value:this.value,prev:null});else if(this.flushDepth>this.lastFlushDepth){for(let s=this.flushDepth-1;s>=this.lastFlushDepth;s--)i+=this.stack[s]===C?"}":"]";this.lastFlushDepth===0?(this.value=JSON.parse(i),this.valueStack={value:this.value,prev:null}):this.parseAndAppend(this.prepareAddition(i),!0);for(let s=this.lastFlushDepth||1;s=this.flushDepth;s--)this.jsonParseOffset--,i=(this.stack[s]===C?"{":"[")+i;this.parseAndAppend(i,!1);for(let s=this.lastFlushDepth-1;s>=this.flushDepth;s--)this.valueStack=this.valueStack.prev}this.lastFlushDepth=this.flushDepth}push(t){if(typeof t!="string"){if(this.pendingByteSeq!==null){let s=t;t=new Uint8Array(this.pendingByteSeq.length+s.length),t.set(this.pendingByteSeq),t.set(s,this.pendingByteSeq.length),this.pendingByteSeq=null}if(t[t.length-1]>127)for(let s=0;s>6===3){s++,(s!==4&&l>>3===30||s!==3&&l>>4===14||s!==2&&l>>5===6)&&(this.pendingByteSeq=t.slice(t.length-s),t=t.slice(0,-s));break}}t=Y.decode(t)}let n=t.length,r=0,i=0;t:for(let s=0;sr&&this.flush(t,r,i),iD("",e),y=g,d=!0,h=[""],c=0,a="",k=Object.keys;if(Array.isArray(i)){let f=i;k=()=>f,i=null}for(;x(),!((a.length>=r||u===null)&&(yield a,a="",u===null)););function w(){if(c===0&&(h=k(y),a+="{"),c===h.length){a+=n&&!d?` ${n.repeat(l.length-1)}}`:"}",A();return}let f=h[c++];D(f,y[f])}function o(){if(c===0&&(a+="["),c===y.length){a+=n&&!d?` ${n.repeat(l.length-1)}]`:"]",A();return}D(c,y[c++])}function j(f){if(d?d=!1:a+=",",n&&u!==null&&(a+=` ${n.repeat(l.length)}`),x===w){let p=s.get(f);p===void 0&&s.set(f,p=E(f)+(n?": ":":")),a+=p}}function D(f,p){if(p=F(y,f,p,i),p===null||typeof p!="object")(x!==w||p!==void 0)&&(j(f),b(p));else{if(l.includes(p))throw new TypeError("Converting circular structure to JSON");j(f),l.push(p),S(),x=Array.isArray(p)?o:w,y=p,d=!0,c=0}}function b(f){switch(typeof f){case"string":a+=E(f);break;case"number":a+=Number.isFinite(f)?String(f):"null";break;case"boolean":a+=f?"true":"false";break;case"undefined":case"object":a+="null";break;default:throw new TypeError(`Do not know how to serialize a ${f.constructor?.name||typeof f}`)}}function S(){u={keys:h,index:c,prev:u}}function A(){l.pop();let f=l.length>0?l[l.length-1]:g;x=Array.isArray(f)?o:w,y=f,d=!1,h=u.keys,c=u.index,u=u.prev}}var Q=typeof Object.hasOwn=="function"?Object.hasOwn:(e,t)=>Object.hasOwnProperty.call(e,t),X={8:"\\b",9:"\\t",10:"\\n",12:"\\f",13:"\\r",34:'\\"',92:"\\\\"},Z=Uint8Array.from({length:2048},(e,t)=>Q(X,t)?2:t<32?6:t<128?1:2);function R(e){return e>=55296&&e<=56319}function v(e){return e>=56320&&e<=57343}function T(e){if(!/[^\x20\x21\x23-\x5B\x5D-\x7F]/.test(e))return e.length+2;let t=0,n=!1;for(let r=0;r=1e9&&(t+=9,e=(e-e%1e9)/1e9),e>=1e4?e>=1e6?t+(e>=1e8?9:e>=1e7?8:7):t+(e>=1e5?6:5):t+(e>=100?e>=1e3?4:3:e>=10?2:1)}function et(e){switch(typeof e){case"string":return T(e);case"number":return Number.isFinite(e)?Number.isInteger(e)?tt(e):String(e).length:4;case"boolean":return e?4:5;case"undefined":case"object":return 4;default:return 0}}function nt(e){return e=N(e),typeof e=="string"?e.length:0}function q(e,t,n){(t===null||Array.isArray(t)||typeof t!="object")&&(t={replacer:t,space:n});let r=!!t.continueOnCircular,i=B(t.replacer),s=Object.keys;if(Array.isArray(i)){let k=i;s=()=>k,i=null}n=nt(n);let l=new Map,g=new Map,u=[],x=new Set,y={"":e},d=!1,h=0,c=0;return a(y,"",e),h===0&&(h+=9),{bytes:isNaN(h)?1/0:h,circular:[...x]};function a(k,w,o){if(!d)if(o=F(k,w,o,i),o===null||typeof o!="object")(o!==void 0||Array.isArray(k))&&(h+=et(o));else{if(u.includes(o)){x.add(o),h+=4,r||(d=!0);return}if(g.has(o)){h+=g.get(o);return}c++;let j=c,D=h,b=0;if(u.push(o),Array.isArray(o)){b=o.length;for(let S=0;S0?2:1)),h+=f,b++,S=h}}h+=b===0?2:1+b,n>0&&b>0&&(h+=(1+u.length*n)*b+1+(u.length-1)*n),u.pop(),j!==c&&g.set(o,h-D)}}}function J(e){return I(O(e)?e:async function*(){let t=e.getReader();try{for(;;){let{value:n,done:r}=await t.read();if(r)break;yield n}}finally{t.releaseLock()}})}function z(e,t,n){return typeof ReadableStream.from=="function"?ReadableStream.from(m(e,t,n)):new ReadableStream({start(){this.generator=m(e,t,n)},pull(r){let{value:i,done:s}=this.generator.next();s?r.close():r.enqueue(i)},cancel(){this.generator=null}})}return $(it);})(); return exports; }))); //# sourceMappingURL=json-ext.min.js.map