Convert Enums from one language to another.
Live demo : https://enum-converter.vercel.app (source)
- Java
- Json
- Python
- Typescript
- C/C++
- C#
- Go
npm install -g enum-converter
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
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,
})
Name | Meaning | type | default |
---|---|---|---|
from | source language (explicit) | Language | |
to | destination language | Language | |
out | destination file | string | |
modify | modify existing file | boolean | false |
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 |