# @freecodecamp/strip-comments 中文文档

规范地址：https://npmcn.com/package/%40freecodecamp/strip-comments/

版本：3\.0\.1
npm 元数据更新时间：2024-04-05T07:41:35.322Z
中文译文更新时间：2026-11-15T13:15:48.258Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40freecodecamp/strip-comments
原文对照：https://npmcn.com/package/%40freecodecamp/strip-comments/?lang=original
项目主页：https://github.com/freeCodeCamp/strip-comments
源码仓库：https://github.com/freeCodeCamp/strip-comments

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

- 包体积（解压后）：27.2 kB，9 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=10
- 运行依赖：0 个
- 首次发布：2021-05-26T08:43:10.382Z
- 最新版本发布：2021-07-16T10:18:48.300Z
- 近 30 天下载量：4438（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

从字符串中去除行和/或块注释 。 快速出击,并与JavaScript,Sass,CSS,Less.js等多种语言合作.

## 安装

```sh
npm install @freecodecamp/strip-comments
```

也可以使用：`pnpm add @freecodecamp/strip-comments`、`yarn add @freecodecamp/strip-comments`、`bun add @freecodecamp/strip-comments`

## README

# 脱衣评论 [![NPM version](https://img.shields.io/npm/v/@freecodecamp/strip-comments.svg?style=flat)](https://www.npmjs.com/package/@freecodecamp/strip-comments) [![NPM monthly downloads](https://img.shields.io/npm/dm/@freecodecamp/strip-comments.svg?style=flat)](https://npmjs.org/package/@freecodecamp/strip-comments) [![NPM total downloads](https://img.shields.io/npm/dt/@freecodecamp/strip-comments.svg?style=flat)](https://npmjs.org/package/@freecodecamp/strip-comments)

> 从字符串中去除行和/或块注释 。 快速出击,并与JavaScript,Sass,CSS,Less.js等多种语言合作.

请考虑跟随这个项目的作者, [乔恩·斯林克特](https://github.com/jonschlinkert),并考虑主演该项目以显示你的:心:和支持.

-   [安装](https://npmcn.com/package/%40freecodecamp/strip-comments/#readme-install)
-   [这有什么用?](https://npmcn.com/package/%40freecodecamp/strip-comments/#readme-what-does-this-do)
-   [使用量](https://npmcn.com/package/%40freecodecamp/strip-comments/#readme-usage)
-   [API 密码](https://npmcn.com/package/%40freecodecamp/strip-comments/#readme-api)
-   [关于](https://npmcn.com/package/%40freecodecamp/strip-comments/#readme-about)

## 安装

安装方式 [无](https://www.npmjs.com/) (所需经费) [节点.js](https://nodejs.org/en/) >=:

```sh
$ npm install --save strip-comments
```

## 这有什么用?

用字符串返回新字符串,并删除注释。 与行评论和/或块评论配合工作。 可选地只删除第一个注释或忽略被保护的评论.

工作单位:

-   阿达
-   页:1
-   苹果脚本
-   c. 国家
-   摇摆
-   密码
-   马鞭草
-   哈斯凯尔
-   贾瓦
-   日记
-   减
-   卢亚
-   垫板
-   词汇
-   帕斯卡尔
-   百分数
-   密码
-   蟒蛇
-   红宝石
-   萨斯
-   弹出
-   坐标
-   快点
-   标注符
-   ưμ㼯a

## 使用量

默认情况下,所有评论都被删除.

```js
const strip = require('strip-comments');
const str = strip('const foo = "bar";// this is a comment\n /* me too *\/');
console.log(str);
// => 'const foo = "bar";\n'
```

更多用户请查看 [测试](https://npmcn.com/package/%40freecodecamp/strip-comments/test)

## API 密码

### [脱去](https://npmcn.com/package/%40freecodecamp/strip-comments/index.js#L33)

从给定的代码中删除全部代码注释 `input`,包括从 `!`,除非设置已禁用 `options.keepProtected` 真实的.

**参数**

-   `input` **{string}(string ) , \[ 弦叫 \]**: 从中取出批注的字符串
-   `options` **{对象}**: 可选选项, 转到 [摘录](https://github.com/jonschlinkert/extract-comments)

-   `line` **(保罗)**: 如果 `false` 只脱去块注释, 默认 `true`
-   `block` **(保罗)**: 如果 `false` 只删除行注释, 默认 `true`
-   `keepProtected` **(保罗)**: 保留被忽略的注释(例如. `/*!` 财务报告和审定财务报表 `//!`(中文(简体) )
-   `preserveNewlines` **(保罗)**: 在评论被删除后保留新行

-   `returns` **{string}(string ) , \[ 弦叫 \]**: 已修改的输入

**示例**

```js
const str = strip('const foo = "bar";// this is a comment\n /* me too */');
console.log(str);
// => 'const foo = "bar";'
```

### [块](https://npmcn.com/package/%40freecodecamp/strip-comments/index.js#L54)

只删除块评论 .

**参数**

-   `input` **{string}(string ) , \[ 弦叫 \]**: 从中取出批注的字符串
-   `options` **{对象}**: 通过 `opts.keepProtected: true` 以保留被忽略的注释(例如). `/*!`(中文(简体) )
-   `returns` **{string}(string ) , \[ 弦叫 \]**: 已修改的字符串

**示例**

```js
const strip = require('..');
const str = strip.block('const foo = "bar";// this is a comment\n /* me too */');
console.log(str);
// => 'const foo = "bar";// this is a comment'
```

### [线条](https://npmcn.com/package/%40freecodecamp/strip-comments/index.js#L74)

只取行注释.

**参数**

-   `input` **{string}(string ) , \[ 弦叫 \]**: 从中取出批注的字符串
-   `options` **{对象}**: 通过 `opts.keepProtected: true` 以保留被忽略的注释(例如). `//!`(中文(简体) )
-   `returns` **{string}(string ) , \[ 弦叫 \]**: 已修改的字符串

**示例**

```js
const str = strip.line('const foo = "bar";// this is a comment\n /* me too */');
console.log(str);
// => 'const foo = "bar";\n/* me too */'
```

### [第一个](https://npmcn.com/package/%40freecodecamp/strip-comments/index.js#L95)

删除给定的第一个注释 `input`或者,如果 `opts.keepProtected` ,第一个未保护的注释将被删除.

**参数**

-   `input` **{string}(string ) , \[ 弦叫 \]**
-   `options` **{对象}**: 通过 `opts.keepProtected: true` 保留注释 `!`
-   `returns` **{string}(string ) , \[ 弦叫 \]**

**示例**

```js
const output = strip.first(input, { keepProtected: true });
console.log(output);
// => '//! first comment\nfoo; '
```

### [块](https://npmcn.com/package/%40freecodecamp/strip-comments/index.js#L116)

解析字符串并返回一个基本的 CST( 具体语法树) .

**参数**

-   `input` **{string}(string ) , \[ 弦叫 \]**: 从中取出批注的字符串
-   `options` **{对象}**: 通过 `opts.keepProtected: true` 以保留被忽略的注释(例如). `/*!`(中文(简体) )
-   `returns` **{string}(string ) , \[ 弦叫 \]**: 已修改的字符串

**示例**

```js
const strip = require('..');
const str = strip.block('const foo = "bar";// this is a comment\n /* me too */');
console.log(str);
// => 'const foo = "bar";// this is a comment'
```

## 关于

**捐款**

拉出请求和星星总是受欢迎的. 对于错误和特性请求, [请创建一个问题](https://npmcn.com/package/issues/new)。 。 。 .

**运行测试**

运行和审查单元测试是熟悉图书馆及其API的好办法。 您可以使用以下命令安装依赖性并运行测试:

```sh
$ npm install && npm test
```
**大楼文件**

_(此工程的 readme.md 由 [动词](https://github.com/verbose/verb-generate-readme)请不要直接编辑读取器。 读取器的任何改动必须在 [动词 md](https://npmcn.com/package/%40freecodecamp/strip-comments/.verb.md) 读取我的模板。 )_

要生成读取, 请运行以下命令 :

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### 相关项目

您可能也对这些项目感兴趣:

-   [密码文字](https://www.npmjs.com/package/code-context): 解析一串javascript,以确定基于函数,变量和注释的上下文 [更多](https://github.com/jonschlinkert/code-context) | [主页](https://github.com/jonschlinkert/code-context "Parse a string of javascript to determine the context for functions, variables and comments based on the code that follows.")
-   [摘录](https://www.npmjs.com/package/extract-comments): 使用esprima来取出一串JavaScript的行并屏蔽注释. 也可以选择.. [更多](https://github.com/jonschlinkert/extract-comments) | [主页](https://github.com/jonschlinkert/extract-comments "Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).")
-   [解析码- 文本](https://www.npmjs.com/package/parse-code-context):快速而简单的方式解析代码上下文,以便与代码注释中的文档一起使用 [更多](https://github.com/jonschlinkert/parse-code-context) | [主页](https://github.com/jonschlinkert/parse-code-context "Fast and simple way to parse code context for use with documentation from code comments. Parses context from a single line of JavaScript, for functions, variable declarations, methods, prototype properties, prototype methods etc.")
-   [注释](https://www.npmjs.com/package/parse-comments):从JavaScript或任何使用同一种格式的语言解析代码注释. | [主页](https://github.com/jonschlinkert/parse-comments "Parse code comments from JavaScript or any language that uses the same format.")

### 贡献者

| **提交** | **贡献者** |  
| -- -- -- -- -- -- --  
82个 [扬施林克特](https://github.com/jonschlinkert) |  
页:1 [tunncko 企业](https://github.com/tunnckoCore) |  
|2| [mk -pmb (英语)](https://github.com/mk-pmb) |  
| 1 | [千克升](https://github.com/kgryte) |  
| 1 | [布里安迪帕尔马](https://github.com/briandipalma) |  
| 1 | [奇异主义](https://github.com/epicoxymoron) |  
| 1 | [克吕瓦尔](https://github.com/XuluWarrior) |

### 作者

**乔恩·斯林克特**

-   [GitHub 配置文件](https://github.com/jonschlinkert)
-   [推特简介](https://twitter.com/jonschlinkert)
-   [链接到配置文件](https://linkedin.com/in/jonschlinkert)

### 许可证

版权所有: 2019, [乔恩·斯林克特](https://github.com/jonschlinkert)。 。 。 . 释放 [MIT 许可证](https://npmcn.com/package/%40freecodecamp/strip-comments/LICENSE)。 。 。 .

## 常见问题

### @freecodecamp/strip-comments 是什么？

从字符串中去除行和/或块注释 。 快速出击,并与JavaScript,Sass,CSS,Less\.js等多种语言合作\.

### 如何安装 @freecodecamp/strip-comments？

在项目目录运行 npm install @freecodecamp/strip-comments，或使用 pnpm add / yarn add / bun add。

### @freecodecamp/strip-comments 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/freecodecamp\_\_strip-comments 是否存在。

### @freecodecamp/strip-comments 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @freecodecamp/strip-comments 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=10。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @freecodecamp/strip-comments 可以商用吗？

@freecodecamp/strip-comments 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @freecodecamp/strip-comments 的下载量有多少？

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

### @freecodecamp/strip-comments 还在维护吗？

最新版本 3\.0\.1 发布于 2021/07/16（5 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/05/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

