Diff Legally

by jakelauer

HTML

<div>
   Last<br/>
   <textarea id="first"></textarea>
</div>
<div>
   Current<br/>
   <textarea id="second"></textarea>
</div>
<div>
   Result<br/>
   <textarea id="result"></textarea>
</div>
<div>
  <button id="goButton">
  Go
  </button>
</div>

CSS

textarea
{
  width: 100%;
  height: 20vh;
}

JavaScript

const getLines = (el) => 
{
  const text = el.value;
  const lines = text.split(/\n/).map(line => line.trim());
  let matchedModuleName = false;
  const libraryLines = lines.filter(line => {
    let no = line.match("├"); 
    let mmn = line.match("Module name");
    no = no || line.match("It might take a while");
    no = no || (mmn && matchedModuleName);
    no = no || line == "";
    no = no || line.match(/Packages \(/);
    matchedModuleName = matchedModuleName || mmn;
    if(!no){
      return true;
    }
  })
  
  return libraryLines;
}

const go = () => {
  const firstLines = getLines(first);
  const secondLines = getLines(second);

  const newLines = secondLines.filter(line => {
    return firstLines.indexOf(line) === -1 || line.match("Module");
  })

  result.value = newLines.join("\n");
}

goButton.addEventListener("click", () => go());