All files / utils generateLink.js

100% Statements 9/9
100% Branches 8/8
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 202x 7x     3x 1x 2x 1x   1x     3x     4x        
const generateLink = (location, current, target, hostname) => {
  if (location && hostname) {
    let path;
 
    if (current) {
      path = location.pathname.replace(current, target);
    } else if (target) {
      path = `/${target}/`;
    } else {
      path = '/';
    }
 
    return `${location.protocol}//${hostname}${path}${location.search}${location.hash}`;
  }
 
  return '#';
};
 
export default generateLink;