https://github.com/nitzano/enum-converter
Convert enums from one language to another
https://github.com/nitzano/enum-converter
ast enum enum-converter enums transpiler
Last synced: about 1 year ago
JSON representation
Convert enums from one language to another
- Host: GitHub
- URL: https://github.com/nitzano/enum-converter
- Owner: nitzano
- License: mit
- Created: 2018-05-03T17:45:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T10:50:27.000Z (over 3 years ago)
- Last Synced: 2024-05-06T00:18:46.982Z (about 2 years ago)
- Topics: ast, enum, enum-converter, enums, transpiler
- Language: TypeScript
- Homepage: https://enum-converter.vercel.app
- Size: 1.89 MB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Enum Converter (enumc)
Convert Enums from one language to another.
Live demo : https://enum-converter.vercel.app
([source](https://github.com/nitzano/enum-converter-demo))
[](https://www.npmjs.com/package/enum-converter)
[](https://www.npmjs.com/package/enum-converter)
[](https://www.npmjs.com/package/enum-converter)


[](https://github.com/nitzano/enum-converter/blob/master/LICENSE)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
---
- [Supported languages](#supported-languages)
- [Installation](#installation)
- [Usage](#usage)
- [CLI](#cli)
- [API](#api)
- [Options](#options)
- [Conversion](#conversion)
- [Styling](#styling)
## Supported languages
* [x] Java
* [x] Json
* [x] Python
* [x] Typescript
* [ ] C/C++
* [ ] C#
* [ ] Go
## Installation
```
npm install -g enum-converter
```
## Usage
### CLI
> ``` enumc [options] ```
```
// convert files
enumc enums.py --to typescript
enumc enums.ts --to python --out my-enums.py
enumc enums.x --from python --to json
enumc enums.py --to typescript --sort-enums asc
// modify existing files
enumc enums.py --modify --name-style kebab --key-style upper
enumc enums.py --modify --sort-enums=asc --sort-values=value_desc
```
### API
```typescript
import {
convert,
EnumsOrder,
Language,
modify,
StringStyle,
ValuesOrder,
} from 'enum-converter';
// convert files
convert('enums.py', Language.Typescript);
convert('enums.ts', Language.Python, {
out: 'my-enums.py'
});
convert('enums.x', Language.Json, {
from: Language.Python
});
convert('enums.py', Language.Typescript, {
sortEnums: EnumsOrder.Ascending
});
// modify exiting files
modify('enums.py' {
nameStyle: StringStyle.KebabCase,
keyStyle: StringStyle.UpperCase,
})
modify('enums.py' {
sortEnums: EnumsOrder.Ascending,
sortValues: ValuesOrder.ValueDescending,
})
```
## Options
### Conversion
| Name | Meaning | type | default |
| ------ | -------------------------- | -------- | ------- |
| from | source language (explicit) | Language | |
| to | destination language | Language | |
| out | destination file | string | |
| modify | modify existing file | boolean | false |
### Styling
| Name | Meaning | type | default |
| -------------- | ----------------------------------------- | ----------- | ------- |
| emit-file-name | emit source file name to destination file | boolean | true |
| emit-stats | emit stats to destination file | boolean | true |
| sort-enums | sort enums in files | EnumsOrder | |
| sort-values | sort values in enums | ValuesOrder | |
| key-style | style enum key string | StringStyle | |
| name-style | style enum name string | StringStyle | |
| value-style | style enum value (strings only) | StringStyle | |