import { ScriptAjaxDescriptor } from "../../../types/script/ScriptAjaxDescriptor"; export function renderAjax( { url, method, variables }: ScriptAjaxDescriptor ) { if( typeof(variables) === 'undefined' ) return null; return ( ` const result = await fetch("${url}", { method: '${method}' }); const ${buildPropertySelector( variables )} = await result.json(); return ${buildPropertySelector( variables )} ` ); } function buildPropertySelector( variables: string[] ) { return `{ ${variables.join( ', ' )} }`; }