enum-converter
v1.4.11
Published
Convert Enums from one language to another
Downloads
46
Maintainers
Readme
Convert Enums from one language to another.
Live demo : https://enum-converter.vercel.app (source)
Supported languages
- [x] Java
- [x] Json
- [x] Python
- [x] Typescript
- [ ] C/C++
- [ ] C#
- [ ] Go
Installation
npm install -g enum-converter
Usage
CLI
enumc <file> [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
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 | |