This package will scan and automatically convert your PHP enums into JavaScript objects.
Input:
namespace App\Enums;
enum Color: string
{
case RED = 'red';
case GREEN = 'green';
case BLUE = 'blue';
}Output:
export default {
"RED": "red",
"GREEN": "green",
"BLUE": "blue"
};You can install the package via composer:
composer require hackel/php-enum-to-jsOptionally, you can publish the stub file using:
php artisan vendor:publish --tag="php-enum-to-js-stub"This will create an enum.stub file in your stubs directory. You can then customize this file to decorate your JavaScript enum however you like.
php artisan enum:to-js:convert--source- The directory to scan for PHP enums. Defaults toapp/Enums.--dest- The directory to write the JavaScript enums to. Defaults toresources/js/enums.--clean- If set, all files in the destination directory will be removed before writing the JavaScript enums.--no-dump-autoloadDo not try to runcomposer dump-autoloadprior to converting.
composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.