miniprogram-text-decoder
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

miniprogram-text-decoder

小程序的TextDecoder polyfill。

此库基于FastestSmallestTextEncoderDecoder修改为小程序版本


支持的小程序

  • 微信小程序
  • 支付宝小程序
  • 字节小程序

其他小程序没有进行测试,可以自行测试


需要注意的问题

  • TextDecoder构造函数参数utfLabel只支持utf-8(默认值), options.fatal 不支持
  • decode方法参数options.stream 不支持
  • encoding属性固定返回utf-8

Example

import TextDecoder from 'miniprogram-text-decoder'

// 设置为全局对象
// globalThis.TextDecoder = TextDecoder

const TextDecoder = new TextDecoder();
TextDecoder.decode('测试')

TIP:
支付宝小程序IDE环境下globalThis为undefined,解决方法
字节小程序所有环境的globalThis都为undefined,暂时无法设置全局变量。


API

参考: https://developer.mozilla.org/zh-CN/docs/Web/API/TextDecoder

Package Sidebar

Install

npm i miniprogram-text-decoder

Weekly Downloads

32

Version

2.0.0

License

MIT

Unpacked Size

9.34 kB

Total Files

7

Last publish

Collaborators

  • zhaoyirong