@mantine/form
Version:
Mantine form management library
33 lines (30 loc) • 899 B
JavaScript
'use client';
;
function reorderErrors(path, { from, to }, errors) {
const oldKeyStart = `${path}.${from}`;
const newKeyStart = `${path}.${to}`;
const clone = { ...errors };
Object.keys(errors).every((key) => {
let oldKey;
let newKey;
if (key.startsWith(oldKeyStart)) {
oldKey = key;
newKey = key.replace(oldKeyStart, newKeyStart);
}
if (key.startsWith(newKeyStart)) {
oldKey = key.replace(newKeyStart, oldKeyStart);
newKey = key;
}
if (oldKey && newKey) {
const value1 = clone[oldKey];
const value2 = clone[newKey];
value2 === void 0 ? delete clone[oldKey] : clone[oldKey] = value2;
value1 === void 0 ? delete clone[newKey] : clone[newKey] = value1;
return false;
}
return true;
});
return clone;
}
exports.reorderErrors = reorderErrors;
//# sourceMappingURL=reorder-errors.cjs.map