indent-string 0.1.0

Indent each line of a multi-line string. A faithful port of the indent-string npm package. Zero dependencies, no_std.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 25.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 125.33 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/indent-string
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

indent-string

All Contributors

crates.io docs.rs CI license

Indent each line of a multi-line string.

foo\nbar foo\n bar. A faithful Rust port of the widely-used indent-string npm package. The counterpart of strip-indent.

  • Zero dependencies, #![no_std]
  • Repeat count, custom indent string, and an include_empty_lines option
  • Differential-tested against the reference indent-string implementation

Install

[dependencies]
indent-string = "0.1"

Usage

use indent_string::{indent_string, indent_string_with};

assert_eq!(indent_string("foo\nbar"), " foo\n bar");

// Repeat count + custom indent:
assert_eq!(indent_string_with("foo\nbar", 2, "\t", false), "\t\tfoo\n\t\tbar");

// By default, empty / whitespace-only lines are not indented:
assert_eq!(indent_string("foo\n\nbar"), " foo\n\n bar");

// ...unless you opt in:
assert_eq!(indent_string_with("foo\n\nbar", 1, " ", true), " foo\n \n bar");

A count of 0 returns the string unchanged. Indentation is applied after every JavaScript line terminator (\n, \r, \u{2028}, \u{2029}), matching the reference's /^/gm.

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.