import { Direction } from 'shared/util/common' ; export function getRandomInt ( min , max ) { return Math . floor ( Math . random ( ) * ( max - min ) ) + min ; } export function toSnakeCase ( str ) { function upperToHyphenLower ( match ) { return '_' + match . toLowerCase ( ) ; } return str . replace ( /[A-Z]/g , upperToHyphenLower ) ; } export function sortByKey ( key , direction = 'ASC' ) { const path = key . split ( '.' ) ; return ( a , b ) : number => { const aValue = path . reduce ( ( current , value ) => current [ value ] , a ) ; const bValue = path . reduce ( ( current , value ) => current [ value ] , b ) ; if ( aValue > bValue ) { return direction === 'ASC' ? 1 : - 1 ; } if ( aValue < bValue ) { return direction === 'ASC' ? - 1 : 1 ; } return 0 ; } ; }