All files / helpers getBluFrameHostname.js

0% Statements 0/14
0% Branches 0/6
0% Functions 0/2
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                                                 
// @flow
 
const NOT_FOUND = -1
const START_BLUFRAME = 0
const START_INSPIRE = 1
 
const getBluFrameHostname = (): string => {
  // Split hostname in parts by dot
  const parts =
    // eslint-disable-next-line no-ternary
    typeof window === "undefined" ? [] : window.location.hostname.split(".")
  // Look for inspire at the start of hostname
  const inspireIndex = parts.findIndex((item) => item === "inspire")
 
  // Remove inspire if there, otherwise keep entire hostname
  let partsIndex = START_BLUFRAME
 
  if (inspireIndex !== NOT_FOUND) {
    partsIndex = START_INSPIRE
  }
 
  let hostname = "/"
 
  if (parts.length) {
    // Join hostname
    hostname = `//${parts.slice(partsIndex).join(".")}/`
  }
 
  return hostname
}
 
export default getBluFrameHostname