Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-const-enum

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-const-enum - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

LICENSE

2

package.json
{
"name": "babel-plugin-const-enum",
"version": "0.0.0",
"version": "0.0.1",
"description": "Transform TypeScript `const` enums",

@@ -5,0 +5,0 @@ "repository": "https://github.com/dosentmatter/babel-plugin-const-enum",

@@ -18,1 +18,110 @@ # babel-plugin-const-enum

```
## Usage
### `removeConst` (default)
Removes the `const` keyword to use regular `enum`.
Can be used in a slower dev build to allow `const`, while prod still uses `tsc`.
See [babel#6476](https://github.com/babel/babel/issues/6476).
```ts
// Before:
const enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
// After:
enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
```
`.babelrc`
```json
{
"plugins": [
"const-enum"
]
}
```
Or Explicitly:
`.babelrc`
```json
{
"plugins": [
[
"const-enum",
{
"transform": "removeConst"
}
]
]
}
```
### `constObject`
Transforms into a `const` object literal.
Can be further compressed using Uglify/Terser to inline `enum` access.
See [babel#8741](https://github.com/babel/babel/issues/8741).
```ts
// Before:
const enum MyEnum {
A = 1,
B = A,
C,
D = C,
E = 1,
F,
G = A * E,
H = A ** B ** C,
I = A << 20
}
// After:
const MyEnum = {
A: 1,
B: 1,
C: 2,
D: 2,
E: 1,
F: 2,
G: 1,
H: 1,
I: 1048576
};
```
`.babelrc`
```json
{
"plugins": [
[
"const-enum",
{
"transform": "constObject"
}
]
]
}
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc