title: How can I format a string to fix indentation in Javascript?
body: <p>I am parsing a file in order to make some documentation.</p>
  
  <p>The string I am being returned is:</p>
  
  <pre><code>"([ {
                  href: "sass.html",
                  text: "Sass"
              }, {
                  href: "components.html",
                  text: "Components"
              }, {
                  href: "javascript.html",
                  text: "Javascript"
              } ])
              "
  </code></pre>
  
  <p>I would like to prettify this so I can output it into a pre tag. So the ideal output would be something like this:</p>
  
  <pre><code>"(
    [
      {
        href: "sass.html",
        text: "Sass"
      },
      {
        href: "components.html",
        text: "Components"
      },
      {
        href: "javascript.html",
        text: "Javascript"
      }
    ]
  )"
  </code></pre>
  
  <p>I am currently thinking I could remove all spacing in the string via:</p>
  
  <pre><code>string.replace(/\s/g,'')
  </code></pre>
  
  <p>Then do a bunch of splits to break each line apart and add spacing for indentation and rejoin it but this feels messy to me. Is there a better way I could so this?</p>
  
  <p>Any advice is of course greatly appreciated. </p>
  
  <p>This is different from: <a href="https://stackoverflow.com/questions/2614862/how-can-i-beautify-json-programmatically">How can I beautify JSON programmatically?</a> because i am dealing with a string on non-valid JSON.</p>