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

babel-plugin-pipe

v1.0.4

Published

a plugin of babel

Downloads

10

Readme

babel-plugin-pipeline

一款协助处理对象解构过程中的 null 和 undefined 的 babel 插件

// before
const { a } = test;
// after
const { a } = test || {};

how to use

  1. install
npm i -D babel-plugin-pipe
  1. 同其它正常的 babel 插件一样开启使用,例如:可以在 .babelrc 文件的 plugins 使用,但要把该插件放在数组的第一位,防止其它 babel 插件对当前的影响

  2. 文件顶部增加 @pipe 的注释,插件会自动对文件内的对象解构进行转换,对于需要使用原生用法的现象,可以通过增加 @pipe-next-line-disabled 或者 @pipe-next-line-disabled 注释来关闭该插件的转换

// @pipe
const { a1 } = test;
// @pipe-next-line-disabled
const { a2: b2 } = test;
const { a4: b4 = 'xxx' } = test; // @pipe-line-disabled

WARNING

对于下面这种格式,默认您已经对变量 c7 的格式做了兜底处理,所以插件不会再增加额外的兜底处理。

// before
const { a7: { b7 } = c7 } = test;
const { a8: { b8 } = {} } = test;
// @after
const { a7: _temp } = test || {},
      { b7 } = _temp || c7;
const { a8: _temp2 } = test || {},
      { b8 } = _temp2 || {};

@babel/plugin-proposal-pipeline-operator

可以与 @babel/plugin-proposal-pipeline-operator 插件一起配合使用,例如:

// before
// 其中 filterA/filterB/filterC 是已经定义后的方法
const {
  b = '' |> filterA |> filterC |> filterB
} = obj;
// after
const { b: _temp } = obj || {},
      b = (_temp || '') |> filterA |> filterC |> filterB;

格式如下:

const { a = '此处是默认值' |> filterA } = test;

pipeline-operator proposal 语法请参考插件文档。

LICENSE

MIT