Registry / devops / blade-formatter

blade-formatter

JSON →
library1.44.4jsnpmunverified

An opinionated Blade template formatter for Laravel that automatically indents markup inside directives, adds spacing to Blade markers, and supports PHP 8 features (null safe operator, named arguments). It also includes PSR-2 formatting inside directives and automatic Tailwind CSS class sorting. The current stable version is 1.44.4 with regular releases. Key differentiators: dedicated Blade formatter (no official one exists), built-in Tailwind sorting, custom directive support, and an online demo. Ships TypeScript declarations and requires Node >= 14.0.0.

npm install blade-formatter
INSTALL
IMPORT
SIG · BLADE-FORMATTER
B
blade-formatter
devopsjavascriptv1.44.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bladeFormatter
import { bladeFormatter } from 'blade-formatter'
const bladeFormatter = require('blade-formatter')
ESM-only since v1.x; CommonJS require throws an error.
Options
import type { Options } from 'blade-formatter'
import { Options } from 'blade-formatter'
Options is a TypeScript type, not a value. Use `import type` to avoid runtime import error.
format
import { format } from 'blade-formatter'
import format from 'blade-formatter'
The package does not have a default export; only named exports exist.

Formats a Blade template with indentation, Tailwind sorting, and custom directives using ESM import.

import { format } from 'blade-formatter'; const unformattedBlade = `@extends('layouts.app')\n@section('content')\n<div class="container">\n<p>@lang('hello')</p>\n</div>\n@endsection`; (async () => { const formatted = await format(unformattedBlade, { indentSize: 4, sortTailwindcssClasses: true, customDirectives: ['customBladeDirective'] }); console.log(formatted); })();
Debug
Known issues
breakingVersion 1.x dropped CommonJS support; require() will throw an error.
fix
Use ES module imports (import { ... } from 'blade-formatter').
affects: >=1.0.0
deprecatedThe `sortTailwindcssClasses` option was deprecated in 1.30.0 in favor of `sortTailwindClasses`.
fix
Rename `sortTailwindcssClasses` to `sortTailwindClasses` in your configuration.
affects: >=1.30.0
gotchaOutput may differ from expectations when custom directives are not registered; they will be treated as unknown and may cause formatting errors.
fix
Always pass custom directive names via the `customDirectives` option.
affects: >=1.0.0
gotchaLarge files may cause heap out-of-memory due to recursive parsing; known issue on Node 14.
fix
Upgrade to >=1.35.0 or increase Node memory limit (--max-old-space-size).
affects: <1.35.0
deprecatedThe `formatPhp` option was deprecated in 1.20.0; PHP formatting is now always enabled.
fix
Remove `formatPhp` from options.
affects: >=1.20.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require('blade-formatter') in Node.js with ESM-only package.
fix
Change import to ES module syntax (import { format } from 'blade-formatter') or use dynamic import.
Cannot read properties of undefined (reading 'options')
Calling format() without passing options object.
fix
Always pass an options object, even if empty: format('...', {}).
Failed to parse file: unexpected token
Invalid Blade syntax, e.g. unclosed section or mismatched directives.
fix
Check that all @section/@endsection, @if/@endif etc. are properly paired.
Error: Cannot find module 'prettier'
Tailwind class sorting requires prettier as optional peer dependency.
fix
Install prettier: npm install --save-dev prettier.
Upgrade
Version history
1.44.4latest on npm
Audit
Dependencies
prettieroptionalOptional peer dependency for Tailwind class sorting integration.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
blade-formatter — npm install blade-formatter · libregistry