@ciolabs/html-find-conditional-comments

中文文档
0.0.2发布于 2025/11/18Apache-2.0 WITH Commons-ClauseTypeScriptESM + CJS零依赖近 30 天下载 2.2万

Finds all conditional comments in a string

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. API
  4. findConditionalComments(html)
  5. TypeScript Support

@ciolabs/html-find-conditional-comments

Finds all conditional comments in a string

Install

npm install @ciolabs/html-find-conditional-comments

Usage

import findConditionalComments from '@ciolabs/html-find-conditional-comments';

const html = `
<!--[if mso]>
Hello, Microsoft Outlook!
<![endif]-->
`;

findConditionalComments(html);
//=> [ { open: "<!--[if mso]>", close: "<![endif]-->", range: [1, 63], downlevel: "hidden", isComment: true, bubble: false } ]

API

findConditionalComments(html)

Returns an Array of Objects for each comment with the following properties:

isComment

boolean

Whether the comment is an HTML comment. This might be false for certain items when downlevel is revealed.

open

string

Opening portion of the conditional comment.

close

string

Closing portion of the conditional comment.

bubble

boolean

Whether the comment "bubbles" around the value.

When true, the comment is visible to all platforms except those that support conditional comments.

<!--[if !mso]>-->
Hello, Not Microsoft Outlook!
<!--<![endif]-->

When false, the comment is hidden from all platforms except those that support conditional comments.

<!--[if mso]> Hello, Microsoft Outlook! <![endif]-->

downlevel

'hidden' | 'revealed'

Either hidden or revealed.

hidden means the comment is hidden from all platforms except those that support conditional comments.

revealed means the comment is visible to all platforms except those that support conditional comments.

This is very similar to the bubble property, but it's not the same.

downlevel always be revealed if bubble is true.

But bubble can be true even if downlevel is hidden when using this syntax:

<![if lt IE 8]>
<p>Please upgrade to Internet Explorer version 8.</p>
<![endif]>

Learn more about downlevel conditional comments.

range

[number, number]

A range array containing the start and end indices of the comment.

TypeScript Support

This package is built with TypeScript and provides full type definitions.

版本与发布记录

@ciolabs/html-find-conditional-comments 共发布 3 个版本,首次发布于 2025/09/19;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.0.2latest2025/11/1811 个月前
0.0.12025/09/191.1 年前
0.0.02025/09/191.1 年前

关于 @ciolabs/html-find-conditional-comments 的常见问题

@ciolabs/html-find-conditional-comments 是什么?

Finds all conditional comments in a string

如何安装 @ciolabs/html-find-conditional-comments?

在项目目录运行 npm install @ciolabs/html-find-conditional-comments,或使用 pnpm add / yarn add / bun add。

@ciolabs/html-find-conditional-comments 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ciolabs/html-find-conditional-comments 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ciolabs/html-find-conditional-comments 可以商用吗?

@ciolabs/html-find-conditional-comments 使用 Apache-2.0 WITH Commons-Clause 许可。声明的许可为 Apache-2.0 WITH Commons-Clause,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@ciolabs/html-find-conditional-comments 的下载量有多少?

根据 npm 官方下载统计,@ciolabs/html-find-conditional-comments 在 2026/10/10 – 2026/11/08 这 30 天内被下载 22,395 次,日均约 747 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ciolabs/html-find-conditional-comments 还在维护吗?

最新版本 0.0.2 发布于 2025/11/18(11 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/09/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。