MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / filterTemplate

Function filterTemplate

packages/filter/src/query.ts:730–752  ·  view source on GitHub ↗
(strings: TemplateStringsArray, ...keys: any[])

Source from the content-addressed store, hash-verified

728}
729
730export 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}

Callers 2

query.unit.tsFile · 0.85

Calls 2

getDeepPropertyFunction · 0.70
parseMethod · 0.65

Tested by

no test coverage detected