function replaceHtml(htmlString, hashObject) {
  const filesArray = Object.keys(hashObject)
  let newHtmlString = htmlString
  
  function replaceSrc(file) {
    const srcAttributeDblQuote = `src="${file}"`
    const srcAttributeSingQuote = `src='${file}'`
    const hash = hashObject[file]
    const classAttribute = `class='${hash}'`
    
    while (newHtmlString.includes(srcAttributeDblQuote)) {
      newHtmlString = newHtmlString.replace(srcAttributeDblQuote, classAttribute)  
    }
    while (newHtmlString.includes(srcAttributeSingQuote)) {
      newHtmlString = newHtmlString.replace(srcAttributeSingQuote, classAttribute)  
    }
  }
  
  filesArray.forEach(replaceSrc)
  
  return newHtmlString  
}

module.exports = replaceHtml
const cheerio = require('cheerio')

function replaceHtml(htmlString, hashObject) {
  const filesArray = Object.keys(hashObject)
  const $ = cheerio.load(htmlString)
  
  function replaceSrc(file) {
    let $elemArray = $(`[src="${file}"]`)
    
    $elemArray.forEach(elem => {
      elem.removeAttr('src')
      elem.addClass(hashObject[file])
    })
    
    $elemArray = $(`[src='${file}']`)
    
    $elemArray.forEach(elem => {
      elem.removeAttr('src')
      elem.addClass(hashObject[file])
    })
  }
  
  filesArray.forEach(replaceSrc)
  
  return $.html()  
}

module.exports = replaceHtml
Convert replaceHtml from replace to cheerio