Registry / serialization / hast-util-has-property

hast-util-has-property

JSON →
library3.0.0jsnpmunverified

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.

npm install hast-util-has-property
INSTALL
IMPORT
SIG · HAST-UTIL-HAS-PROP
H
hast-util-has-property
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.

hasProperty
import { hasProperty } from 'hast-util-has-property'
const hasProperty = require('hast-util-has-property')
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.
hasProperty
import { hasProperty } from 'https://esm.sh/hast-util-has-property@3'
For Deno and browser environments, use an ESM CDN like esm.sh, optionally with `?bundle` for browser usage.

Demonstrates how to import and use the `hasProperty` function to check for the existence of properties on different HAST nodes.

import {hasProperty} from 'hast-util-has-property' // Example 1: Text node has no properties, so 'bravo' is false. hasProperty({type: 'text', value: 'alpha'}, 'bravo') // => false // Example 2: Element node without 'className' property. hasProperty( { type: 'element', tagName: 'div', properties: {id: 'bravo'}, children: [] }, 'className' ) // => false // Example 3: Element node with 'id' property. hasProperty( { type: 'element', tagName: 'div', properties: {id: 'charlie'}, children: [] }, 'id' ) // => true console.log('Checked properties successfully.')
Debug
Known issues
breakingVersion 3.0.0 of `hast-util-has-property` requires Node.js 16 or newer. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or higher. For projects that cannot upgrade, consider pinning to `hast-util-has-property@2`.
affects: >=3.0.0
breakingThis 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.
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.
affects: >=2.0.0
breakingVersion 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.
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.
affects: >=3.0.0
gotchaThe package only exports a named export `hasProperty`. There is no default export. Attempting to import it as a default will fail.
fix
Always use named imports: `import { hasProperty } from 'hast-util-has-property'`. Do not use `import hasProperty from 'hast-util-has-property'`.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... hast-util-has-property.js from ... not supported.
Attempting to use CommonJS `require()` to import an ESM-only package.
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`).
TypeError: hasProperty is not a function
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.
fix
Use the correct named import: `import { hasProperty } from 'hast-util-has-property'`. Verify that no default import syntax is used.
TypeError: node is not a valid HAST node
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.
fix
Ensure that the `node` argument supplied to `hasProperty` is always a well-formed HAST `Node` object, as expected by the utility.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
hast-util-has-property — npm install hast-util-has-property · libregistry