UNPKG

@thi.ng/pointfree

Version:

Pointfree functional composition / Forth style stack execution engine

27 lines (26 loc) 518 B
import { $n, $ } from "./safe.js"; const ismatch = (ctx) => { const stack = ctx[0]; const n = stack.length - 2; $n(n, 0); stack[n] = new RegExp(stack[n + 1]).test(stack[n]); stack.length--; return ctx; }; const fromjson = (ctx) => { const stack = ctx[0]; $(stack, 1); stack.push(JSON.parse(stack.pop())); return ctx; }; const tojson = (ctx) => { const stack = ctx[0]; $(stack, 1); stack.push(JSON.stringify(stack.pop(), null, 4)); return ctx; }; export { fromjson, ismatch, tojson };