UNPKG

mathsteps-experimental-fork

Version:

Step by step math solutions. Experimental Fork

38 lines (33 loc) 1.31 kB
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const nodeCacher = require('./nodeServices/nodeCacher.js'); const kemuSimplifyCommonServices = require('../simplifyExpression/kemuSimplifyCommonServices.js'); function createFunctionForEveryRule(rules, onApplyRuleFunction = kemuSimplifyCommonServices.applyRules) { const fns = []; rules.forEach((rule) => { rule.ogId = rule.id; if (fns.some((f) => f.ogId === rule.id)) { const length = fns.filter((f) => f.ogId === rule.id).length + 1; rule.id = `${rule.id}__CASE_${length}`; } const cache = /* @__PURE__ */ new Map(); const fn = (node, arg2, arg3, arg4) => { const isOptionsObjWithGetMistakes = arg2?.getMistakes || arg3?.getMistakes || arg4?.getMistakes || false; const key = nodeCacher.makeKeyFromNode(node); if (cache.has(key)) { return cache.get(key); } const result = onApplyRuleFunction(node, [rule], { getMistakes: isOptionsObjWithGetMistakes }); cache.set(key, result); return result; }; Object.defineProperty(fn, "name", { value: rule.id, writable: false }); fns.push({ id: rule.id, ogId: rule.ogId, fn }); }); return fns; } exports.createFunctionForEveryRule = createFunctionForEveryRule;