levintoo/laravel-enum-exporter

Laravel dev-only package to export PHP enums to TypeScript

dev-main 2025-07-05 20:54 UTC

This package is auto-updated.

Last update: 2025-07-05 20:54:21 UTC


README

Tests Latest Unstable Version License

Effortlessly sync PHP enums to TypeScript for type-safe frontend integration. This dev-only Laravel package exports your PHP enums into TypeScript files under resources/js/enums, letting you use the same enum definitions on the frontend as your server.

📦 Installation

composer require levintoo/laravel-enum-exporter --dev

🚀 Usage

Export a single enum:

php artisan export:enum Role # or app/Enums/Role.php

Export all enums in app/Enums:

php artisan export:enum --all

🗂 Output Path TypeScript files are generated in:

resources/js/enums/{kebab-case-enum}.ts

📝 Example

Given a PHP enum:

/* app/Enums/UserStatus.php */
enum UserStatus: string
{
    case Active = 'active';
    case Inactive = 'inactive';
    case Pending = 'pending';
}

The following TypeScript file will be generated:

/* resources/js/enums/user-status.ts */
export enum UserStatus {
    Active = 'active',
    Inactive = 'inactive',
    Pending = 'pending',
}

⚠️ Current Status

This package is pre-alpha: APIs and behavior are actively evolving and may change without notice.

🛠 Future Plans

Feature Status
Publish to Packagist ⏳ Planned
Support enums with methods/properties ⏳ Planned
Add option to overwrite existing files ⏳ Planned
Allow custom output paths for TS files ⏳ Planned
Support multiple case styles (kebab, Pascal) ⏳ Planned
Support JS enum workarounds ⏳ Planned