* Decodes Unicode code points from bytes using given encoding. * @param {Uint8Array} bytes * @param {String} [encoding='utf8'] * @throws {Error} Throws an error if given encoding is not supported. * @throws {TextEncodingError} Throws an error if given bytes are malformed. * @return {n
(bytes, encoding = 'utf8')
| 147 | * @return {number[]} Array of Unicode code points |
| 148 | */ |
| 149 | static codePointsFromBytes (bytes, encoding = 'utf8') { |
| 150 | switch (encoding) { |
| 151 | case 'utf8': |
| 152 | return TextEncoder._decodeCodePointsFromUTF8Bytes(bytes) |
| 153 | default: |
| 154 | throw new Error( |
| 155 | `Decoding from '${encoding}' is currently not supported.`) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static _encodeCodePointsToUTF8Bytes (codePoints) { |
| 160 | // In the worst case every code point needs to be represented by 4 bytes |
no test coverage detected