{"id":13289,"library":"hast-util-heading","title":"HAST Heading Utility","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/hast-util-heading","tags":["javascript","unist","hast","hast-util","util","utility","html","category","heading","typescript"],"install":[{"cmd":"npm install hast-util-heading","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-heading","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-heading","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v2.0.0. CommonJS `require()` is not supported. Use dynamic `import()` if necessary within CJS.","wrong":"const heading = require('hast-util-heading');","symbol":"heading","correct":"import { heading } from 'hast-util-heading';"},{"note":"There is no default export; the `heading` function is a named export. Ensure you import it with curly braces.","wrong":"import heading from 'hast-util-heading';","symbol":"heading","correct":"import type { Node } from 'hast';\nimport { heading } from 'hast-util-heading';"}],"quickstart":{"code":"import { heading } from 'hast-util-heading';\n\n// Example 1: Given a non-heading value (e.g., an anchor element)\nconst nonHeadingNode = {\n  type: 'element',\n  tagName: 'a',\n  properties: { href: '#alpha', title: 'Bravo' },\n  children: [{ type: 'text', value: 'Charlie' }]\n};\nconsole.log('Is non-heading node a heading?', heading(nonHeadingNode));\n// Expected output: false\n\n// Example 2: Given a heading element (e.g., an h1 element)\nconst headingNode = {\n  type: 'element',\n  tagName: 'h1',\n  properties: {},\n  children: [{ type: 'text', value: 'Delta' }]\n};\nconsole.log('Is heading node a heading?', heading(headingNode));\n// Expected output: true\n\n// Example 3: Given an hgroup element\nconst hgroupNode = {\n  type: 'element',\n  tagName: 'hgroup',\n  properties: {},\n  children: [{ type: 'text', value: 'Grouped Heading' }]\n};\nconsole.log('Is hgroup node a heading?', heading(hgroupNode));\n// Expected output: true\n","lang":"typescript","description":"Demonstrates how to import and use the `heading` function to check if a HAST node is a heading element."},"warnings":[{"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`.","message":"Version 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`.","severity":"breaking","affected_versions":">=3.0.0"},{"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`.","message":"This 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`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Run `npm install @types/hast@latest` to ensure compatibility with `hast-util-heading@3`.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always use named import syntax: `import { heading } from 'hast-util-heading';`.","message":"The `heading` function is a named export, not a default export. Incorrectly importing it as a default export will lead to runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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).","cause":"Attempting to import an ESM-only package using CommonJS `require()` in Node.js.","error":"ERR_REQUIRE_ESM: require() of ES Module ... hast-util-heading/index.js from ... not supported."},{"fix":"Correct the import statement to use named import syntax: `import { heading } from 'hast-util-heading';`.","cause":"This error typically occurs when `heading` is imported as a default export (`import heading from '...'`) but it is actually a named export.","error":"TypeError: (0 , hast_util_heading_1.heading) is not a function"},{"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`.","cause":"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`.","error":"Cannot find module 'hast-util-heading'"}],"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}