import { UserConfig } from './accessory' ; const isSame = ( a , b ) : boolean => { if ( a === b ) return true ; if ( a instanceof Date && b instanceof Date ) return a . getTime ( ) === b . getTime ( ) ; if ( ! a || ! b || ( typeof a !== 'object' && typeof b !== 'object' ) ) return a === b ; if ( a . prototype !== b . prototype ) return false ; const keys = Object . keys ( a ) ; if ( keys . length !== Object . keys ( b ) . length ) return false ; return keys . every ( ( k ) => isSame ( a [ k ] , b [ k ] ) ) ; } ; const dupeChecker = ( devices = [ ] ) : Outcome < void > => { const unique = [ ] ; let error = Error ( '.' ) ; const state = devices . some ( ( it ) => { if ( ! unique . includes ( it . ipAddress ) ) { unique . push ( it . ipAddress ) ; return false ; } error = Error ( it . ipAddress ) ; return true ; } ) ; return state ? { error } : { } ; } ; const isValidMACAddress = ( mac ) : boolean => /^(?:[\dA-Fa-f]{2}:){5}[\dA-Fa-f]{2}$/ . test ( mac ) ; const isValidIPv4 = ( ip ) : boolean => /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ . test ( ip ) ; const sleep = async ( ms ) : Promise < unknown > => await new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; const isEmpty = ( obj ) : boolean => obj . constructor === Object && Object . keys ( obj ) . length === 0 ; const lit = ( s , ... args ) : string => s . map ( ( ss , i ) => `${ ss }${ args [ i ] ?? '' }` ) . join ( '' ) ; const html = lit ; type EmptyObject = Record < string , never > ; type Success < T > = EmptyObject | { value : T ; } ; interface Failure { error : Error ; } type Outcome < T > = Success < T > | Failure ; const Abnormal = ( result ) : result is Failure => ( result as { error ? : Error ; } ) . error !== undefined ; const Ok = < T > ( result ) : result is Success < T > => ! Abnormal ( result ) ; export { Abnormal , dupeChecker , EmptyObject , html , isEmpty , isSame , isValidIPv4 , isValidMACAddress , Ok , Outcome , sleep } ;