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

@gityoog/wrequest

v1.2.3

Published

Promise Wrap

Downloads

9

Readme

WRequest

Promise Wrap

Installation

$ npm install wrequest@npm:@gityoog/wrequest --save

or

$ npm install git+https://github.com/gityoog/wrequest.git --save

Usage

// 1.创建实例
const request = new WRequest(() => promise);

// 2.链式回调(支持异步/同步回调)
request
  .load(() => {
    // 运行中回调
  })
  .abort((result) => {
    // @param result: 被包装Promise的运行结果
    // @return boolean|void: 返回true可以中断load以外的回调调用(常用于重复请求判断等)
  })
  .success((data) => {
    // 成功回调(以注册的正序顺序运行)
    // @param T: 成功返回值
  })
  .validate((data) => {
    // @param T: 成功返回值
    // @return boolean|string: 返回true|string可停止后续成功回调进入错误处理
  })
  .transform((data) => {
    // @param T: 成功返回值
    // @return RT: 返回新值传递后续成功回调, 抛出错误可停止后续成功回调进入错误处理
  })
  .map((data) => {
    // transform 别名
  })
  .fail((error) => {
    // @param string: 上层错误提示
    // @return string|void: 错误回调以注册逆序运行 如无返回 将停止后续错误回调运行
  })
  .final(() => {
    // 结束回调
  })
  .after.success(() => {
    // 成功回调后的回调
  })
  .after.fail((error) => {
    // 失败回调后的回调
  })
  .promise() // to promise
  .debug.delay() // 调试专用 增加延时(默认: 1000ms)
  .debug.success(data) // 调试专用 直接使用成功Promise运行 map模拟不可逆 将移除之前新增的map逻辑
  .debug.fail(data); // 调试专用 直接使用失败Promise运行

// 3.Generator Build
const api = WRequest.Build((params: types) => Promise.resolve(data));

const newApi = api
  .params((params) => {
    return {
      body: params,
    };
  })
  .handle((r) =>
    r.transform((data) => {
      return {
        result: data,
      };
    })
  );

newApi(params).success((data) => {}); // ....
// or
newApi.cache(params, keys /*optional*/).success((data) => {}); // ....

Changelog

  • v1.1 2022-11-23 add Generator Build
  • v1.2 2023-03-09 print unknown error
  • v1.2.2 2023-06-09 fix builder.params()