* Returns a UTF8-encoded binary string i.e. one byte per character. * Returns the original string in case it was already within ASCII.
(str)
| 188 | * Returns the original string in case it was already within ASCII. |
| 189 | */ |
| 190 | function string2byteString(str) { |
| 191 | if (!/[\u0080-\uFFFF]/.test(str)) return str; |
| 192 | if (!encoder) encoder = new TextEncoder(); |
| 193 | return buffer2string(encoder.encode(str)); |
| 194 | } |
| 195 | |
| 196 | // Chrome 74-91 needs an extraHeaders listener at tab load start, https://crbug.com/1074282 |
| 197 | // We're attaching a no-op in non-blocking mode so it's very lightweight and fast. |
no test coverage detected