strip-indent
Strip leading whitespace from each line in a string
Last updated 6 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm 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 (6 months ago)

11 Versions

  • 4.1.1                                ...           6 months ago
  • 4.1.0                                ...           7 months ago
  • 4.0.0                                ...           5 years ago
  • 3.0.0                                ...           7 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.3                                ...           12 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 164
This Month 231
Last Day 30
Last Week 107
Last Month 595
Dependencies (0)
None
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |