Registry / web-framework / hast-util-is-conditional-comment

hast-util-is-conditional-comment

JSON →
library3.0.1jsnpmunverified

This package, `hast-util-is-conditional-comment`, is a specialized utility within the unified (specifically rehype) ecosystem designed to determine if a given `hast` (Hypertext Abstract Syntax Tree) node represents an HTML conditional comment. Conditional comments are a legacy feature primarily used by older versions of Internet Explorer (discontinued after IE 9) and are generally recommended for removal in modern web development. The current stable version is 3.0.1. As part of the `unified` collective, it adheres to a release cadence tied to major `unified` ecosystem updates, ensuring compatibility with other `hast` and `unist` utilities. Key differentiators include its tight integration with the `hast` AST format, its ESM-only distribution, and its strict compatibility with maintained Node.js versions (currently Node.js 16+). It does not perform transformations but provides a focused predicate function for identifying this specific, non-standard HTML comment type.

npm install hast-util-is-conditional-comment
INSTALL
IMPORT
SIG · HAST-UTIL-IS-CONDI
H
hast-util-is-conditional-comment
web-frameworkjavascriptv3.0.1
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.

isConditionalComment
import { isConditionalComment } from 'hast-util-is-conditional-comment'
const isConditionalComment = require('hast-util-is-conditional-comment')
This package is ESM-only since v3 and exports `isConditionalComment` as a named export. CommonJS `require` is not supported.
Node
import type { Node } from 'hast'
import { Node } from 'hast'
For TypeScript users, import `Node` as a type from `hast` to ensure correct type checking for AST nodes.
u
import { u } from 'unist-builder'
import u from 'unist-builder'
`u` from `unist-builder` is often used for creating `unist` (and by extension `hast`) nodes in examples. It is a named export, not a default export.

Demonstrates how to import and use `isConditionalComment` to programmatically check various `hast` comment nodes for Internet Explorer conditional comment syntax.

import { isConditionalComment } from 'hast-util-is-conditional-comment'; import { u } from 'unist-builder'; // u for creating unist/hast nodes // A valid IE conditional comment const ieConditionalComment = u({ type: 'comment', value: '[if IE]>...<![endif]' }); // An IE conditional end comment const ieConditionalEndComment = u({ type: 'comment', value: '<![endif]' }); // A regular HTML comment const regularComment = u({ type: 'comment', value: 'This is a regular comment' }); console.log('Is IE Conditional Comment (full):', isConditionalComment(ieConditionalComment)); // => true console.log('Is IE Conditional Comment (end):', isConditionalComment(ieConditionalEndComment)); // => true console.log('Is Regular Comment:', isConditionalComment(regularComment)); // => false
Debug
Known issues
breakingVersion 3.x of `hast-util-is-conditional-comment` is ESM-only and requires Node.js 16 or later. Attempting to use it in a CommonJS environment or older Node.js versions will result in import errors or runtime failures.
fix
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json` or `.mjs` files) and upgrade Node.js to version 16 or newer. Replace `require()` calls with `import` statements.
affects: >=3.0.0
gotchaWhile this utility itself only checks node types and does not modify the AST, working with `hast` trees in general (especially with other `rehype` plugins) can expose applications to Cross-Site Scripting (XSS) vulnerabilities if not handled carefully.
fix
Always use `rehype-sanitize` when processing untrusted HTML to prevent potential XSS attacks, especially if other plugins are transforming the tree.
affects: >=1.0.0
gotchaThis package specifically identifies legacy Internet Explorer conditional comments. It will not identify other types of special comments or directives, only the specific patterns recognized as IE conditional comments.
fix
If you need to identify other specific comment patterns, you will need to implement custom logic or use other `hast` utilities designed for broader comment analysis.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import `hast-util-is-conditional-comment` in a CommonJS module.
fix
Change your import statement to `import { isConditionalComment } from 'hast-util-is-conditional-comment';` and ensure your environment supports ESM.
TypeError: isConditionalComment is not a function
Incorrectly importing `isConditionalComment` as a default import, or attempting to destructure from a module that has no named export.
fix
The package has no default export. Always use named import syntax: `import { isConditionalComment } from 'hast-util-is-conditional-comment';`.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
hast-util-is-conditional-comment — npm install hast-util-is-conditional-comment · libregistry