Common practice for handling UTF-8. `decodeURIComponent` + `encodeURIComponent` composed would give identity function:

```
> btoa(decodeURIComponent(encodeURIComponent('ы')))
[Exception... "String contains an invalid character"  code: "5" nsresult: "0x80530005 (InvalidCharacterError)"  location: "<unknown>"]
> btoa(unescape(encodeURIComponent('ы')))
"0Ys="
```

More details are here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding#The_.22Unicode_Problem.22