import _ from 'lodash' ; param { [ Float ] } value param { [ Array ] } style return { [ String ] } function GetColorForValue ( value , style ) { if ( ! style . thresholds ) { return null ; } for ( let i = style . thresholds . length ; i > 0 ; i -- ) { if ( value >= style . thresholds [ i - 1 ] ) { return style . colors [ i ] ; } } return _ . first ( style . colors ) ; } function GetColorIndexForValue ( value , style ) { if ( ! style . thresholds ) { return null ; } for ( let i = style . thresholds . length ; i > 0 ; i -- ) { if ( value >= style . thresholds [ i - 1 ] ) { return i ; } } return 0 ; } function StringToJsRegex ( str ) { if ( str [ 0 ] !== '/' ) { return new RegExp ( '^' + str + '$' ) ; } const match = str . match ( new RegExp ( '^/(.*?)/(g?i?m?y?)$' ) ) ; if ( ! match ) { throw new Error ( `'${ str }' is not a valid regular expression.` ) ; } return new RegExp ( match [ 1 ] , match [ 2 ] ) ; } export { StringToJsRegex , GetColorIndexForValue , GetColorForValue } ;