承接 levintoo/laravel-enum-exporter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

levintoo/laravel-enum-exporter

最新稳定版本:0.1.0

Composer 安装命令:

composer require levintoo/laravel-enum-exporter

包简介

Laravel dev-only package to export PHP enums to TypeScript

README 文档

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 (TypeScript):

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

Export all enums in app/Enums (TypeScript):

php artisan export:enum --all

Export enums as JavaScript workarounds (instead of TypeScript):

php artisan export:enum Role --js
# or
php artisan export:enum --all --js

🗂 Output Path TypeScript files are generated in:

  • TypeScript: resources/js/enums/{kebab-case-enum}.ts
  • JavaScript: resources/js/enums/{kebab-case-enum}.js

📝 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',
}

or The following Javascript file will be generated:

/* resources/js/enums/user-status.js */
const UserStatus = {
    Active: { name: 'Active', value: 'active' },
    Inactive: { name: 'Inactive', value: 'inactive' },
    Pending: { name: 'Pending', value: 'pending' },

    cases() {
        return Object.values(this).filter(e => e?.value !== undefined);
    },

    from(slug) {
        return this.cases().find(
            e => e.name.toLowerCase() === slug
        ) ?? null;
    },

    get(value) {
        return this.cases().find(
            e => e.value === value
        ) ?? null;
    }
};

export default UserStatus;

⚠️ 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

统计信息

  • 总下载量: 47
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-05