1 | # strip-final-newline [![Build Status](https://travis-ci.com/sindresorhus/strip-final-newline.svg?branch=master)](https://travis-ci.com/sindresorhus/strip-final-newline)
|
2 |
|
3 | > Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from a string/buffer
|
4 |
|
5 | Can be useful when parsing the output of, for example, `ChildProcess#execFile`, as [binaries usually output a newline at the end](https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline). Normally, you would use `stdout.trim()`, but that would also remove newlines at the start and whitespace.
|
6 |
|
7 |
|
8 | ## Install
|
9 |
|
10 | ```
|
11 | $ npm install strip-final-newline
|
12 | ```
|
13 |
|
14 |
|
15 | ## Usage
|
16 |
|
17 | ```js
|
18 | const stripFinalNewline = require('strip-final-newline');
|
19 |
|
20 | stripFinalNewline('foo\nbar\n\n');
|
21 | //=> 'foo\nbar\n'
|
22 |
|
23 | stripFinalNewline(Buffer.from('foo\nbar\n\n')).toString();
|
24 | //=> 'foo\nbar\n'
|
25 | ```
|
26 |
|
27 |
|
28 | ## License
|
29 |
|
30 | MIT © [Sindre Sorhus](https://sindresorhus.com)
|