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

uniapp-promisify

v0.3.2

Published

Uni App API Promisify

Downloads

67

Readme

NPM Version NPM Downloads Build GitHub issues GitHub pull requests GitHub License

English | 简体中文

初衷

UniApp 官方的 API 使用的是过时的回调风格,尽管最新版本的 UniApp 的部分 API 支持了 Promise 的调用,但官方 API 的类型并没有对其支持,更糟糕的是官方的 Promise 调用方式在 Vue 2 和 Vue 3 中的行为不同

与其手动处理多个平台的条件判断和类型转换,不如直接对官方的回调 API 进行简单的包装,将回调函数转换为 Promiseresolvereject,并自动推断返回类型。

安装

npm install uniapp-promisify
# Or use yarn
yarn add uniapp-promisify
# Or use pnpm
pnpm i uniapp-promisify

使用

uniapp-promisify 导出了一个名为 promisify 的函数,可以按照以下方式使用:

  • Promise 化单个函数
import { promisify } from 'uniapp-promisify'

const login = promisify(uni.login)
const res = await login()
//     ^? UniNamespace.LoginRes
  • Promise 化整个 uni 全局对象
import { promisify } from 'uniapp-promisify'

const pUni = promisify(uni)
const res = await pUni.login()
//     ^? UniNamespace.LoginRes
  • 直接使用 uniapp-promisify 中已经 Promise 化的 uni 对象
import { uni } from 'uniapp-promisify'

同步 API

由于在一些情况下无法使用异步方式调用,因此当使用被 Promise 化的 uni 全局对象时,可以通过 uni.sync 属性映射到原本的没有被包装过的 uni 对象。

import { uni } from 'uniapp-promisify'

// uni.getUserProfile() 只能在同步函数中调用
const res = uni.sync.getUserProfile()

许可证

本项目使用 AGPL-3.0 许可证 - 有关详细信息,请参阅 LICENSE 文件。