UNPKG

@cran/lib.gql.core

Version:

GQL Core Functionality

19 lines (18 loc) 582 B
const RE_FUNC = /^(?:\(([^)]*?)\))?\s*=>\s*(.*?)\s*$/u; const RE_BODY = /^\{(.*)\}$/u; export class Executable extends Function { constructor(name, body) { super(...getParams(body)); Object.defineProperty(this, "name", { get() { return name; }, }); } } function getParams(body) { const matchFunc = RE_FUNC.exec(body); if (!matchFunc) { return ["", `return(${JSON.stringify(body)})`,]; } const matchBody = RE_BODY.exec(matchFunc[2]); return [matchFunc[1] ?? "", matchBody?.[1] ?? `return(${matchFunc[2]})`,]; }