renderString.js 804 B

1234567891011121314151617181920212223242526272829303132
  1. import { messageSandbox } from '../helper';
  2. import mustacheReplacer from './mustacheReplacer';
  3. const isFirefox = BROWSER_TYPE === 'firefox';
  4. export default async function (str, data) {
  5. if (!str || typeof str !== 'string') return '';
  6. const hasMustacheTag = /\{\{(.*?)\}\}/.test(str);
  7. if (!hasMustacheTag) {
  8. return {
  9. list: {},
  10. value: str,
  11. };
  12. }
  13. let renderedValue = {};
  14. if (str.startsWith('!!') && !isFirefox) {
  15. const refKeysRegex =
  16. /(variables|table|secrets|loopData|workflow|googleSheets|globalData)@/g;
  17. const strToRender = str.replace(refKeysRegex, '$1.');
  18. renderedValue = await messageSandbox('blockExpression', {
  19. str: strToRender,
  20. data,
  21. });
  22. } else {
  23. renderedValue = mustacheReplacer(str, data);
  24. }
  25. return renderedValue;
  26. }