import { Type } from "../type.ts";import type { Any } from "../utils.ts";
function reconstructFunction(code: string) { const func = new Function(`return ${code}`)(); if (!(func instanceof Function)) { throw new TypeError(`Expected function but got ${typeof func}: ${code}`); } return func;}
export const func = new Type("tag:yaml.org,2002:js/function", { kind: "scalar", resolve(data: Any) { if (data === null) { return false; } try { reconstructFunction(`${data}`); return true; } catch (_err) { return false; } }, construct(data: string) { return reconstructFunction(data); }, predicate(object: unknown) { return object instanceof Function; }, represent(object: (...args: Any[]) => Any) { return object.toString(); },});