@cran/gql.core
Version:
Cran/GraphQL Core Utilities
24 lines (23 loc) • 732 B
JavaScript
;
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 {
name;
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(${matchBody[2]})`,];
}