UNPKG

@cran/lib.gql.core

Version:

GQL Core Functionality

23 lines (22 loc) 714 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Executable = void 0; const RE_FUNC = /^(?:\(([^)]*?)\))?\s*=>\s*(.*?)\s*$/u; const RE_BODY = /^\{(.*)\}$/u; class Executable extends Function { constructor(name, body) { super(...getParams(body)); Object.defineProperty(this, "name", { get() { return name; }, }); } } exports.Executable = Executable; 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]})`,]; }