Converts JavaScript Enums to TypeScript Enums
Find a file
2021-08-08 01:02:26 +02:00
.gitignore 🌱 Initial Commit 2021-08-03 17:44:42 +02:00
converter.py possibility to convert to consts instead of enums 2021-08-08 01:02:26 +02:00
README.md 🌱 Initial Commit 2021-08-03 17:44:42 +02:00
to_const.py possibility to convert to consts instead of enums 2021-08-08 01:02:26 +02:00
to_enum.py possibility to convert to consts instead of enums 2021-08-08 01:02:26 +02:00
util.py 🌱 Initial Commit 2021-08-03 17:44:42 +02:00

JStoTSenum

Coded this as a tool to speed up Typing of DoctorMcKay/node-steam-user This converter takes JavaScript Enums like these:

module.exports = {
    "NoCost": 0,
    "BillOnceOnly": 1,
    "BillMonthly": 2,
    "ProofOfPrepurchaseOnly": 3,
    "GuestPass": 4,
    "HardwarePromo": 5,
    "Gift": 6,
}

and converts them to TypeScript Enums like this:

export enum EBillingType {
    "NoCost" = 0;
    "BillOnceOnly" = 1;
    "BillMonthly" = 2;
    "ProofOfPrepurchaseOnly" = 3;
    "GuestPass" = 4;
    "HardwarePromo" = 5;
    "Gift" = 6;
}

Enum naming is based on the JavaScript Filenames, so there can only be one Enum per JavaScript file. The converter takes a directory full of JavaScript files as input, and the output directory can be configured.