wthealth / laravel-enum-transformer
Installs: 55 431
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 3
Open Issues: 2
Requires
- php: ^8.0
- ext-json: *
- bensampo/laravel-enum: ^5.0 || ^6.0
- spatie/typescript-transformer: ^2.1.3
Requires (Dev)
- phpunit/phpunit: ^9.5.10
- scrutinizer/ocular: ^1.8.1
- spatie/phpunit-snapshot-assertions: ^4.2.9
- symplify/easy-coding-standard: ^9.4
This package is auto-updated.
Last update: 2024-12-28 06:52:09 UTC
README
Adds transformation support for bensampo/laravel-enum based enums to the spatie/laravel-typescript-transformer package.
Installation & Configuration
composer require wthealth/laravel-enum-transformer
Add the following Transformer
to the configuration config/type-script-transformer
'transformers' => [
Webtools\LaravelEnumTransformer\LaravelEnumTransformer::class,
],
Usage
Now any enum created based on BenSampo\Enum\Enum
can be transformed to typescript like below
final class UserType extends Enum { const Administrator = 0; const Moderator = 1; const Subscriber = 2; const SuperAdministrator = 3; }
export type UserType = { Administrator = 0, Moderator = 1, Subscriber = 2, SuperAdministrator = 3, }
Or transform to enums:
This must be enabled in config/type-script-transformer
'transform_to_native_enums' => true,
export enum UserType { Administrator = 0, Moderator = 1, Subscriber = 2, SuperAdministrator = 3, }
Read the documentation for further details.
License
The MIT License (MIT). Please see License File for more information.