Files
clash-rules/config-sub-converter/scripts/test-options.js

47 lines
1.1 KiB
JavaScript

function safeStringify(obj) {
const seen = new WeakSet();
return JSON.stringify(
obj,
(k, v) => {
if (typeof v === "object" && v !== null) {
if (seen.has(v)) return "[Circular]";
seen.add(v);
}
if (typeof v === "function") return `[Function: ${v.name || "anonymous"}]`;
if (typeof v === "bigint") return v.toString();
return v;
},
2
);
}
function globalKeysSample(limit = 200) {
try {
const keys = Object.getOwnPropertyNames(globalThis).sort();
return keys.slice(0, limit);
} catch {
return [];
}
}
const report = {
types: {
$content: typeof $content,
$files: typeof $files,
$options: typeof $options,
ProxyUtils: typeof ProxyUtils,
produceArtifact: typeof produceArtifact,
},
values: {
$contentPreview: (typeof $content === "string" ? $content.slice(0, 300) : $content),
$contentLength: (typeof $content === "string" ? $content.length : null),
$files: $files ?? null,
$options: $options ?? null,
},
globals: {
globalThisKeysSample: globalKeysSample(),
}
};
$content = safeStringify(report);