Registry / serialization / rehype-minify-javascript-url

rehype-minify-javascript-url

JSON →
library5.0.1jsnpmunverified

rehype-minify-javascript-url is a rehype plugin designed to optimize HTML documents by minifying `javascript:` URL attributes found within various HTML tags. It's an integral part of the unified collective's rehype ecosystem, which focuses on transforming HTML with a plugin-based architecture. The current stable version is 5.0.1. This package specifically targets and reduces the size of JavaScript code embedded within URL attributes by applying minification techniques (e.g., transforming `alert(true)` to `alert(!0)`). Following the unified ecosystem's release cadence, it ensures compatibility with maintained Node.js versions, currently requiring Node.js 16 or newer. Its primary differentiator is its specialized focus on JavaScript URL minification, contributing to overall HTML document size reduction within the robust rehype processing pipeline.

npm install rehype-minify-javascript-url
INSTALL
IMPORT
SIG · REHYPE-MINIFY-JAVA
R
rehype-minify-javascript-url
serializationjavascriptv5.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.

rehypeMinifyJavaScriptUrl
import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'
const rehypeMinifyJavaScriptUrl = require('rehype-minify-javascript-url')
This package is ESM-only since version 5 and requires Node.js 16+. It exports only a default function.

Demonstrates how to use rehype-minify-javascript-url within a unified pipeline to parse HTML, minify JavaScript URLs, and then stringify the result.

import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url' import rehypeParse from 'rehype-parse' import rehypeStringify from 'rehype-stringify' import {read} from 'to-vfile' import {unified} from 'unified' async function processHtml() { const file = await unified() .use(rehypeParse) .use(rehypeMinifyJavaScriptUrl) .use(rehypeStringify) .process(await read('index.html')) console.log(String(file)) } // Assuming 'index.html' exists in the current directory with content like: // <a href="javascript:alert(true)">Click me</a> // For a runnable example, you might create a dummy file: // import { write } from 'to-vfile'; // await write({ path: 'index.html', value: '<a href="javascript:alert(true)">Click me</a>' }); processHtml().catch(console.error);
Debug
Known issues
breakingThis package is ESM-only. CommonJS `require()` is no longer supported.
fix
Migrate your project to use ES modules or update your bundler configuration to handle ESM imports correctly. Use `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`.
affects: >=5.0.0
breakingrehype-minify-javascript-url requires Node.js version 16 or newer.
fix
Ensure your development and production environments are running Node.js 16 or a later LTS version.
affects: >=5.0.0
gotchaImproper use of rehype plugins, especially when handling user-generated or untrusted HTML, can lead to Cross-Site Scripting (XSS) vulnerabilities.
fix
Always use `rehype-sanitize` in your unified pipeline before or after minification when processing untrusted HTML to ensure the resulting document is safe.
affects: *
gotchaThe `rehype-minify-javascript-url` package exports only a default function. Attempting to use named imports will result in errors.
fix
Ensure you are using a default import, e.g., `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`.
affects: *
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/rehype-minify-javascript-url/index.js from ... not supported.
Attempting to import an ESM-only package using CommonJS `require()` syntax.
fix
Update your import statements to use ES module syntax: `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'` and ensure your project is configured for ESM.
TypeError: rehypeMinifyJavaScriptUrl is not a function
This typically occurs if you try to destructure a named export, but the package only provides a default export, or if the import path is incorrect, leading to an undefined module.
fix
Verify that you are importing the default export correctly: `import rehypeMinifyJavaScriptUrl from 'rehype-minify-javascript-url'`. Do not use `{ rehypeMinifyJavaScriptUrl }`.
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
rehype-minify-javascript-url — npm install rehype-minify-javascript-url · libregistry