strip-indent
Strip leading indentation from a multi-line string.
Removes the leading whitespace common to every line, based on the least-indented line —
useful for normalizing indented template/heredoc text. A faithful Rust port of the
widely-used strip-indent npm package (which
bundles min-indent).
- Zero dependencies,
#![no_std] strip_indent,min_indent, anddedent- Differential-tested against the reference
strip-indent/min-indentimplementations
Install
[]
= "0.1"
Usage
use ;
assert_eq!;
assert_eq!;
// The common indent, in leading spaces/tabs:
assert_eq!;
// Also trim leading/trailing blank lines:
assert_eq!;
Indentation is counted in characters (a tab counts as one), and lines that are empty or contain only whitespace are ignored when computing the common indent.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.