19 lines
639 B
JavaScript
19 lines
639 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toUtf8 = toUtf8;
|
|
exports.fromUtf8 = fromUtf8;
|
|
function toUtf8(str) {
|
|
return new TextEncoder().encode(str);
|
|
}
|
|
/**
|
|
* Takes UTF-8 data and decodes it to a string.
|
|
*
|
|
* In lossy mode, the [REPLACEMENT CHARACTER](https://en.wikipedia.org/wiki/Specials_(Unicode_block))
|
|
* is used to substitute invalid encodings.
|
|
* By default lossy mode is off and invalid data will lead to exceptions.
|
|
*/
|
|
function fromUtf8(data, lossy = false) {
|
|
const fatal = !lossy;
|
|
return new TextDecoder("utf-8", { fatal }).decode(data);
|
|
}
|
|
//# sourceMappingURL=utf8.js.map
|