enum-converter
TypeScript icon, indicating that this package has built-in type declarations

1.4.11 • Public • Published

Enum Converter (enumc)

Convert Enums from one language to another.

Live demo : https://enum-converter.vercel.app (source)

npm npm-next npm-downloads-week test workflow release workflow

license semantic-release Commitizen friendly


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

Dependencies (13)

Dev Dependencies (15)

Package Sidebar

Install

npm i enum-converter

Weekly Downloads

10

Version

1.4.11

License

MIT

Unpacked Size

171 kB

Total Files

132

Last publish

Collaborators

  • nitzano