UNPKG

mathsteps-experimental-fork

Version:

Step by step math solutions. Experimental Fork

49 lines (38 loc) 1.46 kB
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const cache$1 = require('../../cache.js'); const config = require('../../config.js'); const nodeCacher = require('./nodeCacher.js'); const cleanString = require('../../util/cleanString.js'); const cache = cache$1.MyNodeToStringCache; function getNode(thing) { return thing?.rootNode || thing?.node || thing?.nodeAfter || (config.isNode(thing) ? thing : null) } function getValueFromNode(node) { return config.isConstantNode(node) ? nodeCacher.getValueFromNodeValue(node) : config.isSymbolNode(node) ? node.name : null } function oneItemToString(thing, options, extraOptions = {}) { const node = getNode(thing); if (!node) return null const key = nodeCacher.makeKeyFromNode(node, extraOptions) + (options ? JSON.stringify(options) : ''); if (!extraOptions.disableCache && cache.has(key)) return cache.get(key) const value = cleanString.cleanString((getValueFromNode(node) || node.toString(options ?? {}))); if (!extraOptions.disableCache) cache.set(key, value); return value } /** * @returns {string} */ function myNodeToString(unknownThing, options, extraOptions = {}) { if (typeof unknownThing !== 'object') throw new TypeError('nodeToString only accepts objects') return oneItemToString(unknownThing, options, extraOptions) } exports.myNodeToString = myNodeToString;