PHPackages                             crazybooot/laravel-constants-to-js - 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. crazybooot/laravel-constants-to-js

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

crazybooot/laravel-constants-to-js
==================================

Map php class constants to js

1.0.2(6y ago)57492[1 PRs](https://github.com/crazybooot/laravel-constants-to-js/pulls)PHPPHP ^7.1

Since Mar 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/crazybooot/laravel-constants-to-js)[ Packagist](https://packagist.org/packages/crazybooot/laravel-constants-to-js)[ RSS](/packages/crazybooot-laravel-constants-to-js/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (4)Used By (0)

Exports Laravel config and class constants to JavaScript
========================================================

[](#exports-laravel-config-and-class-constants-to-javascript)

Includes artisan command to generate JavaScript ES6 or UMD module

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

[](#installation)

You can install the package via composer:

```
composer require crazybooot/laravel-constants-to-js
```

Publish config:

```
php artisan vendor:publish --provider="Crazybooot\ConstantsToJs\Providers\ServiceProvider" --tag=config
```

Usage
-----

[](#usage)

Add JavaScript resulted object hierarchy to `config\constants-to-js.php` config file to `constants` section as an assoc array.

To include constants from specified class use `class` as key and class name as value:

```
return [
    'constants' => [
        'user' => [
            'type' => [
                'class' => App\User::class,
            ],
        ],
    ],
];
```

To inculde values from config file use `config` as key and string with path to config as value:

```
return [
    'constants' => [
        'queue' => [
            'connections' => [
                'config' => 'queue.connections',
            ],
        ],
    ],
];
```

Including class constants supports to filter them by constant name using `starts_with` option:

```
return [
    'constants' => [
        'user' => [
            'type'   => [
                'class'       => App\User::class,
                'starts_with' => 'TYPE_',
            ],
            'status' => [
                'class'       => App\User::class,
                'starts_with' => 'STATUS_',
            ],
        ],
    ],
];
```

To make some transformation with kyes and values use `transform_key` or `transform_value` options array where each key is a function will be applied to key or value and its value is array of additional parameters which will be passed to function: as value

```
return [
    'constants' => [
        'user' => [
            'type'   => [
                'class'       => App\User::class,
                'transform_key' => [
                    'strtoupper' => [],
                ]
            ],
        ],
        'queue' => [
            'connections' => [
                'config' => 'queue.connections',
                'transform_value' => [
                    'array_get'  => ['driver'],
                    'title_case' => []
                ],
            ],
        ],
    ],
];
```

To change destination and generated JavaScript file name use `target_path`configuration option:

```
return [
    'target_path' => resource_path('assets/js/constants.js'),
];
```

After cofiguration run next command to generate resulted JavaScript file:

```
php artisan constants:js
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.MD) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Total

3

Last Release

2519d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63f9f618bf7eb34b152613b7583bc1d024a9bb95abfa563a9e212a4b4b2da7ee?d=identicon)[crazybooot](/maintainers/crazybooot)

---

Top Contributors

[![crazybooot](https://avatars.githubusercontent.com/u/4480913?v=4)](https://github.com/crazybooot "crazybooot (8 commits)")

### Embed Badge

![Health badge](/badges/crazybooot-laravel-constants-to-js/health.svg)

```
[![Health](https://phpackages.com/badges/crazybooot-laravel-constants-to-js/health.svg)](https://phpackages.com/packages/crazybooot-laravel-constants-to-js)
```

###  Alternatives

[serafim/properties

PHP properties implementation

789.1k1](/packages/serafim-properties)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
