UNPKG

@modular-forms/react

Version:

The modular and type-safe form library for React

21 lines (20 loc) 775 B
/** * Returns whether the field is dirty. * * @param startValue The start value. * @param currentValue The current value. * * TODO: Should we pass field as paramater instead of values? * * @returns Whether is dirty. */ export function isFieldDirty(startValue, currentValue) { const toValue = (item) => item instanceof Blob ? item.size : item; return Array.isArray(startValue) && Array.isArray(currentValue) ? startValue.map(toValue).join() !== currentValue.map(toValue).join() : startValue instanceof Date && currentValue instanceof Date ? startValue.getTime() !== currentValue.getTime() : Number.isNaN(startValue) && Number.isNaN(currentValue) ? false : startValue !== currentValue; }