Registry / web-framework / hast-util-is-body-ok-link

hast-util-is-body-ok-link

JSON →
library3.0.1jsnpmunverified

hast-util-is-body-ok-link is a utility package within the `unified` ecosystem, specifically designed for working with HAST (HTML Abstract Syntax Tree) nodes. Its primary function is to determine if a given `link` element adheres to the “Body OK” criteria as defined by the WHATWG HTML standard, meaning it can safely exist within the `<body>` section of an HTML document rather than being restricted to the `<head>`. This utility is currently at version `3.0.1` and is maintained as part of the broader `rehypejs` collective. Releases typically align with major `unified` ecosystem updates, ensuring compatibility with other `hast` and `rehype` plugins. A key differentiator is its strict adherence to web standards and its integration into a comprehensive Markdown/HTML processing pipeline. It ships with full TypeScript type definitions, providing a robust and type-safe development experience for Node.js (version 16+) and browser environments.

npm install hast-util-is-body-ok-link
INSTALL
IMPORT
SIG · HAST-UTIL-IS-BODY-
H
hast-util-is-body-ok-link
web-frameworkjavascriptv3.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.

isBodyOkLink
import { isBodyOkLink } from 'hast-util-is-body-ok-link'
const isBodyOkLink = require('hast-util-is-body-ok-link')
This package is ESM-only since version 3.0.0, and has no default export.
isBodyOkLink
import { isBodyOkLink } from 'hast-util-is-body-ok-link'
import isBodyOkLink from 'hast-util-is-body-ok-link'
There is no default export; the function is a named export.
Node
import type { Node } from 'hast'
While not directly from this package, importing `Node` type from `hast` is common for type-checking when working with HAST utilities.

Demonstrates how to import and use `isBodyOkLink` to check various HAST `link` nodes and a non-link node for 'Body OK' compatibility according to WHATWG HTML specifications.

import { h } from 'hastscript'; import { isBodyOkLink } from 'hast-util-is-body-ok-link'; // Example 1: Link with itemProp (Body OK) const link1 = h('link', { itemProp: 'foo' }); console.log('Link with itemProp:', isBodyOkLink(link1)); // Expected: true // Example 2: Stylesheet link (Body OK) const link2 = h('link', { rel: ['stylesheet'], href: 'index.css' }); console.log('Stylesheet link:', isBodyOkLink(link2)); // Expected: true // Example 3: Author link (Not Body OK) const link3 = h('link', { rel: ['author'], href: 'index.css' }); console.log('Author link:', isBodyOkLink(link3)); // Expected: false // Example 4: Pingback link (Body OK) const link4 = h('link', { rel: ['pingback'], href: 'ping.xml' }); console.log('Pingback link:', isBodyOkLink(link4)); // Expected: true // Example 5: Non-link element const div = h('div', 'Hello'); console.log('Non-link element:', isBodyOkLink(div)); // Expected: false (or handles as invalid HAST Node gracefully)
Debug
Known issues
breakingVersion 3.0.0 and later of `hast-util-is-body-ok-link` (and the `unified` ecosystem it belongs to) require Node.js 16 or newer. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or higher.
affects: >=3.0.0
breaking`hast-util-is-body-ok-link` is an ESM-only package since version 3.0.0. Attempting to use CommonJS `require()` statements will result in an `ERR_REQUIRE_ESM` error.
fix
Refactor your import statements to use ES Modules (e.g., `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`).
affects: >=3.0.0
breakingVersion 3.0.0 aligns with major updates across the `unified` and `hast` ecosystems (e.g., `unified` v11, `@types/hast` updates). This may necessitate updating other `hast` utilities and plugins to their latest compatible major versions.
fix
Ensure all related `unified`, `rehype`, and `hast` packages in your project are updated to their latest compatible major versions.
affects: >=3.0.0
gotchaWhen processing untrusted HTML content, directly using `rehype` and its utilities like this without explicit sanitization can lead to Cross-Site Scripting (XSS) vulnerabilities.
fix
Always integrate `rehype-sanitize` into your `rehype` processing pipeline when dealing with HTML from untrusted sources to mitigate XSS risks.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require('hast-util-is-body-ok-link')` in a CommonJS environment, but the package is ESM-only.
fix
Switch to ES module import syntax: `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`.
TypeError: isBodyOkLink is not a function
The `isBodyOkLink` function was imported incorrectly, likely as a default import (`import isBodyOkLink from '...'`) when it is a named export.
fix
Use a named import: `import { isBodyOkLink } from 'hast-util-is-body-ok-link';`.
TypeError: Cannot read properties of undefined (reading 'type')
The `node` argument passed to `isBodyOkLink` is `undefined`, `null`, or an object that does not conform to the expected HAST `Node` structure, preventing access to its `type` property.
fix
Ensure the `node` argument is a properly constructed HAST `Node` object before passing it to `isBodyOkLink`.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
hastscriptoptionalUsed to create HAST nodes for testing or examples, not a runtime dependency for `isBodyOkLink` itself.
Agent activity
4 hits · last 30 days
node
4
Resources
hast-util-is-body-ok-link — npm install hast-util-is-body-ok-link · libregistry