PHPackages                             diagonal/laravel-ts-enum-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. diagonal/laravel-ts-enum-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

diagonal/laravel-ts-enum-generator
==================================

Generate runtime-usable TypeScript objects and enums from PHP enums with utils

0.3.3(1mo ago)59.3k↑246.5%1[3 PRs](https://github.com/Diagonal-HQ/ts-enum-generator/pulls)MITPHPPHP ^8.4CI passing

Since Jun 28Pushed 1w agoCompare

[ Source](https://github.com/Diagonal-HQ/ts-enum-generator)[ Packagist](https://packagist.org/packages/diagonal/laravel-ts-enum-generator)[ Docs](https://github.com/diagonal/ts-enum-generator)[ GitHub Sponsors](https://github.com/Diagonal-HQ)[ RSS](/packages/diagonal-laravel-ts-enum-generator/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (28)Versions (21)Used By (0)

Diagonal TS Enum Generator
==========================

[](#diagonal-ts-enum-generator)

[![Diagonal](https://camo.githubusercontent.com/3a7651af35bf0415ef79190d84fc20e76a50f50a0e5aa32812c57c72b945f840/68747470733a2f2f7075622d30353165333063383732363334313266616333313430343266663436323635612e72322e6465762f576562736974652532304d656469612f446961676f6e616c4c6f676f54726164656d61726b426c61636b2e706e67)](https://camo.githubusercontent.com/3a7651af35bf0415ef79190d84fc20e76a50f50a0e5aa32812c57c72b945f840/68747470733a2f2f7075622d30353165333063383732363334313266616333313430343266663436323635612e72322e6465762f576562736974652532304d656469612f446961676f6e616c4c6f676f54726164656d61726b426c61636b2e706e67)

Downloadable developer software from Diagonal Software Corp. for application development with Laravel, PHP enums, and TypeScript.

[![Latest Version on Packagist](https://camo.githubusercontent.com/1f18ebcc64081e923636f2dcb01b88192bde2a95d93a24a8790907be1b8af2f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646961676f6e616c2f74732d656e756d2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/diagonal/ts-enum-generator)[![Tests](https://camo.githubusercontent.com/0fb0910802a9c2dd33ef48558de502dc0a32d527ffcef556a0e56f1da02cba40/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f446961676f6e616c2d48512f74732d656e756d2d67656e657261746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/diagonal/ts-enum-generator/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/98e51bfe08f7a04d1d8e23bfa0d70d47e8d24bdbee058a6df43aa3c38dd5185e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646961676f6e616c2f74732d656e756d2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/diagonal/ts-enum-generator)

Diagonal TS Enum Generator is a downloadable computer software development tool distributed as the `diagonal/ts-enum-generator` Composer package. It generates TypeScript definitions from PHP enums so backend and frontend applications can share typed enum contracts.

The generated TypeScript can include type definitions, runtime objects, and utility functions for use in application development, deployment, and management workflows.

Package details
---------------

[](#package-details)

- **Provider:** Diagonal Software Corp.
- **Software name:** Diagonal TS Enum Generator
- **Package:** `diagonal/ts-enum-generator`
- **Distribution:** Downloadable Composer package via Packagist
- **Use case:** Computer system and application development with Laravel, PHP, and TypeScript

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require diagonal/ts-enum-generator
```

You can publish the config file with:

```
php artisan vendor:publish --tag="ts-enum-generator-config"
```

This is the contents of the published config file:

```
return [
    'default_source_dir' => 'app/Enums',
    'default_destination_dir' => 'resources/ts/enums',

    'output' => [
        'use_namespaces' => true,
        'single_file' => true,
        'output_filename' => 'enums.ts',
        'namespace_separator' => '.',
        'include_comments' => true,
        'generate_runtime_objects' => true,
        'generate_per_type_utils' => true,
        'generate_generic_utils' => true,
        'types_only' => false,
    ],

    'namespace' => [
        'root_namespace' => null,
        'strip_namespace_prefix' => null,
        'namespace_suffix' => 'Enums',
    ],
];
```

Usage
-----

[](#usage)

Create PHP enums in your Laravel application:

```
