trim-newlines 0.1.0

Trim newlines (\r and \n) from the start and/or end of a string. A faithful port of the trim-newlines 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: 22.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 106.98 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/trim-newlines
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

trim-newlines

All Contributors

crates.io docs.rs CI license

Trim newlines from the start and/or end of a string.

Removes leading and trailing newline characters — \r and \n only, not other whitespace. A faithful Rust port of the widely-used trim-newlines npm package.

  • Zero dependencies, #![no_std]
  • Returns a borrowed &str slice (no allocation)
  • Differential-tested against the reference trim-newlines implementation

Install

[dependencies]
trim-newlines = "0.1"

Usage

use trim_newlines::{trim_newlines, trim_newlines_start, trim_newlines_end};

assert_eq!(trim_newlines("\n\nfoo\n\n"), "foo");
assert_eq!(trim_newlines_start("\r\nbar\r\n"), "bar\r\n");
assert_eq!(trim_newlines_end("\r\nbar\r\n"), "\r\nbar");

// Only newlines are trimmed — spaces and tabs are preserved:
assert_eq!(trim_newlines("  spaced  "), "  spaced  ");

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.