Comparing version 0.2.0 to 0.3.0
{ | ||
"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') | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93
3938
4
0
1