readme.md (1141B)
1 # 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 ## Install 8 9 ``` 10 $ npm install strip-final-newline 11 ``` 12 13 ## Usage 14 15 ```js 16 import stripFinalNewline from 'strip-final-newline'; 17 18 stripFinalNewline('foo\nbar\n\n'); 19 //=> 'foo\nbar\n' 20 21 stripFinalNewline(Buffer.from('foo\nbar\n\n')).toString(); 22 //=> 'foo\nbar\n' 23 ``` 24 25 --- 26 27 <div align="center"> 28 <b> 29 <a href="https://tidelift.com/subscription/pkg/npm-strip-eof?utm_source=npm-strip-eof&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> 30 </b> 31 <br> 32 <sub> 33 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. 34 </sub> 35 </div>