# babel-plugin-enum-to-object

> transform enum to object for better tree shaking

Latest version **0.2.3** (published 2023-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-enum-to-object
pnpm add babel-plugin-enum-to-object
yarn add babel-plugin-enum-to-object
bun add babel-plugin-enum-to-object
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2023-04-22 |
| First published | 2023-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | baozouai |
| Maintainers | baozouai |
| Keywords | babel, plugin, enum, typescript, node, tree shaking, enum to oeject |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-enum-to-object
- Repository: https://github.com/baozouai/babel-plugin-enum-to-object
- Issues: https://github.com/baozouai/babel-plugin-enum-to-object/issues
- npm.io page: https://npm.io/package/babel-plugin-enum-to-object

## Dependencies (3)

- [@babel/generator](https://npm.io/package/@babel/generator.md) ^7.21.4
- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.20.2
- [@babel/plugin-syntax-typescript](https://npm.io/package/@babel/plugin-syntax-typescript.md) ^7.21.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2023-04-22
- 0.2.3-beta.0 — 2023-04-22
- 0.2.2 — 2023-04-22
- 0.2.1 — 2023-04-22
- 0.1.0 — 2023-04-17

## README

<p align="center">
<h1 align="center">babel-plugin-enum-to-object</h1>
</p>

<div align="center">


 [![NPM version][npm-image]][npm-url] ![NPM downloads][download-image]

![Test][test-badge] ![codecov][codecov-badge]


[npm-image]: https://img.shields.io/npm/v/babel-plugin-enum-to-object.svg?style=flat-square
[npm-url]: http://npmjs.org/package/babel-plugin-enum-to-object


[download-image]: https://img.shields.io/npm/dm/babel-plugin-enum-to-object.svg?style=flat-square



[test-badge]: https://github.com/baozouai/babel-plugin-enum-to-object/actions/workflows/ci.yml/badge.svg

[codecov-badge]: https://codecov.io/github/baozouai/babel-plugin-enum-to-object/branch/master/graph/badge.svg

</div>

English | [中文](./README-zh_CN.md)
## About

A babel Plugin to transform ts enum to object，for better shaking


## Options

```ts
  interface BabelPluginEnumToObjectOptions {
  /**
   * need reflect ? default true
   * @example
   * enum Status {
   *  PAID
   * }
   * reflect: true
   * =>
   * const Status = {
   * PAID: 0,
   * 0: 'PAID',
   * }
   * reflect: false
   * =>
   * const Status = {
   * PAID: 0,
   * }
   */
  reflect?: boolean
}
```
eg:

before add plugin：
```ts
enum Status {
  PAID,
  UN_PAID
}

// =>

var Status;
(function (Status) {
  Status[Status.PAID = 0] = 'PAID'
  Status[Status.UN_PAID = 1] = 'UN_PAID'
})(Status || (Status = {}))
```

after add plugin：
```ts
enum Status {
  PAID,
  UN_PAID
}

// =>
// default (reflect is true)
const Status = {
  PAID: 0,
  0: 'PAID',
  UN_PAID: 1,
  1: 'UN_PAID'
}
//  set reflect false
const Status = {
  PAID: 0,
  UN_PAID: 1,
}
```


## 📦  Install

```sh
pnpm add babel-plugin-enum-to-object -D
# or
yarn add babel-plugin-enum-to-object -D
# or
npm i babel-plugin-enum-to-object -D
```

##  🔨 Usage

```js
// babel.config.js

module.exports = {

  plugins: [
    // if isProduction add this
    ['enum-to-object', { reflect: true or false }]
  ],
}
```
## 📄 License

babel-plugin-enum-to-object is [MIT licensed](./LICENSE).

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