!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).javaScriptToString=r()}(this,function(){"use strict";const e={},r=Object.prototype.toString;function n(n){return null==n?n+"":"object"==typeof n||"function"==typeof n?e[r.call(n)]||"object":typeof n}["Boolean","Number","String","Array","Date","RegExp","Object","Error","Promise","DataView","WeakRef","FinalizationRegistry"].forEach(function(r){e["[object "+r+"]"]=r.toLowerCase()}),["Function","AsyncFunction"].forEach(function(r){e["[object "+r+"]"]="function"}),["Generator","AsyncGenerator"].forEach(function(r){e["[object "+r+"]"]="generator"}),["GeneratorFunction","AsyncGeneratorFunction"].forEach(function(r){e["[object "+r+"]"]="generatorfunction"}),["ArrayBuffer","SharedArrayBuffer"].forEach(function(r){e["[object "+r+"]"]="arraybuffer"}),["Map","WeakMap"].forEach(function(r){e["[object "+r+"]"]="map"}),["Set","WeakSet"].forEach(function(r){e["[object "+r+"]"]="set"}),["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].forEach(function(r){e["[object "+r+"]"]="typedarray"});var t=[],o=[],c=0;const a=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/;function u(e){if(a.test(e))return`.${e}`;if(/^\d+$/.test(e))return`[${e}]`;return`['${e.replace(/\\/g,"\\\\").replace(/'/gi,"\\'")}']`}function s(e,r,n,t=!0){const o=Object.getOwnPropertyNames(t?r.prototype:r),c=t?".prototype.":".";for(const a of o)["caller","callee","arguments"].indexOf(a)<0&&(e[`${n}${c}${a}`]=t?r.prototype[a]:r[a])}const i=(()=>{const e={};return s(e,Array,"Array",!1),s(e,Array,"Array"),s(e,JSON,"JSON",!1),s(e,Object,"Object",!1),s(e,Object,"Object"),s(e,Function,"Function",!1),s(e,Function,"Function"),s(e,Date,"Date",!1),s(e,String,"String"),e.Function=Function,e})();function f(e,r,n){if(0===e.length)return"[]";const t=[];for(let o=0;or.source===e)}function p(e,r){if(e.length>0){const n=`___ref${c=(c+1)%Number.MAX_SAFE_INTEGER}`,o=e.reduce((e,r)=>{const o=function(e,r){const n=r.historyRef.indexOf(r.source);if(n<0)return"";const t=r.historyRef.slice(n);let o,c="";for(let n=0;n{t.push(N(o,r,n))}),0===t.length?"new Set()":`new Set([${t.join(", ")}])`}(e,r,t);case"map":if(e instanceof WeakMap){if(r.throwOnNonSerializable)throw new Error("Non-serializable value: WeakMap");return"undefined"}return function(e,r,n){const t=[];return e.forEach((e,o)=>{t.push(`[${N(o,r,n)}, ${N(e,r,n)}]`)}),0===t.length?"new Map()":`new Map([${t.join(", ")}])`}(e,r,t);case"object":return function(e,r,n){const t=[];for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){n.references.push(o),n.currentPath.push(o);const c=N(e[o],r,n);if(n.currentPath.pop(),n.references.pop(),"undefined"!==c){if(!a.test(o)){const e=o.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o=`"${e}"`}t.push(`${o}: ${c}`)}}return 0===t.length?"{}":p(l(e),`{\n${t.join(",\n")}\n}`)}(e,r,t);case"function":case"generatorfunction":return function(e,r,n){const t=e.name||"anonymousFunction",o=r.includeFunctionProperties?y(t,e,r,n):"";n.references.push("prototype"),n.currentPath.push("prototype");const c=r.includeFunctionPrototype?y(`${t}.prototype`,e.prototype,r,n):"";n.currentPath.pop(),n.references.pop();let a=String(e);if(a.indexOf("[native code]")>-1&&a.length<100)for(const r in i)i[r]===e&&(a=r);return o||c?p(l(e),`(function(){\n var ${t} = ${String(a)};\n ${o}\n ${c}\n return ${t};\n}())`):a}(e,r,t);case"arraybuffer":return b(e,r,t);case"dataview":return function(e,r,n){return r.includeBuffers?`new DataView(${b(e.buffer,r,n)}, ${e.byteOffset}, ${e.byteLength})`:"undefined"}(e,r,t);case"promise":case"generator":case"weakref":case"weakmap":case"weakset":case"finalizationregistry":if(r.throwOnNonSerializable)throw new Error(`Non-serializable value: ${n(e)}`);return"undefined"}}function N(e,r,c){const a="object"==typeof e&&null!==e||"function"==typeof e,u=c.references.indexOf(e);if(a&&c.visited.has(e)&&u<0)return o.push({destPath:[...c.currentPath],sourcePath:c.visited.get(e)||[]}),"null";if(u<0||"string"==typeof c.references[u]){const t=n(e),o=c.references.length;switch(a&&!c.visited.has(e)&&c.visited.set(e,[...c.currentPath]),c.references.push(e),t){case"object":if(c.nestedObjectsLeft<=0)return"undefined";c.nestedObjectsLeft--;break;case"array":case"typedarray":if(c.nestedArraysLeft<=0)return"undefined";c.nestedArraysLeft--;break;case"function":case"generatorfunction":if(c.nestedFunctionsLeft<=0)return"undefined";c.nestedFunctionsLeft--}const u=h(e,r,c);switch(c.references.splice(o),t){case"object":c.nestedObjectsLeft++;break;case"array":case"typedarray":c.nestedArraysLeft++;break;case"function":case"generatorfunction":c.nestedFunctionsLeft++}return u}return t.push({historyRef:c.references.slice(0),source:e}),"null"}return function(e,r){const n={includeFunctionProperties:void 0===(r=r||{}).includeFunctionProperties||r.includeFunctionProperties,includeFunctionPrototype:void 0===r.includeFunctionPrototype||r.includeFunctionPrototype,includeBuffers:void 0===r.includeBuffers||r.includeBuffers,nestedObjectsAmount:void 0===r.nestedObjectsAmount?Number.POSITIVE_INFINITY:r.nestedObjectsAmount,nestedArraysAmount:void 0===r.nestedArraysAmount?Number.POSITIVE_INFINITY:r.nestedArraysAmount,nestedFunctionsAmount:void 0===r.nestedFunctionsAmount?Number.POSITIVE_INFINITY:r.nestedFunctionsAmount,throwOnNonSerializable:void 0!==r.throwOnNonSerializable&&r.throwOnNonSerializable};t=[],o=[],c=0;const a=new Map;a.set(e,[]);const s=h(e,n,{references:[e],nestedObjectsLeft:n.nestedObjectsAmount,nestedArraysLeft:n.nestedArraysAmount,nestedFunctionsLeft:n.nestedFunctionsAmount,visited:a,currentPath:[]}),i=p(l(e),s);return function(e,r){if(0===e.length)return r;const n="___ref"+(c=(c+1)%Number.MAX_SAFE_INTEGER),t=e.map(e=>{const r=e.destPath.map(u).join(""),t=e.sourcePath.map(u).join("");return`${n}${r} = ${n}${t}; `}).join("");return`(function(){ var ${n} = ${r}; ${t}return ${n}; }())`}(o,i)}}); //# sourceMappingURL=javascripttostring.umd.js.map