strip-indent

中文文档
4.1.1发布于 2025/10/12MITTypeScriptES Module零依赖近 30 天下载 4亿

Strip leading whitespace from each line in a string

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. API
  4. stripIndent(string)
  5. dedent(string)
  6. Related

strip-indent

Strip leading whitespace from each line in a string

The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.

Useful for removing redundant indentation.

Install

npm install strip-indent

Usage

import stripIndent from 'strip-indent';

const string = '\tunicorn\n\t\tcake';
/*
    unicorn
        cake
*/

stripIndent(string);
/*
unicorn
    cake
*/

API

stripIndent(string)

Strip leading whitespace from each line in a string.

The line with the least number of leading whitespace, ignoring empty lines, determines the number to remove.

dedent(string)

Strip leading whitespace from each line in a string and remove surrounding blank lines.

Like stripIndent(), but also removes leading and trailing lines that contain only whitespace. Useful for template literals and multi-line strings where you want clean boundaries.

import {dedent} from 'strip-indent';

dedent(`
    unicorn
        cake
`);
/*
unicorn
    cake
*/

版本与发布记录

strip-indent 共发布 11 个版本,首次发布于 2014/03/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.1.1latest2025/10/121.1 年前
4.1.02025/09/111.1 年前
4.0.02021/05/035 年前
3.0.02019/04/177 年前
2.0.02016/04/2210 年前
1.0.12015/02/1711 年前

关于 strip-indent 的常见问题

strip-indent 是什么?

Strip leading whitespace from each line in a string

如何安装 strip-indent?

在项目目录运行 npm install strip-indent,或使用 pnpm add / yarn add / bun add。

strip-indent 支持 TypeScript 吗?

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

strip-indent 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

strip-indent 需要什么版本的 Node.js?

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

strip-indent 可以商用吗?

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

strip-indent 的下载量有多少?

根据 npm 官方下载统计,strip-indent 在 2026/10/05 – 2026/11/03 这 30 天内被下载 402,313,597 次,日均约 13,410,453 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

strip-indent 还在维护吗?

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