Registry / serialization / hast-util-minify-whitespace

hast-util-minify-whitespace

JSON →
library1.0.1jsnpmunverified

hast-util-minify-whitespace is a focused utility within the unified ecosystem, specifically designed to optimize HTML by minifying whitespace between elements in a `hast` (HTML Abstract Syntax Tree). It reduces multiple consecutive whitespace characters to a single space, or to a newline if configured, thereby improving the size of HTML fragments. The package is currently at version 1.0.1, with releases coordinated within the larger `rehypejs` collective, which emphasizes modern JavaScript practices. Key differentiators include its robust integration into the pluggable unified processing pipeline, full TypeScript support, and its commitment to WHATWG HTML parsing standards. It operates as an ESM-only module and requires Node.js 16 or newer, aligning with contemporary Node.js environments.

npm install hast-util-minify-whitespace
INSTALL
IMPORT
SIG · HAST-UTIL-MINIFY-W
H
hast-util-minify-whitespace
serializationjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

minifyWhitespace
import { minifyWhitespace } from 'hast-util-minify-whitespace'
const minifyWhitespace = require('hast-util-minify-whitespace')
This package is ESM-only since v1.0.0; CommonJS `require()` is not supported.
h
import { h } from 'hastscript'
const h = require('hastscript')
While not part of this package, `hastscript` is commonly used to create `hast` nodes and is often a companion dependency for testing or examples.
Options
import type { Options } from 'hast-util-minify-whitespace'
Import the TypeScript type definition for configuration options.

Demonstrates how to import and use `minifyWhitespace` to process a `hast` tree created with `hastscript`, showing the transformation of internal whitespace.

import { h } from 'hastscript'; import { minifyWhitespace } from 'hast-util-minify-whitespace'; const tree = h('p', [ ' ', h('strong', 'foo'), ' ', h('em', 'bar'), ' ', h('meta', { itemProp: true }), ' ' ]); console.log('Original tree:\n', JSON.stringify(tree, null, 2)); minifyWhitespace(tree); console.log('\nMinified tree:\n', JSON.stringify(tree, null, 2));
Debug
Known issues
breakingThis package, like all packages in the `rehypejs` monorepo, now requires Node.js 16 or newer. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or later.
affects: >=1.0.0
breakingThis package is ESM-only. Attempting to import it using CommonJS `require()` will result in errors.
fix
Ensure your project uses ES modules (`import`) and configure your `package.json` with `"type": "module"` or use `.mjs` extensions for files importing this package.
affects: >=1.0.0
breakingThe `rehypejs` monorepo, which this package is part of, now uses the `exports` field in `package.json`. This may affect how bundlers and older Node.js versions resolve imports.
fix
Ensure your build tooling and Node.js environment are up to date and correctly configured to handle the `exports` field. Avoid relying on undocumented subpath imports.
affects: >=1.0.0
gotchaMinifying whitespace within a `hast` tree does not inherently protect against Cross-Site Scripting (XSS) vulnerabilities. If the processed HTML is rendered without further sanitization, it could still be unsafe.
fix
Always use `rehype-sanitize` or a similar sanitization utility on your `hast` tree before serializing it to HTML, especially if the input HTML is untrusted.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module ... not supported.
Attempting to use `require()` to import an ESM-only package.
fix
Change `const minifyWhitespace = require('hast-util-minify-whitespace')` to `import { minifyWhitespace } from 'hast-util-minify-whitespace'` and ensure your project is configured for ESM.
minifyWhitespace is not a function
Trying to access `minifyWhitespace` as a property of the module object when using `require()` on an ESM-only package, or incorrectly destructuring named exports.
fix
Confirm you are using `import { minifyWhitespace } from 'hast-util-minify-whitespace'` and that your environment supports ESM.
ReferenceError: h is not defined
The `h` function from `hastscript` was used in an example or your code without being installed or imported.
fix
Install `hastscript` (`npm install hastscript`) and ensure you `import { h } from 'hastscript'` in your file.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
hast-util-minify-whitespace — npm install hast-util-minify-whitespace · libregistry