strip-indent 0.1.0

Strip leading whitespace from each line of a multi-line string, based on the least-indented line. A faithful port of the strip-indent npm package. Zero deps, no_std.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented4 out of 4 items with examples
  • Size
  • Source code size: 26.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 132.75 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/strip-indent
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

strip-indent

All Contributors

crates.io docs.rs CI license

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, and dedent
  • Differential-tested against the reference strip-indent/min-indent implementations

Install

[dependencies]
strip-indent = "0.1"

Usage

use strip_indent::{strip_indent, min_indent, dedent};

assert_eq!(strip_indent("    foo\n      bar"), "foo\n  bar");
assert_eq!(strip_indent("\tfoo\n\t\tbar"), "foo\n\tbar");

// The common indent, in leading spaces/tabs:
assert_eq!(min_indent("  a\n    b"), 2);

// Also trim leading/trailing blank lines:
assert_eq!(dedent("\n\n   foo\n   bar\n\n"), "foo\nbar");

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.