# babel-plugin-pipe

> a plugin of babel

Latest version **1.0.4** (published 2019-06-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-pipe
pnpm add babel-plugin-pipe
yarn add babel-plugin-pipe
bun add babel-plugin-pipe
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-06-16 |
| First published | 2019-03-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | qingguoing@gmail.com |
| Maintainers | qingguoing |
| Keywords | pipe, pipeline, Object destructuring |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-pipe
- Repository: https://github.com/qingguoing/babel-plugin-pipeline
- Homepage: https://github.com/qingguoing/babel-plugin-pipeline#readme
- Issues: https://github.com/qingguoing/babel-plugin-pipeline/issues
- npm.io page: https://npm.io/package/babel-plugin-pipe

## Dependencies (1)

- [@babel/core](https://npm.io/package/@babel/core.md) ^7.4.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-06-16
- 1.0.3 — 2019-06-10
- 1.0.2 — 2019-04-12
- 1.0.1 — 2019-04-09
- 1.0.0 — 2019-03-27
- 0.0.1 — 2019-03-27

## README

### babel-plugin-pipeline

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

```js
// before
const { a } = test;
```

```js
// after
const { a } = test || {};
```

### how to use
1. install

```js
npm i -D babel-plugin-pipe
```

2. 同其它正常的 babel 插件一样开启使用，例如：可以在 `.babelrc` 文件的 `plugins` 使用，**但要把该插件放在数组的第一位，防止其它 babel 插件对当前的影响**

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

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

#### WARNING

对于下面这种格式，默认您已经对变量 c7 的格式做了兜底处理，所以插件不会再增加额外的兜底处理。
```js
// before
const { a7: { b7 } = c7 } = test;
const { a8: { b8 } = {} } = test;
```

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

### @babel/plugin-proposal-pipeline-operator

可以与 [@babel/plugin-proposal-pipeline-operator](https://babeljs.io/docs/en/next/babel-plugin-proposal-pipeline-operator.html) 插件一起配合使用，例如：

```js
// before
// 其中 filterA/filterB/filterC 是已经定义后的方法
const {
  b = '' |> filterA |> filterC |> filterB
} = obj;
```

```js
// after
const { b: _temp } = obj || {},
      b = (_temp || '') |> filterA |> filterC |> filterB;
```

格式如下：

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

`pipeline-operator proposal` 语法请参考[插件](https://babeljs.io/docs/en/next/babel-plugin-proposal-pipeline-operator.html)文档。

### LICENSE
MIT

---
_Source: https://npm.io/package/babel-plugin-pipe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
