proqualex / javascript-formatters-laravel
Laravel middleware that formats successful JSON responses as JavaScript.
Package info
github.com/rsotolongo/javascript-formatters-laravel
pkg:composer/proqualex/javascript-formatters-laravel
Requires
- php: ^8.4.1
- laravel/framework: ^13.0
- proqualex/javascript-formatters-core: ^0.1
- symfony/http-foundation: ^7.4 || ^8.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-01 02:00:51 UTC
README
Middleware for Laravel 13, distributed under the MIT license.
Install the published package with composer require proqualex/javascript-formatters-laravel. Composer installs the Core formatter as a dependency.
For local development, add this path repository to the application's composer.json, adjusting the URL relative to that file, then run the same command.
{
"type": "path",
"url": "../javascript-formatters/*",
"options": {
"versions": {
"proqualex/javascript-formatters-core": "0.1.0",
"proqualex/javascript-formatters-laravel": "0.1.0"
}
}
}
use Illuminate\Support\Facades\Route; use ProQualEx\JavaScriptFormatters\Laravel\JavaScriptResponse; Route::get('/products', fn () => response()->json(['items' => []])) ->middleware(JavaScriptResponse::class);
GET /products?format=js converts a successful JSON response to a readable const value declaration. Requests without format=js retain the original response. Laravel resolves the Core JavaScriptSerializer through constructor injection.
| Query parameter | Effect |
|---|---|
minimized=true |
Omits indentation and formatting whitespace. |
quoted=true |
Quotes property names. |
name=products |
Sets the JavaScript binding. |
declaration=let |
Selects const, let, or var regardless of letter case. |
export=true |
Emits an ES module default export and ignores name and declaration. |
Boolean options enable only for true, regardless of letter case. An invalid name or declaration in named declaration mode returns 422.