{"id":11004,"library":"hast-util-is-conditional-comment","title":"HAST Utility: Is Conditional Comment","description":"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.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","comment","conditional","hast","hast-util","html","unist","util","utility","typescript"],"install":[{"cmd":"npm install hast-util-is-conditional-comment","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-is-conditional-comment","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-is-conditional-comment","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v3 and exports `isConditionalComment` as a named export. CommonJS `require` is not supported.","wrong":"const isConditionalComment = require('hast-util-is-conditional-comment')","symbol":"isConditionalComment","correct":"import { isConditionalComment } from 'hast-util-is-conditional-comment'"},{"note":"For TypeScript users, import `Node` as a type from `hast` to ensure correct type checking for AST nodes.","wrong":"import { Node } from 'hast'","symbol":"Node","correct":"import type { Node } from 'hast'"},{"note":"`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.","wrong":"import u from 'unist-builder'","symbol":"u","correct":"import { u } from 'unist-builder'"}],"quickstart":{"code":"import { isConditionalComment } from 'hast-util-is-conditional-comment';\nimport { u } from 'unist-builder'; // u for creating unist/hast nodes\n\n// A valid IE conditional comment\nconst ieConditionalComment = u({ type: 'comment', value: '[if IE]>...<![endif]' });\n// An IE conditional end comment\nconst ieConditionalEndComment = u({ type: 'comment', value: '<![endif]' });\n// A regular HTML comment\nconst regularComment = u({ type: 'comment', value: 'This is a regular comment' });\n\nconsole.log('Is IE Conditional Comment (full):', isConditionalComment(ieConditionalComment));\n// => true\nconsole.log('Is IE Conditional Comment (end):', isConditionalComment(ieConditionalEndComment));\n// => true\nconsole.log('Is Regular Comment:', isConditionalComment(regularComment));\n// => false","lang":"typescript","description":"Demonstrates how to import and use `isConditionalComment` to programmatically check various `hast` comment nodes for Internet Explorer conditional comment syntax."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always use `rehype-sanitize` when processing untrusted HTML to prevent potential XSS attacks, especially if other plugins are transforming the tree.","message":"While 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","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 to `import { isConditionalComment } from 'hast-util-is-conditional-comment';` and ensure your environment supports ESM.","cause":"Attempting to use `require()` to import `hast-util-is-conditional-comment` in a CommonJS module.","error":"ERR_REQUIRE_ESM"},{"fix":"The package has no default export. Always use named import syntax: `import { isConditionalComment } from 'hast-util-is-conditional-comment';`.","cause":"Incorrectly importing `isConditionalComment` as a default import, or attempting to destructure from a module that has no named export.","error":"TypeError: isConditionalComment is not a function"}],"ecosystem":"npm"}