/** Emulate the browser's default ValidityState object */ export class ValidityState implements globalThis . ValidityState { badInput = false ; customError = false ; patternMismatch = false ; rangeOverflow = false ; rangeUnderflow = false ; stepMismatch = false ; tooLong = false ; tooShort = false ; typeMismatch = false ; valid = true ; valueMissing = false ; constructor ( ) { Object . seal ( this ) ; } } param { ValidityState } validityObject return { ValidityState } export const setValid = ( validityObject ) : ValidityState => { validityObject . badInput = false ; validityObject . customError = false ; validityObject . patternMismatch = false ; validityObject . rangeOverflow = false ; validityObject . rangeUnderflow = false ; validityObject . stepMismatch = false ; validityObject . tooLong = false ; validityObject . tooShort = false ; validityObject . typeMismatch = false ; validityObject . valid = true ; validityObject . valueMissing = false ; return validityObject ; } ; param { ValidityState } param { Object } return { ValidityState } export const reconcileValidity = ( validityObject , newState ) : ValidityState => { validityObject . valid = isValid ( newState ) ; Object . keys ( newState ) . forEach ( key => validityObject [ key ] = newState [ key ] ) ; return validityObject ; } ; param { Object } return { Boolean } export const isValid = ( validityState ) : boolean => { let valid = true ; for ( let key in validityState ) { if ( key !== 'valid' && validityState [ key ] !== false ) { valid = false ; } } return valid ; } ;