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

synchronizationawaiterror

v0.1.2

Published

同步await错误

Readme

synchronizationawaiterror

wow! this awesome!

install

npm i -D synchronizationawaiterror

or

yarn add synchronizationawaiterror

Its implementation is very simple

definition

export declare function SynchronizationAwaitError<T, B, E = Error>(
  promise: Promise<T>,
  beautifyTeturnValue?: (res: T) => B,
  errorCaptured?: object
): Promise<[E, null] | [null, T | B]>;

use

第一个参数的返回值将是您返回的数组的第二个值

const [err, val] = SynchronizationAwaitError(Promise.resolve(1));

console.log(err, val); // null 1

第二个参数和他的名字一样,帮助你美化你的返回值

import { SynchronizationAwaitError } from "synchronizationawaiterror";
interface Service {
  res: string;
}
interface replaceType {
  res: number;
}
interface ErrorInterface {
  errorText: string;
}
(async function () {
  const [err, val] = await SynchronizationAwaitError<
    Service,
    replaceType,
    ErrorInterface
  >(
    // here!
    Promise.resolve({ res: "1" }),
    (result: Service) => {
      const replace = Object.assign(result, { res: parseInt(result.res) });
      return replace;
    },
    { errorText: "hava a error!" }
  );
  console.log(err, val); // null 1 => number
})();

第三个参数确定错误返回值

import { SynchronizationAwaitError } from "synchronizationawaiterror";
interface Service {
  res: string;
}
interface replaceType {
  res: number;
}
interface ErrorInterface {
  errorText: string;
}
(async function () {
  const [err, val] = await SynchronizationAwaitError<
    Service,
    replaceType,
    ErrorInterface
  >(
    // Pay attention here!
    Promise.reject({ err: "hiahia!" }),
    (result: Service) => {
      const replace = Object.assign(result, { res: parseInt(result.res) });
      return replace;
    },
    { errorText: "hava a error!" }
  );
  console.log(err, val); // { errorText: "hava a error!" , err: "hiahia!"  }
})();

记住它的名字! synchronizationawaiterror!