UNPKG

@mantine/form

Version:

Mantine form management library

47 lines (43 loc) 1.36 kB
'use client'; 'use strict'; var clearListState = require('./clear-list-state.cjs'); function getIndexFromKeyAfterPath(key, path) { const split = key.substring(path.length + 1).split(".")[0]; return parseInt(split, 10); } function changeErrorIndices(path, index, errors, change) { if (index === void 0) { return errors; } const pathString = `${String(path)}`; let clearedErrors = errors; if (change === -1) { clearedErrors = clearListState.clearListState(`${pathString}.${index}`, clearedErrors); } const cloned = { ...clearedErrors }; const changedKeys = /* @__PURE__ */ new Set(); Object.entries(clearedErrors).filter(([key]) => { if (!key.startsWith(`${pathString}.`)) { return false; } const currIndex = getIndexFromKeyAfterPath(key, pathString); if (Number.isNaN(currIndex)) { return false; } return currIndex >= index; }).forEach(([key, value]) => { const currIndex = getIndexFromKeyAfterPath(key, pathString); const newKey = key.replace( `${pathString}.${currIndex}`, `${pathString}.${currIndex + change}` ); cloned[newKey] = value; changedKeys.add(newKey); if (!changedKeys.has(key)) { delete cloned[key]; } }); return cloned; } exports.changeErrorIndices = changeErrorIndices; //# sourceMappingURL=change-error-indices.cjs.map