title: Determine OS newline in JavaScript
body: <p>I am generating a file for the user to download, and I want to insert the correct newline character(s) for their platform (<code>\n</code>, <code>\r</code>, or <code>\r\n</code>).</p>
  
  <p>I am aware of the following solutions, but none solve my problem exactly:</p>
  
  <ul>
  <li>Querying <code>navigator.platform</code> or <code>navigator.appVersion</code>. These properties are <a href="https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID/appVersion" rel="nofollow noreferrer">deprecated</a>, so I would prefer not to rely on them.</li>
  <li>There are specific approaches for <a href="https://stackoverflow.com/a/22664158/2683771">Firefox</a> and <a href="https://stackoverflow.com/a/12989543/2683771">NodeJS</a>. These do not apply, as I'm creating a website, and I would prefer if it worked on all browsers.</li>
  <li>There are ways to find <a href="https://stackoverflow.com/a/8556867/2683771">the <em>browser's</em> newline characters</a>, but I'm interested in the user's platform. (These are different: Firefox always uses <code>\n</code>, regardless of the OS.)</li>
  </ul>