Search by

proqualex / javascript-formatters-laravel

rsotolongo

Laravel middleware that formats successful JSON responses as JavaScript.

Package info

github.com/rsotolongo/javascript-formatters-laravel

pkg:composer/proqualex/javascript-formatters-laravel

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-12-01 01:37 UTC

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.