Registry / serialization / hast-util-heading

hast-util-heading

JSON →
library3.0.0jsnpmunverified

hast-util-heading is a highly specialized utility within the unified ecosystem, designed to programmatically check if a given HAST (Hypertext Abstract Syntax Tree) node represents a heading element (h1-h6, hgroup). The current stable version is 3.0.0. As part of the syntax-tree collective, it adheres to a release cadence that maintains compatibility with currently supported Node.js versions, typically dropping support for unmaintained Node.js versions with new major releases. Its key differentiator is its singular, focused purpose: providing a reliable, performant boolean check for heading elements, which is particularly useful in linting tools, accessibility checkers, or content transformers operating on HTML syntax trees. It is built for ESM-first environments and provides full TypeScript type definitions.

npm install hast-util-heading
INSTALL
IMPORT
SIG · HAST-UTIL-HEADING
H
hast-util-heading
serializationjavascriptv3.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.

heading
import { heading } from 'hast-util-heading';
const heading = require('hast-util-heading');
This package is ESM-only since v2.0.0. CommonJS `require()` is not supported. Use dynamic `import()` if necessary within CJS.
heading
import type { Node } from 'hast'; import { heading } from 'hast-util-heading';
import heading from 'hast-util-heading';
There is no default export; the `heading` function is a named export. Ensure you import it with curly braces.

Demonstrates how to import and use the `heading` function to check if a HAST node is a heading element.

import { heading } from 'hast-util-heading'; // Example 1: Given a non-heading value (e.g., an anchor element) const nonHeadingNode = { type: 'element', tagName: 'a', properties: { href: '#alpha', title: 'Bravo' }, children: [{ type: 'text', value: 'Charlie' }] }; console.log('Is non-heading node a heading?', heading(nonHeadingNode)); // Expected output: false // Example 2: Given a heading element (e.g., an h1 element) const headingNode = { type: 'element', tagName: 'h1', properties: {}, children: [{ type: 'text', value: 'Delta' }] }; console.log('Is heading node a heading?', heading(headingNode)); // Expected output: true // Example 3: Given an hgroup element const hgroupNode = { type: 'element', tagName: 'hgroup', properties: {}, children: [{ type: 'text', value: 'Grouped Heading' }] }; console.log('Is hgroup node a heading?', heading(hgroupNode)); // Expected output: true
Debug
Known issues
breakingVersion 3.0.0 of `hast-util-heading` requires Node.js 16 or higher. Projects running on older Node.js versions must upgrade their environment or stick to `hast-util-heading@^2`.
fix
Upgrade your Node.js environment to version 16 or newer. Alternatively, if upgrading Node.js is not possible, downgrade this package to `hast-util-heading@^2`.
affects: >=3.0.0
breakingThis package is ESM-only since version 2.0.0. Attempting to `require()` it in a CommonJS context will result in an error. Version 3.0.0 further updates to use the `exports` field in `package.json`.
fix
Migrate your project to use ES modules (`import`). If you must use CommonJS, use dynamic `import()` and ensure your bundler (if any) is configured for ESM. For older environments or CJS-only projects, use `hast-util-heading@^1`.
affects: >=2.0.0
breakingVersion 3.0.0 updates its internal dependencies, including `@types/hast`. It is recommended to update `@types/hast` in your project if you encounter type-related issues.
fix
Run `npm install @types/hast@latest` to ensure compatibility with `hast-util-heading@3`.
affects: >=3.0.0
gotchaThe `heading` function is a named export, not a default export. Incorrectly importing it as a default export will lead to runtime errors.
fix
Always use named import syntax: `import { heading } from 'hast-util-heading';`.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module ... hast-util-heading/index.js from ... not supported.
Attempting to import an ESM-only package using CommonJS `require()` in Node.js.
fix
Change your import statement from `const heading = require('hast-util-heading');` to `import { heading } from 'hast-util-heading';` and ensure your environment supports ESM (e.g., set `"type": "module"` in `package.json` or use `.mjs` files).
TypeError: (0 , hast_util_heading_1.heading) is not a function
This error typically occurs when `heading` is imported as a default export (`import heading from '...'`) but it is actually a named export.
fix
Correct the import statement to use named import syntax: `import { heading } from 'hast-util-heading';`.
Cannot find module 'hast-util-heading'
This can happen if Node.js is older than v16, which is required for version 3.0.0, or if there's an issue resolving the `exports` map in `package.json`.
fix
Ensure your Node.js version is 16 or higher. If it is, clear your `node_modules` and `package-lock.json` (`rm -rf node_modules package-lock.json && npm install`) to resolve potential module resolution issues. Alternatively, if you cannot upgrade Node.js, install an older compatible version like `hast-util-heading@^2` or `hast-util-heading@^1`.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
hast-util-heading — npm install hast-util-heading · libregistry