strip-indent
Strip leading whitespace from each line in a string
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install strip-indent 
SYNC missed versions from official npm registry.

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
*/

Related

Current Tags

  • 4.1.1                                ...           latest (a year ago)

11 Versions

  • 4.1.1                                ...           a year ago
  • 4.1.0                                ...           a year ago
  • 4.0.0                                ...           6 years ago
  • 3.0.0                                ...           8 years ago
  • 2.0.0                                ...           11 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.3                                ...           13 years ago
  • 0.1.2                                ...           13 years ago
  • 0.1.1                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 49
Today 0
This Week 0
This Month 24
Last Day 0
Last Week 11
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE