Format template string to remove whitespace but support indentation : <p>Say I have the following template string:</p>

<pre><code>const str1 = ` 
        const x = 5;
`
</code></pre>

<p>If I were to render it in the DOM it would take into consideration the whitespace before the string begins and render it with the whitespace. I could solve this using <code>str1.trim()</code>, but, lets say we have another string:</p>

<pre><code>const str2 = `
        const x = 1;
          const y = 2;
            const z = 3;
`
</code></pre>

<p>I would like to remove the whitespace before each string row but preserve the indentation. An expected result would look something like:</p>

<pre><code>const x = 1;
  const y = 2;
    const z = 3;
</code></pre>

<p>Is there a way I could achieve this with either regex or js ?</p>
