import { pandaLinkValidators , projectIdFromProjectLinkRegex } from './watchers' ; import { executeRegex } from './parsing' ; export const validateInbounds = ( value ) => { const num = parseFloat ( value ) ; return num >= 0 && num <= 100 ; } ; export const validateIntegerString = ( value ) : boolean => /^\d+$/ . test ( value ) ; export const validateNumber = ( value ) : boolean => ! Number . isNaN ( parseFloat ( value ) ) && Number . isFinite ( parseFloat ( value ) ) ; export const validatePositiveNumber = ( value ) : boolean => validateNumber ( value ) && parseFloat ( value ) >= 0 ; export const validateRejectionThreshold = ( value ) => ( validateInbounds ( value ) && validateIntegerString ( value ) ) || value === '' ; export const validatePersistedStateKey = ( key ) => key . startsWith ( 'reduxPersist:' ) && ! ! /reduxPersist:(.*)/g . exec ( key ) ; export const selectReduxPersistStateKey = ( key ) => ( /reduxPersist:(.*)/g . exec ( key ) as RegExpExecArray ) [ 1 ] ; export const validateInputPandaLink = ( input ) : boolean => { try { return pandaLinkValidators . map ( fn => fn ( input ) ) . every ( ( el ) => el === true ) ; } catch ( e ) { return false ; } } ; export const validateProjectIdLink = ( input ) : boolean => { try { const groupId = executeRegex ( input ) ( projectIdFromProjectLinkRegex ) ; return groupId . length === 30 ? true : false ; } catch ( e ) { return false ; } } ;