import { AndroidColor } from '../types/NotificationAndroid' ; import { isNumber } from '../utils' ; param color returns { boolean } export function isValidColor ( color ) { if ( Object . values ( AndroidColor ) . includes ( color as AndroidColor ) ) { return true ; } if ( ! color . startsWith ( '#' ) ) { return false ; } const length = color . length - 1 ; return length === 6 || length === 8 ; } param timestamp returns { boolean } export function isValidTimestamp ( timestamp ) { return timestamp > 0 ; } param pattern { array } export function isValidVibratePattern ( pattern ) { if ( pattern . length % 2 !== 0 ) { return false ; } for ( let i = 0 ; i < pattern . length ; i ++ ) { const ms = pattern [ i ] ; if ( ! isNumber ( ms ) ) { return false ; } if ( ms <= 0 ) { return false ; } } return true ; } param pattern { array } type LightPattern = [ string , number , number ] ; type ValidLightPattern = [ boolean ] | [ boolean , 'color' | 'onMs' | 'offMs' ] ; export function isValidLightPattern ( pattern ) { const [ color , onMs , offMs ] = pattern ; if ( ! isValidColor ( color ) ) { return [ false , 'color' ] ; } if ( ! isNumber ( onMs ) ) { return [ false , 'onMs' ] ; } if ( ! isNumber ( offMs ) ) { return [ false , 'offMs' ] ; } if ( onMs < 1 ) { return [ false , 'onMs' ] ; } if ( offMs < 1 ) { return [ false , 'offMs' ] ; } return [ true ] ; }