All files create_new_path.js

100% Statements 10/10
100% Branches 7/7
100% Functions 3/3
100% Lines 9/9

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 162x   2x 6x   2x 5x     2x 6x   5x 5x    
const WEBP_REGEXP = /^(~images)([\w\d/\-_]+)(\.[jpe?g|png]+)/
 
const checkReplaceTo = replaceTo =>
  replaceTo && typeof replaceTo === 'function'
 
const replaced = (path = '~webp') => {
  return path + '$2.webp'
}
 
module.exports = ({ replaceTo, webpPath }, { file, folder, url }) => {
  if (checkReplaceTo(replaceTo)) return replaceTo({ file, folder, url })
 
  let replacer = replaceTo || WEBP_REGEXP
  return url.replace(replacer, replaced(webpPath))
}