redent 0.1.0

Strip redundant indentation and indent the string. A faithful port of the redent npm package (strip-indent + indent-string).
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 22.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 117.11 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/redent
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

redent

All Contributors

crates.io docs.rs CI license

Strip redundant indentation and re-indent a string.

Removes the common leading indentation from a multi-line string, then indents it by a fixed amount — handy for normalizing then re-formatting heredoc/template text. A faithful Rust port of the widely-used redent npm package, built on strip-indent and indent-string.

  • #![no_std]
  • Differential-tested against the reference redent implementation

Install

[dependencies]
redent = "0.1"

Usage

use redent::{redent, redent_with};

// Strip the common indent (count defaults to 0):
assert_eq!(redent("  foo\n    bar"), "foo\n  bar");

// Strip, then re-indent by two spaces:
assert_eq!(redent_with("  foo\n    bar", 2, " ", false), "  foo\n    bar");

// Custom indent + indent empty lines:
assert_eq!(redent_with("  a\n\n  b", 2, " ", true), "  a\n  \n  b");

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.