formbold-react
Version:
Formbold package for react.
99 lines (98 loc) • 3.71 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValueEmpty = exports.toFormValues = exports.mergeConfig = void 0;
/**
* Merges the provided configuration object with the default configuration,
* overriding any properties that are specified in the provided object.
*
* @param config - The configuration object to merge with the default configuration.
* @returns The merged configuration object.
*/
var mergeConfig = function (defaultConfig, config) {
var _a;
if (config === void 0) { config = {}; }
var errorMessages = __assign(__assign({}, defaultConfig.errorMessages), ((_a = config.errorMessages) !== null && _a !== void 0 ? _a : {}));
return __assign(__assign(__assign({}, defaultConfig), config), { errorMessages: errorMessages });
};
exports.mergeConfig = mergeConfig;
var toFormValues = function (formData) {
var e_1, _a;
var values = {};
try {
for (var _b = __values(formData.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], rawValue = _d[1];
var currentValue = values[key];
if (currentValue === undefined) {
values[key] = rawValue;
continue;
}
values[key] = Array.isArray(currentValue) ? __spreadArray(__spreadArray([], __read(currentValue), false), [rawValue], false) : [currentValue, rawValue];
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return values;
};
exports.toFormValues = toFormValues;
var isValueEmpty = function (value) {
if (value === undefined) {
return true;
}
if (Array.isArray(value)) {
return value.length === 0 || value.every(function (item) { return item === ''; });
}
return value === '';
};
exports.isValueEmpty = isValueEmpty;