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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mpex

v1.1.4

Published

微信小程序 API 的 Promise 版本,及实用方法集合

Downloads

27

Readme

mpex

微信小程序 API 的 Promise 版本,及实用方法集合

安装

使用 npm npm install -S mpex 使用 yarn yarn add mpex

使用说明

mpex 对绝大部分的小程序 API 进行了 Promise 化的封装。

首先导入 mpex 库。

import * as mpex from "mpex";
// 或者直接使用
import { <WxApi> } from "mpex"

以实现一个下载附件,保存附件,及询问用户是否打开附件的功能为例演示使用代码。

  async downloadAttachment(url: string) {
    mpex.showLoading("正在下载附件…");
    const ret1 = await mpex.downloadFile({ url: attachment.uri });
    const ret2 = await mpex.saveFile({ tempFilePath: ret1.tempFilePath });
    mpex.hideLoading();
    const msg = `附件已经下载完成。 点击确定马上打开。`;
    const res = await mpex.prompt(msg);
    if (res.confirm) {
      wx.openDocument({ filePath: ret2.savedFilePath });
    }
  }

除了 wx 命名空间下的 API。 本库 还提供了对 CameraContextMapContext 对象下的接口的 Promise 化封装。

export function promisifyMapContext(ctx: wx.MapContext);

export function promisifyCameraContext(ctx: wx.CameraContext);

下面是其他一些封装的常见功能。

  1. 使用封装的导航 API, 以 navigateTo 为例。 可免去手动拼接 query 的麻烦。
mpex.navigateTo("/pages/news/main", { newsId: 1988, cate: 2 });
  1. 提供 showActionSheet 的封装 chooseActionMenu 用于选择菜单的使用。TS 下有 TS 泛型加持。
const menus = [
  LeaveCategory.sick,
  LeaveCategory.absence,
  LeaveCategory.work
].map(category => {
  const title = formatLeaveCategory(category);
  return { title, category };
});
mpex.chooseActionMenu(menus).then(menu => {
  this.state.category = menu.category;
});

其他

有问题和建议欢迎通过 issue 反馈。