title: Parsing text into javascript String
body: <p>I am trying to parse some text into javascript strings. In essence I have a String in javascript containing what would be another javascript string. Here are some samples that I have in my tests:</p>
  
  <pre><code>input1: '"This \\"should\\" work"' 
  output1: 'This "should" also work'
  
  input2: '"Another working \\nstring\\n with newlines"'
  output2: 'Another working \nstring\n with newlines'
  
  // Should throw an exception since it would escape the last ":
  input3: '"This should not work\\"'
  
  // Should throw an exception since it contains an illegal newline
  input4: '"This \n should also not work"'
  </code></pre>
  
  <p>I was considering using <code>eval</code> on the input strings but it feels like a hack and I am unsure if it is safe. <strike>It doesn't yield an error on the <code>input3</code> sample when I try it in Node.</strike>It works when running my tests but not when used I run: <code>eval('"This should not work\\"')</code> in Node directly.</p>
  
  <p><strong>How can I parse the above sample inputs to their corresponding outputs and still get errors for the bad samples?</strong></p>
  
  <p><strong>EDIT:</strong><br>
  My initial atempt:</p>
  
  <pre><code>output = input.slice(1, input.length - 1)
  </code></pre>
  
  <p>My second atempt:</p>
  
  <pre><code>output = eval(input); 
  </code></pre>
  
  <p>Using <code>eval</code> seems to work , but feels like a hack. </p>