MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / unpackAndCall

Function unpackAndCall

lib/utils.ts:50–72  ·  view source on GitHub ↗
(
  func: ((...args: any[]) => any) | undefined,
  obj: {
    [p: string]: any;
  },
)

Source from the content-addressed store, hash-verified

48}
49
50export function unpackAndCall(
51 func: ((...args: any[]) => any) | undefined,
52 obj: {
53 [p: string]: any;
54 },
55): any {
56 if (!func) return "";
57 // Get the names of the function parameters
58 // @ts-ignore
59 const paramNames = func
60 .toString()
61 .match(/function\s.*?\(([^)]*)\)/)[1]
62 .split(",")
63 .map((param) => param.trim());
64
65 // Sort the object properties according to the function parameters
66 // @ts-ignore
67 const args = paramNames.map((paramName) => obj[paramName]);
68
69 // Call the function with the unpacked arguments
70 // @ts-ignore
71 return func(...args);
72}
73
74export function stripTrailingAndCurly(str: string) {
75 // Remove trailing slashes

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected