import { removeCurrencyFormatting } from './formatting' ; export const parseStringProperty = ( queryString , fallback ) => ( input ) => { const maybeElem = input . querySelector ( queryString ) ; return maybeElem && maybeElem . textContent ? maybeElem . textContent . trim ( ) : `[Error:${ fallback }]` ; } ; export const parseNumericProperty = ( queryString , fallback = 0 ) => ( input ) : number => { const maybeElem = input . querySelector ( queryString ) ; return maybeElem && maybeElem . textContent ? parseFloat ( maybeElem . textContent . trim ( ) . replace ( /,/g , '' ) ) : fallback ; } ; export const parseCurrencyProperty = ( queryString ) => ( input ) : number => { const maybeElem = input . querySelector ( queryString ) ; return maybeElem && maybeElem . textContent ? parseFloat ( removeCurrencyFormatting ( maybeElem . textContent ) ) : 0 ; } ; export const findHitIframe = ( input ) => { return input . querySelector ( 'iframe.embed-responsive-item' ) ; } ; export const findCaptchaContainer = ( input ) => input . querySelector ( 'img.captcha-image' ) ; param input export const findErrorDiv = ( input ) => input . querySelector ( '#MainContent > div:nth-child(2) > div > div' ) ; export const validateHitAccept = ( html ) : boolean => { return ! ! findHitIframe ( html ) ; } ; export const parseReactProps = ( html ) => ( querySelector ) : string => { const dataNode = html . querySelector ( querySelector ) ; if ( ! dataNode ) { throw new Error ( `Node containing React props was not found. querySelector: ${ querySelector }` ) ; } return getDataReactProps ( dataNode ) ; } ; const getDataReactProps = ( dataNode ) : string => { const reactProps = dataNode . getAttribute ( 'data-react-props' ) ; if ( ! reactProps ) { throw new Error ( `No react props found on node.` ) ; } else { return reactProps ; } } ; export const executeRegex = ( inputString ) => ( regex ) => { const resultArr = regex . exec ( inputString ) ; if ( resultArr === null || resultArr . length < 1 ) { throw new Error ( `Problem parsing string. Input: ${ inputString } :: Regexp: ${ regex } :: Result: ${ resultArr }` ) ; } else { return resultArr [ 1 ] ; } } ; export const testRegex = ( inputString ) => ( regex ) => regex . test ( inputString ) ;