Registry / devops / haml-formatter

haml-formatter

JSON →
library0.1.0jsnpmunverified

A pure JavaScript/TypeScript formatter for HAML templates that automatically indents and structures HAML code. Version 0.1.0, released in 2019, with no recent updates. It offers a single function FormatHaml with options for tab size and spaces vs tabs. Lightweight and simple, it differs from Ruby-based formatters by being usable in Node.js without Ruby dependencies. Suitable for linting and formatting HAML files in build pipelines or editors.

npm install haml-formatter
INSTALL
IMPORT
SIG · HAML-FORMATTER
H
haml-formatter
devopsjavascriptv0.1.0
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.

FormatHaml
import { FormatHaml } from 'haml-formatter'
const FormatHaml = require('haml-formatter')
Package is ESM-only; CommonJS require will error if used in Node without .mjs extension.
Options
import type { Options } from 'haml-formatter'
const Options = require('haml-formatter').Options
Options is a TypeScript interface; use type import for type-checking.
FormatHaml (default import)
import FormatHaml from 'haml-formatter'
const f = require('haml-formatter').default
Package exports FormatHaml as named export; default import also works.

Demonstrates formatting HAML with custom options (tab size and spaces).

import { FormatHaml } from 'haml-formatter'; const hamlInput = ` .level .level-left %h1.title %i.fa.fa-map-marker .level .level-left %h1.title %i.fa.fa-map-marker `; const formatted = FormatHaml(hamlInput, { tabSize: 4, insertSpaces: true }); console.log(formatted);
Debug
Known issues
gotchaRequires ESM environment; CommonJS require('haml-formatter') fails in Node <12 or without "type":"module".
fix
Use import syntax or set "type":"module" in package.json, or use dynamic import() in CJS.
affects: all
gotchaInput HAML must be valid; formatter may produce unexpected output for invalid HAML.
fix
Validate HAML before formatting, e.g., with haml-js.
affects: all
gotchaNo CLI or editor integration provided; must be used programmatically.
fix
Write a script to read files and pipe through FormatHaml, or use a task runner.
affects: all
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Package uses ESM exports but project is not configured for ES modules.
fix
Add "type": "module" to package.json or convert file to .mjs extension.
TypeError: FormatHaml is not a function
Incorrect import: using require with destructuring or wrong path.
fix
Use import { FormatHaml } from 'haml-formatter' or const FormatHaml = (await import('haml-formatter')).FormatHaml.
error TS2304: Cannot find name 'Options'
Options interface is not imported as a type.
fix
Add import type { Options } from 'haml-formatter' or use inline type.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
haml-formatter — npm install haml-formatter · libregistry