HAST Utility: Is Conditional Comment

3.0.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →