prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

working json output

Tyler 35e5d724 ee61dff7

+12 -16
+12 -16
packages/site/src/components/Playground.tsx
··· 14 14 useEffect(() => { 15 15 const timeoutId = setTimeout(() => { 16 16 try { 17 - const AsyncFunction = async function () {}.constructor as new ( 18 - ...args: string[] 19 - ) => (...args: unknown[]) => Promise<unknown>; 17 + const cleanedCode = code.replace( 18 + /import\s+{[^}]*}\s+from\s+['"][^'"]+['"]\s*;?\s*/g, 19 + "", 20 + ); 20 21 21 - const wrappedCode = ` 22 - const { lx } = arguments[0]; 23 - ${code} 24 - const exports = {}; 25 - for (const key in this) { 26 - if (this.hasOwnProperty(key) && key !== 'lx') { 27 - exports[key] = this[key]; 28 - } 29 - } 30 - return Object.values(exports)[0]; 31 - `; 22 + const lastVarMatch = cleanedCode.match(/(?:const|let|var)\s+(\w+)\s*=/); 23 + const lastVarName = lastVarMatch ? lastVarMatch[1] : null; 32 24 33 - const fn = new AsyncFunction(wrappedCode); 34 - const result = fn.call({}, { lx }); 25 + const wrappedCode = lastVarName 26 + ? `${cleanedCode}\nreturn ${lastVarName};` 27 + : cleanedCode; 28 + 29 + const fn = new Function("lx", wrappedCode); 30 + const result = fn(lx); 35 31 36 32 if (result && typeof result === "object" && "json" in result) { 37 33 const jsonOutput = (result as { json: unknown }).json;