micromark-util-sanitize-uri is a focused utility package within the unified collective's micromark ecosystem, designed to safely normalize and sanitize URIs. It currently operates at version 2.0.1. The package encodes unsafe characters using percent-encoding, skips already encoded sequences, and can further sanitize URIs by validating against a regex of allowed protocols, effectively neutralizing potentially dangerous `javascript:` schemes. This utility is crucial for developers building custom micromark extensions or processing user-generated content, ensuring that URLs rendered in HTML are free from XSS vulnerabilities. As part of the broader micromark project, it follows the unified collective's release cadence, with major versions tied to Node.js LTS support, ensuring compatibility with Node.js 16+ for its current v2 release.
npm install micromark-util-sanitize-uriVerified import paths — ran on the pinned version, not inferred.
Demonstrates `sanitizeUri` with protocol filtering and `normalizeUri` for encoding special characters, showing how to make URLs safe for embedding.
Migrate your project to use ES modules (`import`) or use a tool like `esm-interop` if you are stuck on CommonJS.
Upgrade your Node.js version to 16 or newer to maintain compatibility. Check the `micromark` monorepo compatibility guidelines for the latest recommendations.
When calling `sanitizeUri(url, pattern)`, specify `pattern` as a regular expression matching only the truly safe protocols you intend to permit.
Change your import statement to `import { sanitizeUri } from 'micromark-util-sanitize-uri';` in an ES module context. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions.Verify that `micromark-util-sanitize-uri` is correctly installed (`npm install micromark-util-sanitize-uri`) and that you are using ES module `import` syntax (`import { sanitizeUri } from 'micromark-util-sanitize-uri';`).No dependency data recorded yet.