npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

weapp-polyfill

v3.2.2

Published

Browser API polyfill for Weapp

Downloads

11

Readme

weapp-polyfill npm

Polyfills for w3c API on top of Weapp API, including:

  • XMLHttpRequest
  • FormData
  • WebSocket
  • localStorage
  • online/offline events

Why

微信小程序设计了一系列 IO 相关的 API,但社区中现存的模块绝大部分使用的是 w3c 标准的 API。本项目通过 polyfill 这些 w3c API 允许开发者在不修改第三方模块代码的情况下直接在小程序中使用这些模块。

Usage

npm i weapp-polyfill -D

如果你的应用或 SDK 使用打包工具(打包成一个文件后再导入微信开发工具使用),你可以在程序入口的最开始 auto polyfill 所有 API

require('weapp-polyfill/auto-polyfill');

即可在整个项目中直接使用浏览器 API。See a realworld demo

weapp-polyfill pacakge 本身 export 了以下对象:

const {
  XMLHttpRequest,·
  FormData,
  WebSocket,
  localStorage,
  polyfill,
} = require('weapp-polyfill');

不支持不使用打包工具直接在微信开发工具使用。

Caveats

由于微信 API 与小程序运行时的限制,polyfill 的 API 有以下限制:

XMLHttpRequest

  • 不会出现 HEADERS_RECEIVEDLOADING 状态

FormData

  • Blob 被定义为一个拥有 uri 属性的对象,uri 的值为通过微信 API 得到的本地临时文件路径:{ uri: 'tempFilePath' }
  • 如果一个 FormData append 了多个 blob,只有第一个会被发送

online/offline events

  • 仅当使用 auto polyfill 功能时有效。当网络状态变化时,会在当前模块的 global/window 中派发 online/offline 事件。

Changelogs

3.2.2

  • 修复了 WebSocket protocol 参数为 string 类型时在真机最新基础库上报错的问题

3.2.1

  • 修复了 WebSocket protocol 参数不生效的问题

3.2.0

  • WebSocket 支持多实例(需要基础库 >= 1.7.0)

3.1.2

  • 修复了导致 Babel 提供的 Promise 失效的兼容性问题
  • 修复了 WebSocket is not connected 错误
  • 修复小程序中一个 regression

3.1.1

  • 修复 auto-polyfill 在小游戏真机上没有生效的问题

3.1.0

  • 支持微信小游戏

3.0.0

  • WebSocket 增加了以下特性
    • 支持 subprotocol
    • 支持二进制帧(ArrayBuffer)
  • 增加 online/offline events 支持

2.0.1

  • XMLHttpRequest 忽略 response headers key 的大小写。

2.0.0

  • XMLHttpRequest 增加了以下特性
    • 支持获取 Response Headers
    • 支持通过 xhr.upload 获取文件上传进度
    • 支持 abort