constcreateParser=require('js-native-template');constmethods={echo: (x)=>x,asyncEcho: async(x)=>x}constparse=createParser(methods);(async()=>{constresult=awaitparse('Echoes: ${echo("foo").toUpperCase()} ${asyncEcho("bar")}');// result === 'Echoes: FOO bar')();
Catch errors
constcreateParser=require('js-native-template');constparse=createParser();(async()=>{try{constresult=awaitparse('Throw error: ${nonExisting}');}catch(err){// err.message === 'nonExisting is not defined at 1:16' - position of occured error is relative in parsed string}})();