@data-driven-forms/react-form-renderer
Version:
React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.
94 lines • 3.88 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.trunc = exports.isNumber = exports.prepare = exports.assign = exports.prepareMsg = exports.memoize = exports.TO_STRING = void 0;
exports.selectNum = selectNum;
/* eslint-disable no-unused-vars */
var react_1 = require("react");
var validators_1 = __importDefault(require("../validators"));
var HAS_PROP = {}.hasOwnProperty;
exports.TO_STRING = {}.toString;
var isObject = function (obj) { return typeof obj === 'object' && exports.TO_STRING.call(obj) === '[object Object]' && obj !== null; };
var stringify = function (args) {
var arr = [];
var value;
var options = args;
if (typeof options === 'number') {
options = options.toString();
}
for (var k in options) {
if (HAS_PROP.call(options, k)) {
value = options[k];
arr.push(k, (0, react_1.isValidElement)(value) ? stringify(value.props) : isObject(value) ? stringify(value) : value != null ? value.toString() : 'undefined');
}
}
return JSON.stringify(arr);
};
var memoize = function (func) {
if (!func.cache) {
func.cache = {};
}
return function (value, allValues) {
var options = [];
for (var _i = 2; _i < arguments.length; _i++) {
options[_i - 2] = arguments[_i];
}
var key = stringify(value);
return HAS_PROP.call(func.cache, key) ? func.cache[key] : (func.cache[key] = func.apply(void 0, __spreadArray([value, allValues], options, false)));
};
};
exports.memoize = memoize;
var defaultMessage = function (type, values) {
var msg = validators_1.default.messages[type];
return typeof msg === 'string' ? { defaultMessage: msg, values: values } : Object.assign({}, msg, { values: values });
};
var prepareMsg = function (msg, type, values) {
if (msg == null) {
return defaultMessage(type, values);
}
var processedMsg = msg;
if (HAS_PROP.call(processedMsg, 'props') && (0, react_1.isValidElement)(processedMsg)) {
processedMsg = processedMsg.props;
}
if (processedMsg[type] != null) {
processedMsg = processedMsg[type];
}
if (isObject(processedMsg)) {
if (HAS_PROP.call(processedMsg, 'id') || HAS_PROP.call(processedMsg, 'defaultMessage')) {
return Object.assign({}, processedMsg, { values: values });
}
return defaultMessage(type, values);
}
return { id: processedMsg, defaultMessage: processedMsg, values: values };
};
exports.prepareMsg = prepareMsg;
exports.assign = Object.assign;
var prepare = function (func) {
return function (value, allValues) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
return func.apply(void 0, __spreadArray([value, allValues], args, false));
};
};
exports.prepare = prepare;
var isNumber = function (num) { return !isNaN(num) && (num !== 0 || ('' + num).trim() !== ''); };
exports.isNumber = isNumber;
function selectNum(var1, var2) {
return (0, exports.isNumber)(var1) ? +var1 : arguments.length > 1 && (0, exports.isNumber)(var2) ? +var2 : null;
}
var trunc = function (num) { return (Math.trunc ? Math.trunc(num) : num < 0 ? Math.ceil(num) : Math.floor(num)); };
exports.trunc = trunc;
//# sourceMappingURL=helpers.js.map