Registry / web-framework / hast-util-embedded

hast-util-embedded

JSON →
library3.0.0jsnpmunverified

This package is a focused utility from the unified collective, designed to determine if a given HAST (Hypertext Abstract Syntax Tree) node represents "embedded content" according to the HTML specification. Currently at stable version 3.0.0, it follows the unified ecosystem's release cadence, often aligning major releases with Node.js LTS updates or significant ecosystem shifts like ESM adoption. Its key differentiator is its precise adherence to the HTML specification for embedded content, providing a reliable, small-footprint function (`embedded`) for tree traversal and manipulation tasks where identifying specific HTML element categories is crucial. It is highly specialized, differentiating it from more general element checking utilities like `hast-util-is-element` by focusing solely on the HTML definition of embedded content (e.g., `audio`, `video`, `img`, `iframe`, `svg`). This makes it ideal for specific content processing pipelines within the `unified` ecosystem.

npm install hast-util-embedded
INSTALL
IMPORT
SIG · HAST-UTIL-EMBEDDED
H
hast-util-embedded
web-frameworkjavascriptv3.0.0
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.

embedded
import { embedded } from 'hast-util-embedded'
const { embedded } = require('hast-util-embedded')
This package is ESM-only since version 2.0.0; CommonJS `require()` is not supported.
embedded (TypeScript)
import type { Element } from 'hast'; import { embedded } from 'hast-util-embedded'
The package ships with TypeScript types. The usage for the `embedded` function is the same as JavaScript, but HAST node types can be imported from `@types/hast` or derived from `unist`.

This example demonstrates how to use the `embedded` utility to check if various HAST nodes represent embedded HTML content, printing the boolean result.

import { embedded } from 'hast-util-embedded'; // Example 1: Check a non-embedded HTML element (an anchor tag). // The `embedded` utility determines if a HAST node is considered // 'embedded content' by the HTML specification. An `<a>` element is not. const nonEmbeddedNode = { type: 'element', tagName: 'a', properties: { href: '#link', title: 'Example Link' }, children: [{ type: 'text', value: 'Click Me' }] }; console.log('Is <a> embedded content?', embedded(nonEmbeddedNode)); // Expected output: Is <a> embedded content? false // Example 2: Check an embedded HTML element (an audio tag). // HTML `audio` elements are classified as embedded content. const embeddedAudioNode = { type: 'element', tagName: 'audio', properties: { src: 'music.ogg', controls: true }, children: [] }; console.log('Is <audio> embedded content?', embedded(embeddedAudioNode)); // Expected output: Is <audio> embedded content? true // Example 3: Check another embedded HTML element (an iframe tag). // HTML `iframe` elements are also classified as embedded content. const embeddedIframeNode = { type: 'element', tagName: 'iframe', properties: { src: 'https://example.com', width: '600', height: '400' }, children: [] }; console.log('Is <iframe> embedded content?', embedded(embeddedIframeNode)); // Expected output: Is <iframe> embedded content? true
Debug
Known issues
breakingSince version 2.0.0, `hast-util-embedded` transitioned to being an ES Modules (ESM) only package. This means CommonJS `require()` statements will fail to load the module.
fix
Update all module imports to use ES Modules syntax: `import { embedded } from 'hast-util-embedded'`.
affects: >=2.0.0
breakingVersion 3.0.0 and subsequent releases require Node.js version 16 or higher. Running the package in older Node.js environments will result in runtime errors related to unsupported syntax or APIs.
fix
Upgrade your Node.js environment to version 16 or later to ensure compatibility.
affects: >=3.0.0
breakingWith version 3.0.0, the package adopted the `exports` field in its `package.json`. While standard for modern Node.js environments (v12.x+ for basic usage, v16+ for full stability), older bundlers or custom module resolvers might encounter issues if not properly configured to handle this field.
fix
Ensure your build tooling (e.g., webpack, Rollup) and Node.js environment are up-to-date and correctly configured for `package.json` `exports` resolution.
affects: >=3.0.0
gotchaThis utility is highly specialized, checking exclusively for HTML elements defined as *embedded content* (e.g., `audio`, `canvas`, `embed`, `iframe`, `img`, `math`, `object`, `picture`, `svg`, `video`). It is not a general-purpose element checker like `hast-util-is-element`.
fix
Confirm that the HTML element you are checking falls under the specification's definition of 'embedded content'. For general element checking or other HTML categories, use appropriate dedicated utilities.
affects: All
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to import `hast-util-embedded` using CommonJS `require()` syntax in an ES Modules context, or with a package that is ESM-only since v2.0.0.
fix
Update your import statement to use ES Modules syntax: `import { embedded } from 'hast-util-embedded'`.
ERR_PACKAGE_IMPORT_NOT_DEFINED
This error can occur if you're trying to import from a subpath that isn't explicitly exported, or if your Node.js environment (pre-12.17) or bundler doesn't fully support the `exports` field introduced in v3.0.0.
fix
Ensure you are importing directly from the package name (`'hast-util-embedded'`) and that your Node.js version is 16 or higher. Update your build tooling if necessary.
TypeError: embedded is not a function
This typically happens if the module failed to load correctly, which can be due to Node.js version incompatibility (running v3.0.0+ on Node.js < 16) or incorrect import syntax.
fix
Verify your Node.js version is 16 or newer. Double-check that you are using the correct ESM import syntax: `import { embedded } from 'hast-util-embedded'`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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