@modular-forms/qwik
Version:
The modular and type-safe form library for Qwik
19 lines (18 loc) • 710 B
JavaScript
/**
* Returns whether the field is dirty.
*
* @param startValue The start value.
* @param currentValue The current value.
*
* @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;
}