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

wh-auto-trycatch

v1.0.1

Published

全局为async/await自动添加trycatch

Downloads

1

Readme

babel自定义插件: wh-auto-trycatch


在日常开发中经常会遇到使用async&&await对异步promise方法的同步使用,但是很多时候我们总的手动添加try&&catch,为了避免这个重复动作,我开发了这款babel插件来帮助我完成这一个动作

效果:

before:

async doSth(){
  const data = await getSth()
}

after:

try {
  async doSth(){
    const data = await getSth()
  }
} catch (e) {
  console.log(CatchError,e)
}`;
(注意: 所有代码都会被置入tryCatch的包裹中,如果你的代码不希望被包括,请自行处理逻辑 !!)

使用步骤

一、项目安装插件

npm i --save wh-auto-trycatch

二、项目安装插件

在babel.config.json中配置

plugins: [
    [
      require('wh-auto-trycatch'), 
     {
       exclude: ['node_modules'], // 默认值 ['node_modules'] ,排除文件
       include: ['main.js'], // 默认值 [] ,入口文件
       customLog: 'error code:404 not found', // 默认值 'Error', 捕获Error的提示文案
     }
   ]
]

本插件原理是利用对ast AwaitExpression的判断,并将其包裹的ast置入我预设的trycatch代码模板,最终生成我们需要的效果

tips:

  • 如果代码已添加trycatch, 本插件会忽略插入
  • 表达式、箭头函数、声明式函数都做了兼容哦!

最后

  • 由于水平有限,本插件并未十分完善或部分项目可能无法使用,这里只提供参考和思想,各位看官谨慎使用!!!