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

enum-xyz

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enum-xyz - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

4

package.json
{
"name": "enum-xyz",
"type": "module",
"version": "0.2.0",
"version": "0.3.0",
"description": "JavaScript enums using proxies.",

@@ -29,4 +29,4 @@ "homepage": "https://github.com/chasefleming/enum-xyz",

"jest": "^27.5.1",
"microbundle": "^0.14.2"
"microbundle": "^0.15.1"
}
}
# enum-xyz
JavaScript enums using proxies.
`enum-xyz` offers a way to generate enums in JavaScript leveraging the power of Proxies. It supports various casing styles, transformations, and other customization options.

@@ -27,7 +27,23 @@ > Based on [this tweet](https://twitter.com/2ality/status/1486139713354448897)

console.log(Summer); // Outputs: "Summer"
console.log(Autumn); // Outputs: "Autumn"
console.log(Winter); // Outputs: "Winter"
console.log(Spring); // Outputs: "Spring"
```
#### Options for String Enums:
- `casing`: Transforms the string based on the specified casing style. Available options are `snakeCase`, `camelCase`, `PascalCase`, `kebabCase`, `lowercase`, and `uppercase`.
- `transform`: Provide a custom function to transform the enum values. This function takes the original value and returns a transformed value.
##### Example:
```
const { userId, userAddress } = Enum.String({ casing: 'kebabCase' });
console.log(userId); // Outputs: "user-id"
const options = {
casing: 'kebabCase',
transform: (value) => `https://api.example.com/${value}`
};
const { userEndpoint, orderEndpoint } = Enum.String(options);
console.log(userEndpoint); // Outputs: "https://api.example.com/user-endpoint"
```
### Numeric Enums

@@ -43,12 +59,15 @@

console.log(A); // Outputs: 0
console.log(B); // Outputs: 1
console.log(C); // Outputs: 2
console.log(D); // Outputs: 3
```
To start from a different index:
#### Options for Numeric Enums:
- `startIndex`: Start the numeric enum from a specific index.
- `step`: Increment the numeric values by a specific step (e.g., 2, 5, 10).
##### Example:
```
const { A, B, C, D } = Enum.Numeric(5);
const { A, B, C } = Enum.Numeric({ startIndex: 5, step: 2 });
console.log(A); // Outputs: 5
console.log(B); // Outputs: 7
```

@@ -64,3 +83,13 @@

console.log(blue); // Outputs: Symbol(blue)
console.log(red); // Outputs: Symbol(red)
```
#### Options for Symbol Enums:
- `global`: Create a global symbol using Symbol.for().
##### Example:
```
const { blueGlobal } = Enum.Symbol({ global: true });
console.log(blueGlobal); // Outputs: Symbol.for('blueGlobal')
```
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