所有 Expo 支持的平台上都提供标准 TextEncoder 和 TextDecoder API。
标准 URL API 可在所有 Expo 支持的平台上使用。
¥The standard URL API is available on all Expo-supported platforms.
¥Installation
该 API 是 expo
包的一部分。请参阅 Web 和 Node.js 的 浏览器和服务器运行时支持。
¥This API is part of the expo
package. Refer to the browser and server runtime support for web and Node.js.
¥Usage
TextEncoder
和 TextDecoder
在全球范围内可用,无需导入。
¥TextEncoder
and TextDecoder
are available globally without any need to import them.
// [104, 101, 108, 108, 111]
const hello = new TextEncoder().encode('hello');
// "hello"
const text = new TextDecoder().decode(hello);
TextEncoder
API 包含在 Hermes 引擎中。参见 Hermes GitHub 存储库内的 TextEncoder.cpp 中的源代码。
¥The TextEncoder
API is included in the Hermes engine. See the source code in TextEncoder.cpp inside the Hermes GitHub repository.
TextDecoder
API 不是原生平台上的 spec-compliant。仅支持 UTF-8 编码。如果你需要支持更多编码,请使用像 text-encoding
这样的 polyfill。
¥The TextDecoder
API is not spec-compliant on native platforms. Only the UTF-8 encoding is supported. If you need support for more encodings, use a polyfill like text-encoding
.