/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/next-json@0.5.1/dist/cjs/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NJSON=void 0,exports.expressNJSON=expressNJSON,exports.fetchNJSON=fetchNJSON;const parser_1=require("./parser");function parse(e,t){try{const n=(0,parser_1.parse)(e,{grammarSource:"",offset:0,..."function"==typeof t?void 0:t});if("function"==typeof t&&(t={reviver:t}),t||(t={}),"function"!=typeof t.reviver)return n;const{numberKey:i,reviver:r}=t,s=[];function o(e,t,n,f,a){if(n&&"object"==typeof n&&!(n instanceof Date)&&!(n instanceof RegExp)&&!(n instanceof URL)&&!ArrayBuffer.isView(n)&&!s.includes(n))if(s.push(n),n instanceof Array)for(const[e,t]of n.entries())n[e]=o(n,i?e:e.toString(),t,a);else if(n instanceof Error){const e=o(n,"message",n.message);Object.defineProperty(n,"message",{configurable:!0,value:e,writable:!0})}else if(n instanceof Map){const e=Array.from(n),{length:t}=e;for(const[i,r]of e.entries()){const s=o(n,i,r,!1,!0);let f,a,c=!1,u=!1;if(s instanceof Array&&2===s.length?([f,a]=s,f!==r[0]?c=u=!0:n.set(f,a)):c=!0,c){for(let r=i;r<t;++r)n.delete(e[r][0]);u&&n.set(f,a);for(let r=i+i;r<t;++r)n.set(...e[r])}}}else if(n instanceof Set){const e=Array.from(n),{length:t}=e;for(const[i,r]of e.entries()){const s=o(n,i,r);if(s!==r){for(let r=i;r<t;++r)n.delete(e[r]);n.add(s);for(let r=i+i;r<t;++r)n.add(e[r])}}}else for(const[e,t]of Object.entries(n))n[e]=o(n,e,t);return f?n:r.call(e,t,n)}return o({"":n},"",n)}catch(f){if(f instanceof parser_1.NJSONError){const a=new SyntaxError(f.format([]).substring(7).replace(".\n at :"," at ")),[c,,...u]=a.stack.split("\n");throw Object.defineProperty(a,"stack",{value:[c,...u].join("\n")}),a}throw f}}function argument(){return!this.identifier&&!this.elements.some((e=>!e.argument()))}function excludeRef(){return{argument:function(){return!0},exclude:!0,stringify:function(){return"null"}}}function nativeRef(e){return{argument:function(){return!this.identifier},stringified:e,stringify:function(e,t){return this.identifier&&t?this.identifier:this.stringified}}}const errors=[EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError],typedArrays=[BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array];function stringify(e,t,n){let i,r,s="",o=!1,f=!1,a="",c=!1,u=e=>e.getTime().toString(),l=!0;if(t){let e;if("object"==typeof t&&(t instanceof Array?e=t:("iso"===t.date?u=e=>`"${e.toISOString()}"`:"string"===t.date?u=e=>`"${e.toString()}"`:"utc"===t.date&&(u=e=>`"${e.toUTCString()}"`),t.numberKey&&(o=!0),"number"==typeof t.stringLength&&(r=t.stringLength),!0===t.omitStack&&(f=!0),!0===t.sortKeys&&(c=!0),!1===t.undef&&(l=!1),"function"==typeof t.replacer?i=t.replacer:t.replacer instanceof Array&&(e=t.replacer),n=t.space)),"function"==typeof t&&(i=t),e){const t=["",...e.map((e=>"number"!=typeof e||o?e:e.toString())).filter((e=>"string"==typeof e||o&&"number"==typeof e))];i=function(e,n){return this instanceof Array||t.includes(e)?n:parse}}}if("string"==typeof n||"number"==typeof n&&n>0){if("number"==typeof n){let e="";for(let t=1;t<=10&&t<=n;++t)e+=" ";n=e}else"string"==typeof n&&(n=n.replace(/[^ \n\r\t]/g,"").substring(0,10));s="\n",a=" "}else n="";const g=[],d=new Map,y=n;const h=function e(t,n,h,$,p){if(i&&!$&&(h=i.call(t,n,h)),p&&(!(h instanceof Array)||2!==h.length))return{exclude:!0};if(function(e){switch(typeof e){case"function":case"symbol":return!0;case"object":return e;case"string":return void 0!==r&&e.length>=r}return!1}(h)){let m=d.get(h);if(!m){let b;switch(d.set(h,m={}),typeof h){case"function":case"symbol":b=excludeRef();break;case"string":b=nativeRef(JSON.stringify(h));break;default:if(h instanceof Array){let x=[];const N=[];let v=N,j=-1;for(const[A,R]of h.entries())N.push(e(h,o?A:A.toString(),R,p));function O(e,t,n){if(this.already&&this.identifier&&t)return this.identifier;n&&(j=N.findIndex((e=>!e.argument())),-1!==j&&(v=N.slice(0,j),x=N.slice(j,N.length)));const i=e+y;if(!this.already&&this.identifier&&t){if(this.already=!0,x.length){const t=i+y;return`Object.assign(${s}${i}${this.identifier},${s}${i}{${s}${x.map(((e,n)=>`${t}"${n+j}":${a}${e.stringify(t,!0)}`)).join(`,${s}`)}${s}${i}}${s}${e})`}return this.identifier}return v.length?`[${s}${v.map((e=>i+e.stringify(i,t))).join(`,${s}`)}${s}${e}]`:"[]"}b={argument:argument,elements:N,stringify:O};break}if(h instanceof Date){b=nativeRef(isNaN(h.getTime())?"new Date(NaN)":`new Date(${u(h)})`);break}if(h instanceof Map){const w=[];let k=[],J=w;for(const[I,U]of Array.from(h).entries()){const _=e(h,I,U,!1,!0);_.exclude||w.push(_)}function E(e,t,n){if(this.already&&this.identifier&&t)return this.identifier;if(n){const e=w.findIndex((e=>!e.argument()));-1!==e&&(J=w.slice(0,e),k=w.slice(e,w.length))}const i=e+y;return!this.already&&this.identifier&&t?(this.already=!0,k.length?`${this.identifier}${s}${k.map((e=>{const t=e.stringify(i,!0);return`${i}.set(${t.substring(1,t.length-1)})`})).join(s)}`:this.identifier):J.length?`new Map([${s}${J.map((e=>i+e.stringify(i,t))).join(`,${s}`)}${s}${e}])`:"new Map()"}b={argument:argument,elements:w,stringify:E};break}if(h instanceof RegExp){const[,B,M]=h.toString().match("/(.*)/(.*)");b=nativeRef(`new RegExp(${JSON.stringify(B)}${M?`,"${M}"`:""})`);break}if(h instanceof Set){const C=[];let L=[],T=C;for(const[P,K]of Array.from(h).entries())C.push(e(h,P,K));function D(e,t,n){if(this.already&&this.identifier&&t)return this.identifier;if(n){const e=C.findIndex((e=>!e.argument()));-1!==e&&(T=C.slice(0,e),L=C.slice(e,C.length))}const i=e+y;return!this.already&&this.identifier&&t?(this.already=!0,L.length?`${this.identifier}${s}${L.map((e=>`${i}.add(${e.stringify(i,!0)})`)).join(s)}`:this.identifier):T.length?`new Set([${s}${T.map((e=>i+e.stringify(i,t))).join(`,${s}`)}${s}${e}])`:"new Set()"}b={argument:argument,elements:C,stringify:D};break}if(h instanceof URL){b=nativeRef(`new URL(${JSON.stringify(h.toString())})`);break}const S=typedArrays.findIndex((e=>h instanceof e));if(-1!==S){const{name:F,prototype:{toString:q}}=typedArrays[S],V=h instanceof BigInt64Array||h instanceof BigUint64Array,z=q.call(h);b=nativeRef(z.length?`new ${F}([${V?`${z.replace(/,/g,"n,")}n`:z}])`:`new ${F}()`)}else{const G=[],H=[];let Q=H;const W=Object.entries(h);function X(){return!this.identifier&&!this.elements.some((e=>!e[1].argument()))}if(c&&W.sort(((e,t)=>e[0]<t[0]?-1:1)),h instanceof Error){const Z=errors.findIndex((e=>h instanceof e)),ee=-1===Z?Error:errors[Z],te=h.cause?e(h,"cause",h.cause):void 0,ne=e(h,"message",h.message),ie=h.name!==ee.name?e(h,"name",h.name):void 0,re=f?void 0:e(h,"stack",h.stack);let se=!1;te&&!te.exclude&&H.push(["cause",te]),ie&&!ie.exclude&&H.push(["name",ie]),re&&!re.exclude&&H.push(["stack",re]);for(const[fe,ae]of W)if(!["cause","message","name","stack"].includes(fe)){const ce=e(h,fe,ae);ce.exclude||H.push([fe,ce])}function oe(e,t,n){if(this.already&&this.identifier&&t)return this.identifier;if(n){const e=ne&&!ne.argument();if(se=-1!==H.findIndex((e=>!e[1].argument()))||e,se&&e){const e=H.length&&"cause"===H[0][0]?H.shift():void 0;H.unshift(["message",ne]),e&&H.unshift(e)}}const i=e+y,r=i+y,o=e=>`new ${ee.name}(${!ne||ne.exclude||n&&!ne.argument()?'""':ne.stringify(e,t)})`,f=()=>`Object.assign(${s}${i}${this.identifier&&t?this.identifier:o(r)},${s}${i}{${s}${H.map((e=>`${r}${JSON.stringify(e[0])}:${a}${e[1].stringify(r,t)}`)).join(`,${s}`)}${s}${i}}${s}${e})`;return!this.already&&this.identifier&&t?(this.already=!0,se?f():this.identifier):0===H.length||se?o(i):f()}b={argument:X,elements:H,stringify:oe};break}for(const[ue,le]of W){const ge=e(h,ue,le);ge.exclude||H.push([ue,ge])}function Y(e,t,n){if(this.already&&this.identifier&&t)return this.identifier;if(n){Q=[];for(const e of H)(e[1].argument()?Q:G).push(e)}const i=e+y;if(!this.already&&this.identifier&&t){if(this.already=!0,G.length){const t=i+y;return`Object.assign(${s}${i}${this.identifier},${s}${i}{${s}${G.map((e=>`${t}${JSON.stringify(e[0])}:${a}${e[1].stringify(t,!0)}`)).join(`,${s}`)}${s}${i}}${s}${e})`}return this.identifier}const r=this.main&&t,o=r?"(":"",f=r?")":"";return Q.length?`${o}{${s}${Q.map((e=>`${i}${JSON.stringify(e[0])}:${a}${e[1].stringify(i,t)}`)).join(`,${s}`)}${s}${e}}${f}`:"{}"}b={argument:X,elements:H,stringify:Y}}}Object.assign(m,b)}return m.found?m.exclude||m.identifier||(m.identifier=function(){const{length:e}=g;for(let t=0;t<=e;++t)if(t===e)for(let t=0;t<=e;++t)g[t]=0;else{if(25!==g[t]){g[t]++;break}g[t]=0}return String.fromCharCode(...g.map((e=>e+65)).reverse())}()):m.found=!0,m}switch(typeof h){case"bigint":return nativeRef(`${h.toString()}n`);case"boolean":case"number":return nativeRef(Object.is(h,-0)?"-0":h.toString());case"object":return nativeRef("null");case"string":return nativeRef(JSON.stringify(h));case"undefined":if(l)return nativeRef("undefined")}return excludeRef()}({"":e},"",e);if(h.exclude)return;h.main=!0;const $=Array.from(d.values()).filter((e=>e.identifier)).sort(((e,t)=>e.identifier.length<t.identifier.length?-1:e.identifier.length>t.identifier.length?1:e.identifier<t.identifier?-1:1));if(!$.length)return h.stringify("");const p=$.map((e=>e.stringify(y,!1,!0)));return`((${$.map((e=>e.identifier)).join(`,${a}`)})${a}=>${s}${y}${h.stringify(y,!0)}${s})(${s}${y}${p.join(`,${s}${y}`)}${s})`}function expressNJSON(e={}){const{parse:t,stringify:n}=e;return function(e,i,r){if(i.njson=function(e,t){this.set({"Content-Type":"application/njson"}),this.end(exports.NJSON.stringify(e,t||n))},e._body||"application/njson"!==e.headers["content-type"])return r();const s=[];e.on("data",(e=>s.push(e))),e.on("end",(()=>{try{e.body=exports.NJSON.parse(Buffer.concat(s).toString(e.headers["content-encoding"]||"utf8"),t),e._body=!0,r()}catch(e){r(e)}}))}}function fetchNJSON(e){const t=e;(null===Response||void 0===Response?void 0:Response.prototype)&&(Response.prototype.njson=async function(e){try{return exports.NJSON.parse(await this.text(),e||t)}catch(e){const{stack:t}=e,[n,i,...r]=t.split("\n");throw Object.defineProperty(e,"stack",{configurable:!0,enumerable:!1,value:[n,...r].join("\n")}),e}})}exports.NJSON={parse:parse,stringify:stringify};
//# sourceMappingURL=/sm/b115ae8576d1b5979df40e0bbc07474ddc802f842485a7c103de8562a2788507.map