{"id":11001,"library":"hast-util-has-property","title":"HAST Property Checker","description":"hast-util-has-property is a focused utility within the unified (specifically HAST) ecosystem, designed to ascertain if a given HAST (Hypertext Abstract Syntax Tree) element node possesses a specified property. The current stable version is 3.0.0. This package is maintained by the syntax-tree collective, aligning its release cadence with Node.js LTS versions and the broader `unified` project's evolution, frequently releasing new major versions to adopt modern JavaScript features like ESM. Its primary differentiation lies in its tight integration with the HAST specification, providing a type-safe (TypeScript-enabled) and robust method for property checking, crucial for HTML processing pipelines. It is a highly specialized tool, typically used by developers working directly with HAST manipulation, offering a reliable primitive for conditional logic based on element properties in transform plugins. It strictly operates on valid HAST `Node` objects, particularly `Element` types, providing a precise `boolean` result.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/hast-util-has-property","tags":["javascript","unist","hast","hast-util","util","utility","html","element","property","typescript"],"install":[{"cmd":"npm install hast-util-has-property","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-has-property","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-has-property","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v2.0.0, and has been further refined with 'exports' in v3.0.0. CommonJS 'require' is not supported.","wrong":"const hasProperty = require('hast-util-has-property')","symbol":"hasProperty","correct":"import { hasProperty } from 'hast-util-has-property'"},{"note":"For Deno and browser environments, use an ESM CDN like esm.sh, optionally with `?bundle` for browser usage.","symbol":"hasProperty","correct":"import { hasProperty } from 'https://esm.sh/hast-util-has-property@3'"}],"quickstart":{"code":"import {hasProperty} from 'hast-util-has-property'\n\n// Example 1: Text node has no properties, so 'bravo' is false.\nhasProperty({type: 'text', value: 'alpha'}, 'bravo') // => false\n\n// Example 2: Element node without 'className' property.\nhasProperty(\n  {\n    type: 'element',\n    tagName: 'div',\n    properties: {id: 'bravo'},\n    children: []\n  },\n  'className'\n) // => false\n\n// Example 3: Element node with 'id' property.\nhasProperty(\n  {\n    type: 'element',\n    tagName: 'div',\n    properties: {id: 'charlie'},\n    children: []\n  },\n  'id'\n) // => true\n\nconsole.log('Checked properties successfully.')","lang":"javascript","description":"Demonstrates how to import and use the `hasProperty` function to check for the existence of properties on different HAST nodes."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or higher. For projects that cannot upgrade, consider pinning to `hast-util-has-property@2`.","message":"Version 3.0.0 of `hast-util-has-property` requires Node.js 16 or newer. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate your project to use ECMAScript Modules (ESM) syntax (`import ... from '...'`) for this package. Ensure your `package.json` specifies `\"type\": \"module\"` or use `.mjs` file extensions.","message":"This package is ESM-only since v2.0.0 and further refined with 'exports' in v3.0.0. CommonJS `require()` statements will no longer work and will result in errors.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure that the `node` argument passed to `hasProperty` is a valid HAST `Node` (typically an `Element`), and the `field` argument is a string representing the property name. Avoid passing `null`, `undefined`, or other non-node values.","message":"Version 3.0.0 removes support for passing non-Node or non-name types as arguments to `hasProperty`. The function now expects valid HAST `Node` objects for the first argument and a string for the second.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always use named imports: `import { hasProperty } from 'hast-util-has-property'`. Do not use `import hasProperty from 'hast-util-has-property'`.","message":"The package only exports a named export `hasProperty`. There is no default export. Attempting to import it as a default will fail.","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 `const hasProperty = require('hast-util-has-property')` to `import { hasProperty } from 'hast-util-has-property'`. Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`).","cause":"Attempting to use CommonJS `require()` to import an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... hast-util-has-property.js from ... not supported."},{"fix":"Use the correct named import: `import { hasProperty } from 'hast-util-has-property'`. Verify that no default import syntax is used.","cause":"Incorrect import syntax, often trying to import a named export as a default, or attempting to `require()` an ESM module and access a non-existent default property.","error":"TypeError: hasProperty is not a function"},{"fix":"Ensure that the `node` argument supplied to `hasProperty` is always a well-formed HAST `Node` object, as expected by the utility.","cause":"Passing an invalid `node` argument (e.g., `null`, `undefined`, or a non-HAST object) to `hasProperty` after the v3.0.0 update, which enforced stricter input validation.","error":"TypeError: node is not a valid HAST node"}],"ecosystem":"npm"}