export function renderTemplate ( str , data ? ) { const matches = str . match ( /{{(.*?)}}/g ) ; if ( Array . isArray ( matches ) && data !== undefined ) { matches . forEach ( ( v ) => { str = str . replace ( v , data [ v . replace ( /{{|}}/g , '' ) ] ) ; } ) ; } return str ; } export function getMedianStringLength ( strings ) { const sortedStringLengths = strings . map ( ( s ) => s . length ) . sort ( ( a , b ) => a - b ) ; return sortedStringLengths [ Math . floor ( sortedStringLengths . length / 2 ) ] || 0 ; } /**
 * Creates a deterministic number based hash out of a string.
 */ export function stringHash ( str ) { let hash = 0 ; let chr = 0 ; if ( str . length === 0 ) { return hash ; } for ( let i = 0 ; i < str . length ; i ++ ) { chr = str . charCodeAt ( i ) ; hash = ( hash << 5 ) - hash + chr ; hash |= 0 ; } return hash < 0 ? hash * - 2 : hash ; } export function getGroupQueryText ( groupIds ) { return `groups:(${ groupIds . join ( ' or ' ) })` ; } export function getJobQueryText ( jobIds ) { return Array . isArray ( jobIds ) ? `id:(${ jobIds . join ( ' OR ' ) })` : `id:${ jobIds }` ; }