UNPKG

@schema-render/core-react

Version:

Through a set of simple JSON Schema, efficiently build a set of forms.

52 lines (51 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { performStatement: function() { return performStatement; }, performStatementWithPath: function() { return performStatementWithPath; } }); var _tinyLodash = require("./tinyLodash"); var _checking = require("./checking"); var _logger = /*#__PURE__*/ _interop_require_default(require("./logger")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function performStatement(param) { var statement = param.statement, _param_parentValue = param.parentValue, parentValue = _param_parentValue === void 0 ? {} : _param_parentValue, _param_rootValue = param.rootValue, rootValue = _param_rootValue === void 0 ? {} : _param_rootValue, _param_userCtx = param.userCtx, userCtx = _param_userCtx === void 0 ? {} : _param_userCtx; if ((0, _checking.isBoolean)(statement)) { return statement; } if ((0, _checking.isString)(statement)) { try { var fn = new Function('$', '$root', '$userCtx', "return ".concat(statement)); return !!fn(parentValue, rootValue, userCtx); } catch (e) { _logger.default.warn(e); } } return false; } function performStatementWithPath(param) { var statement = param.statement, path = param.path, rootValue = param.rootValue, userCtx = param.userCtx; var parentPath = (0, _tinyLodash.dropRight)(path); return performStatement({ statement: statement, parentValue: parentPath.length ? (0, _tinyLodash.get)(rootValue, parentPath) : rootValue, rootValue: rootValue, userCtx: userCtx }); }