purescript/purescript-strings

Data.String.Unsafe.char is not Unicode-aware

ayaka14732 opened this issue ยท 1 comments

Current Data.String.Unsafe.char :: String -> Char implementation,

exports.char = function (s) {
  if (s.length === 1) return s.charAt(0);
  throw new Error("Data.String.Unsafe.char: Expected string of length 1.");
};

https://github.com/purescript/purescript-strings/blob/v4.0.1/src/Data/String/Unsafe.js#L10-L13

fails to handle the strings like "๐€".

Yes, this is expected: a Char is exactly one UTF-16 code unit, so you can't fit any astral plane code points into a Char. If you avoid Data.String.Unsafe and just use Data.String then you'll be ok.