"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.stringify=void 0;const t=require("./utils"),e=[];function n(t,i){let s=i[t];return null!=s&&("function"==typeof s.toJSON5?s=s.toJSON5(t):"function"==typeof s.toJSON&&(s=s.toJSON(t))),s instanceof Number?s=Number(s):s instanceof String?s=String(s):s instanceof Boolean&&(s=s.valueOf()),null===s?"null":!0===s?"true":!1===s?"false":"string"==typeof s?r(s):"number"==typeof s?String(s):"object"==typeof s?Array.isArray(s)?function(t){if(e.includes(t))throw new TypeError("Converting circular structure to JSON5");e.push(t);const r=[];for(let e=0;e<t.length;e++){const o=n(String(e),t);r.push(null!=o?o:"null")}let o;if(0===r.length)o="[]";else{o=`[${r.join(",")}]`}return e.pop(),o}(s):function(t){if(e.includes(t))throw new TypeError("Converting circular structure to JSON5");e.push(t);const r=Object.keys(t),i=[];for(const e of r){const r=n(e,t);if(void 0!==r){let t=`${o(e)}:`;t+=r,i.push(t)}}let s;if(0===i.length)s="{}";else{s=`{${i.join(",")}}`}return e.pop(),s}(s):void 0}function r(e){const n={"'":.1,'"':.2};let r="";for(let o=0;o<e.length;o++){const i=e[o];if("'"!==i&&'"'!==i)if("\0"===i&&(0,t.isDigit)(e[o+1]))r+="\\x00";else if(void 0===t.replacements[i])if(i<" "){const t=i.charCodeAt(0).toString(16);r+=`\\x${`00${t}`.substring(t.length)}`}else r+=i;else r+=t.replacements[i];else n[i]++,r+=i}const o=Object.keys(n).reduce(((t,e)=>n[t]<n[e]?t:e));return r=r.replace(new RegExp(o,"g"),t.replacements[o]),o+r+o}function o(e){if(0===e.length)return r(e);const n=String.fromCodePoint(e.codePointAt(0));if(!(0,t.isIdStartChar)(n))return r(e);for(let o=n.length;o<e.length;o++){const n=String.fromCodePoint(e.codePointAt(o));if(!(0,t.isIdContinueChar)(n))return r(e)}return e}exports.stringify=function(t){return n("",{"":t})};