{"id":13285,"library":"hast-util-embedded","title":"hast-util-embedded","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/hast-util-embedded","tags":["javascript","unist","hast","hast-util","util","utility","html","category","embedded","typescript"],"install":[{"cmd":"npm install hast-util-embedded","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-embedded","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-embedded","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since version 2.0.0; CommonJS `require()` is not supported.","wrong":"const { embedded } = require('hast-util-embedded')","symbol":"embedded","correct":"import { embedded } from 'hast-util-embedded'"},{"note":"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`.","symbol":"embedded (TypeScript)","correct":"import type { Element } from 'hast';\nimport { embedded } from 'hast-util-embedded'"}],"quickstart":{"code":"import { embedded } from 'hast-util-embedded';\n\n// Example 1: Check a non-embedded HTML element (an anchor tag).\n// The `embedded` utility determines if a HAST node is considered\n// 'embedded content' by the HTML specification. An `<a>` element is not.\nconst nonEmbeddedNode = {\n  type: 'element',\n  tagName: 'a',\n  properties: { href: '#link', title: 'Example Link' },\n  children: [{ type: 'text', value: 'Click Me' }]\n};\nconsole.log('Is <a> embedded content?', embedded(nonEmbeddedNode));\n// Expected output: Is <a> embedded content? false\n\n// Example 2: Check an embedded HTML element (an audio tag).\n// HTML `audio` elements are classified as embedded content.\nconst embeddedAudioNode = {\n  type: 'element',\n  tagName: 'audio',\n  properties: { src: 'music.ogg', controls: true },\n  children: []\n};\nconsole.log('Is <audio> embedded content?', embedded(embeddedAudioNode));\n// Expected output: Is <audio> embedded content? true\n\n// Example 3: Check another embedded HTML element (an iframe tag).\n// HTML `iframe` elements are also classified as embedded content.\nconst embeddedIframeNode = {\n  type: 'element',\n  tagName: 'iframe',\n  properties: { src: 'https://example.com', width: '600', height: '400' },\n  children: []\n};\nconsole.log('Is <iframe> embedded content?', embedded(embeddedIframeNode));\n// Expected output: Is <iframe> embedded content? true","lang":"typescript","description":"This example demonstrates how to use the `embedded` utility to check if various HAST nodes represent embedded HTML content, printing the boolean result."},"warnings":[{"fix":"Update all module imports to use ES Modules syntax: `import { embedded } from 'hast-util-embedded'`.","message":"Since 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Node.js environment to version 16 or later to ensure compatibility.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"With 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"This 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`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update your import statement to use ES Modules syntax: `import { embedded } from 'hast-util-embedded'`.","cause":"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.","error":"ReferenceError: require is not defined"},{"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.","cause":"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.","error":"ERR_PACKAGE_IMPORT_NOT_DEFINED"},{"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'`.","cause":"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.","error":"TypeError: embedded is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}