strip-indent

Strip leading whitespace from each line in a string

MIT 11 个版本
安装
npm install strip-indent
yarn add strip-indent
pnpm add strip-indent
bun add strip-indent
README

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
*/
版本列表
4.1.1 2025-10-12
4.1.0 2025-09-11
4.0.0 2021-05-03
3.0.0 2019-04-17
2.0.0 2016-04-22
1.0.1 2015-02-16
1.0.0 2014-08-13
0.1.3 2014-04-29
0.1.2 2014-04-16
0.1.1 2014-04-06
0.1.0 2014-03-29