# strip-indent
[](#contributors-)
[](https://crates.io/crates/strip-indent)
[](https://docs.rs/strip-indent)
[](https://github.com/trananhtung/strip-indent/actions/workflows/ci.yml)
[](#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`](https://www.npmjs.com/package/strip-indent) npm package (which
bundles [`min-indent`](https://www.npmjs.com/package/min-indent)).
- **Zero dependencies**, **`#![no_std]`**
- `strip_indent`, `min_indent`, and `dedent`
- Differential-tested against the reference `strip-indent`/`min-indent` implementations
## Install
```toml
[dependencies]
strip-indent = "0.1"
```
## Usage
```rust
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](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/trananhtung"><img src="https://avatars.githubusercontent.com/u/30992229?v=4?s=100" width="100px;" alt="Tung Tran"/><br /><sub><b>Tung Tran</b></sub></a><br /><a href="https://github.com/trananhtung/./commits?author=trananhtung" title="Code">💻</a> <a href="#maintenance-trananhtung" title="Maintenance">🚧</a></td>
</tr>
</tbody>
</table>
## License
Licensed under either of [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE) at your option.