| 15 | self.replace_object_strings(value, ctx, data) |
| 16 | |
| 17 | def replace_string(self, str_data: str, ctx: Context, data: ParamsDictionary) -> str: |
| 18 | str_ = str_data |
| 19 | regex = re.compile(r'\${(.*?)}') |
| 20 | matches = regex.findall(str_) |
| 21 | |
| 22 | if matches: |
| 23 | for match in matches: |
| 24 | try: |
| 25 | key = match |
| 26 | value = data.get(key) or self.run_js(key, ctx, data) |
| 27 | str_ = str_.replace(f"${{{match}}}", str(value)) |
| 28 | except Exception as e: |
| 29 | print("Mapper Error 1", e) |
| 30 | |
| 31 | result = self.js_mapper(str_, ctx, data) |
| 32 | return str(result) |
| 33 | |
| 34 | def run_js(self, str_: str, ctx: Context, data: ParamsDictionary = {}, func: FunctionContext = {}, vars: VarsContext = {}) -> ParamsDictionary: |
| 35 | return eval(f"lambda ctx, data, func, vars: {str_}")(ctx, data, func, vars) |