ts-enum-gen-cli
v1.0.0
Published
Generate TypeScript enums from JSON, CSV, or database column values
Maintainers
Readme
ts-enum-gen-cli
Generate TypeScript enums from JSON, CSV, or inline values.
Install
npm install -g ts-enum-gen-cliUsage
# Inline values
ts-enum-gen-cli Red,Green,Blue -n Color
# From JSON array
ts-enum-gen-cli -i colors.json -n Color
# From JSON object keys
ts-enum-gen-cli -i config.json -n ConfigKey --from-json-keys
# From CSV
ts-enum-gen-cli -i statuses.csv -n Status
# Pipe from stdin
echo "Active,Inactive,Pending" | ts-enum-gen-cli -n Status
# Write to file
ts-enum-gen-cli -i roles.json -n Role -o src/enums/role.tsOptions
| Flag | Description |
|------|-------------|
| -i, --input <path> | Input file (JSON or CSV) |
| -n, --name <name> | Enum name (default: MyEnum) |
| -o, --output <path> | Output .ts file (stdout if omitted) |
| --const | Generate const enum |
| --string-enum | String enum with values equal to keys |
| --numeric | Numeric enum (0, 1, 2, ...) |
| --from-json-keys | Use JSON object keys as enum members |
Examples
String enum (default)
ts-enum-gen-cli Admin,User,Guest -n Roleexport enum Role {
Admin = 'Admin',
User = 'User',
Guest = 'Guest',
}Const numeric enum
ts-enum-gen-cli Active,Inactive -n Status --const --numericexport const enum Status {
Active = 0,
Inactive = 1,
}License
MIT
