function escapeUnicodeChars (
  // see https://www.wikiwand.com/en/UTF-16
  text
) {
  return (
    // note: we leave surrogate pairs as two individual chars,
    // as JSON doesn't interpret them as a single unicode char.
    text.replace(
      /[\u007F-\uFFFF]/g,
      c => '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4)
    )
  )
}
Escape unicode characters.
For example input '\u2661' (length 1) will output '\\u2661' (length 5).
@param {string} text
@return {string}