Skip to content

Instantly share code, notes, and snippets.

View gabrielvisconti89's full-sized avatar
🏠
Working from home

Gabriel Visconti gabrielvisconti89

🏠
Working from home
View GitHub Profile
@gabrielvisconti89
gabrielvisconti89 / utf8-regex.js
Created May 12, 2021 11:18 — forked from chrisveness/utf8-regex.js
Utf8 string encode/decode using regular expressions
/**
* Encodes multi-byte Unicode string into utf-8 multiple single-byte characters
* (BMP / basic multilingual plane only).
*
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars.
*
* Can be achieved in JavaScript by unescape(encodeURIComponent(str)),
* but this approach may be useful in other languages.
*
* @param {string} unicodeString - Unicode string to be encoded as UTF-8.