Skip to content

This package will scan and automatically convert your PHP enums into JavaScript objects.

License

Notifications You must be signed in to change notification settings

hackel/php-enum-to-js

Repository files navigation

PHP Enum to JS for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package will scan and automatically convert your PHP enums into JavaScript objects.

Example:

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"
};

Installation

You can install the package via composer:

composer require hackel/php-enum-to-js

Optionally, 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.

Usage

php artisan enum:to-js:convert

Options

  • --source - The directory to scan for PHP enums. Defaults to app/Enums.
  • --dest - The directory to write the JavaScript enums to. Defaults to resources/js/enums.
  • --clean - If set, all files in the destination directory will be removed before writing the JavaScript enums.
  • --no-dump-autoload Do not try to run composer dump-autoload prior to converting.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

This package will scan and automatically convert your PHP enums into JavaScript objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages