(strings: TemplateStringsArray, ...keys: any[])
| 728 | } |
| 729 | |
| 730 | export function filterTemplate(strings: TemplateStringsArray, ...keys: any[]) { |
| 731 | return function filter(ctx: AnyObject) { |
| 732 | const tokens = [strings[0]]; |
| 733 | keys.forEach((key, i) => { |
| 734 | if ( |
| 735 | typeof key === 'object' || |
| 736 | typeof key === 'boolean' || |
| 737 | typeof key === 'number' |
| 738 | ) { |
| 739 | tokens.push(JSON.stringify(key), strings[i + 1]); |
| 740 | return; |
| 741 | } |
| 742 | const value = getDeepProperty(ctx, key); |
| 743 | tokens.push(JSON.stringify(value), strings[i + 1]); |
| 744 | }); |
| 745 | const result = tokens.join(''); |
| 746 | try { |
| 747 | return JSON.parse(result); |
| 748 | } catch (e) { |
| 749 | throw new Error('Invalid JSON: ' + result); |
| 750 | } |
| 751 | }; |
| 752 | } |
no test coverage detected