# @ciolabs/html-find-conditional-comments 中文文档

规范地址：https://npmcn.com/package/%40ciolabs/html-find-conditional-comments/

版本：0\.0\.2
npm 元数据更新时间：2025-11-17T16:20:56.174Z
中文译文更新时间：2026-11-09T16:24:56.937Z
软件包许可：Apache-2\.0 WITH Commons-Clause

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ciolabs/html-find-conditional-comments
原文对照：https://npmcn.com/package/%40ciolabs/html-find-conditional-comments/?lang=original
项目主页：https://github.com/customerio/ciolabs/tree/main/packages/html-find-conditional-comments#readme
源码仓库：https://github.com/customerio/ciolabs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：20.5 kB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2025-09-18T17:04:30.706Z
- 最新版本发布：2025-11-17T16:20:55.970Z
- 近 30 天下载量：22395（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 1 个）

## 中文简介

在字符串中查找所有有条件的注释

## 安装

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

也可以使用：`pnpm add @ciolabs/html-find-conditional-comments`、`yarn add @ciolabs/html-find-conditional-comments`、`bun add @ciolabs/html-find-conditional-comments`

## README

# @ciolabs/html-find-无条件评论

> 在字符串中查找所有有条件的注释

## 安装

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

## 使用量

```js
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 密码

### 找到条件性评论( html)

返回每个注释的对象矩阵,其属性如下:

#### 为 Comment

> `boolean`

注释是否为 HTML 注释 。 这可能是 `false` 用于某些项目时 `downlevel` 实值 `revealed`。 。 。 .

#### 打开

> `string`

有条件注释的开口部分.

#### 关闭

> `string`

条件性注释的收尾部分.

#### 发泡

> `boolean`

是否围绕数值的注释"bubbles" .

何时 `true`,除支持有条件评论的平台外,所有平台都可以看到该注释.

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

何时 `false`,该注释从所有平台被隐藏,但支持有条件注释的平台除外.

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

#### 下层

> `'hidden' | 'revealed'`

无论是 `hidden` 或者说 `revealed`。 。 。 .

`hidden` 指除支持有条件评论的平台外,所有平台都隐藏了注释.

`revealed` 指除支持有条件评论的平台外,所有平台都可以看到注释.

这是非常相似的 `bubble` 财产,但并不一样.

`downlevel` 永远 `revealed` 若为 `bubble` 实值 `true`。 。 。 .

不过 `bubble` 可能会是 `true` 即便 `downlevel` 实值 `hidden` 使用此语法时 :

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

学习更多关于 [下层条件注释](https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/ms537512\(v%3dvs.85\)#downlevel-hidden-conditional-comments)。 。 。 .

#### 范围

> `[number, number]`

包含注释起始和结尾索引的区域数组.

## 类型脚本支持

此软件包由TypeScript所构建,并提供了完整的类型定义.

## 常见问题

### @ciolabs/html-find-conditional-comments 是什么？

在字符串中查找所有有条件的注释

### 如何安装 @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 和提交记录判断。

