{"id":19614771,"url":"https://github.com/leancloud/weapp-polyfill","last_synced_at":"2025-04-28T01:32:17.476Z","repository":{"id":11421030,"uuid":"69627729","full_name":"leancloud/weapp-polyfill","owner":"leancloud","description":"Polyfills for w3c API on top of Weapp API","archived":false,"fork":false,"pushed_at":"2022-06-23T00:28:24.000Z","size":125,"stargazers_count":46,"open_issues_count":5,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-05T04:51:16.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-30T02:50:24.000Z","updated_at":"2024-10-25T11:00:02.000Z","dependencies_parsed_at":"2022-09-09T02:10:52.157Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/weapp-polyfill","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fweapp-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/weapp-polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251234128,"owners_count":21556787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T10:53:42.058Z","updated_at":"2025-04-28T01:32:16.038Z","avatar_url":"https://github.com/leancloud.png","language":"JavaScript","funding_links":[],"categories":["组件"],"sub_categories":[],"readme":"# weapp-polyfill [![npm](https://img.shields.io/npm/v/weapp-polyfill.svg?style=flat-square)](https://www.npmjs.com/package/weapp-polyfill)\nPolyfills for w3c API on top of Weapp API, including:\n\n- XMLHttpRequest\n- FormData\n- WebSocket\n- localStorage\n- online/offline events\n\n## Why\n微信小程序设计了一系列 IO 相关的 API，但社区中现存的模块绝大部分使用的是 w3c 标准的 API。本项目通过 polyfill 这些 w3c API 允许开发者在不修改第三方模块代码的情况下直接在小程序中使用这些模块。\n\n## Usage\n```\nnpm i weapp-polyfill -D\n```\n\n如果你的应用或 SDK 使用打包工具（打包成一个文件后再导入微信开发工具使用），你可以在程序入口的最开始 auto polyfill 所有 API\n\n```\nrequire('weapp-polyfill/auto-polyfill');\n```\n\n即可在整个项目中直接使用浏览器 API。See a [realworld demo](https://github.com/leancloud/javascript-sdk/blob/35af5a0547b1d48d3d933fac1fae0eaf16083fa9/src/index-weapp.js)。\n\nweapp-polyfill pacakge 本身 export 了以下对象：\n\n```\nconst {\n  XMLHttpRequest,·\n  FormData,\n  WebSocket,\n  localStorage,\n  polyfill,\n} = require('weapp-polyfill');\n```\n\n不支持不使用打包工具直接在微信开发工具使用。\n\n## Caveats\n由于微信 API 与小程序运行时的限制，polyfill 的 API 有以下限制：\n\n### XMLHttpRequest\n- 不会出现 `HEADERS_RECEIVED` 与 `LOADING` 状态\n\n### FormData\n- Blob 被定义为一个拥有 `uri` 属性的对象，`uri` 的值为通过微信 API 得到的本地临时文件路径：`{ uri: 'tempFilePath' }`\n- 如果一个 FormData append 了多个 blob，只有第一个会被发送\n\n### online/offline events\n- 仅当使用 auto polyfill 功能时有效。当网络状态变化时，会在当前模块的 global/window 中派发 online/offline 事件。\n\n## Changelogs\n\n#### 3.2.2\n- 修复了 WebSocket protocol 参数为 string 类型时在真机最新基础库上报错的问题\n\n#### 3.2.1\n- 修复了 WebSocket protocol 参数不生效的问题\n\n### 3.2.0\n- WebSocket 支持多实例（需要基础库 \u003e= 1.7.0）\n\n#### 3.1.2\n- 修复了导致 Babel 提供的 Promise 失效的兼容性问题\n- 修复了 `WebSocket is not connected` 错误\n- 修复小程序中一个 regression\n\n#### 3.1.1\n- 修复 auto-polyfill 在小游戏真机上没有生效的问题\n\n### 3.1.0\n-  支持微信小游戏\n\n### 3.0.0\n- WebSocket 增加了以下特性\n  - 支持 subprotocol\n  - 支持二进制帧（ArrayBuffer）\n- 增加 online/offline events 支持\n\n#### 2.0.1\n- XMLHttpRequest 忽略 response headers key 的大小写。\n\n### 2.0.0\n- XMLHttpRequest 增加了以下特性\n  - 支持获取 Response Headers\n  - 支持通过 xhr.upload 获取文件上传进度\n  - 支持 abort\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fweapp-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Fweapp-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fweapp-polyfill/lists"}