title: Split JavaScript string into array of codepoints? (taking into account "surrogate pairs" but not "grapheme clusters")
body: <p>Splitting a JavaScript string into "characters" can be done trivially but there are problems if you care about Unicode (and you should care about Unicode).</p>
  
  <p>JavaScript natively treats characters as 16-bit entities (<a href="https://en.wikipedia.org/wiki/UTF-16" rel="noreferrer">UCS-2 or UTF-16</a>) but this does not allow for Unicode characters outside the <a href="https://en.wikipedia.org/wiki/Plane_%28Unicode%29#Basic_Multilingual_Plane" rel="noreferrer">BMP (Basic Multilingual Plane)</a>.</p>
  
  <p>To deal with Unicode characters beyond the BMP, JavaScript must take into account "<a href="https://stackoverflow.com/questions/tagged/surrogate-pairs">surrogate pairs</a>", which it does not do natively.</p>
  
  <p><strong>I'm looking for how to split a js string by codepoint, whether the codepoints require one or two JavaScript "characters" (code units).</strong></p>
  
  <p>Depending on your needs, splitting by <a href="https://en.wikipedia.org/wiki/Code_point" rel="noreferrer">codepoint</a> might not be enough, and you might want to split by "<a href="http://www.termwiki.com/EN:grapheme_cluster" rel="noreferrer">grapheme cluster</a>", where a cluster is a base codepoint followed by all its non-spacing modifier codepoints, such as <a href="https://en.wikipedia.org/wiki/Combining_character" rel="noreferrer">combining accents and diacritics</a>.</p>
  
  <p><strong>For the purposes of this question I do not require splitting by grapheme cluster.</strong></p>