pax_global_header00006660000000000000000000000064133652723720014524gustar00rootroot0000000000000052 comment=51c93d6c8683d9fd1cacdb32f2afebac9a1155a1 strip-final-newline-2.0.0/000077500000000000000000000000001336527237200154125ustar00rootroot00000000000000strip-final-newline-2.0.0/.editorconfig000066400000000000000000000002571336527237200200730ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 strip-final-newline-2.0.0/.gitattributes000066400000000000000000000000231336527237200203000ustar00rootroot00000000000000* text=auto eol=lf strip-final-newline-2.0.0/.gitignore000066400000000000000000000000271336527237200174010ustar00rootroot00000000000000node_modules yarn.lock strip-final-newline-2.0.0/.npmrc000066400000000000000000000000231336527237200165250ustar00rootroot00000000000000package-lock=false strip-final-newline-2.0.0/.travis.yml000066400000000000000000000000641336527237200175230ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' - '6' strip-final-newline-2.0.0/index.js000066400000000000000000000005601336527237200170600ustar00rootroot00000000000000'use strict'; module.exports = input => { const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt(); const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt(); if (input[input.length - 1] === LF) { input = input.slice(0, input.length - 1); } if (input[input.length - 1] === CR) { input = input.slice(0, input.length - 1); } return input; }; strip-final-newline-2.0.0/license000066400000000000000000000021251336527237200167570ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. strip-final-newline-2.0.0/package.json000066400000000000000000000012061336527237200176770ustar00rootroot00000000000000{ "name": "strip-final-newline", "version": "2.0.0", "description": "Strip the final newline character from a string/buffer", "license": "MIT", "repository": "sindresorhus/strip-final-newline", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=6" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "strip", "trim", "remove", "delete", "final", "last", "end", "file", "newline", "linebreak", "character", "string", "buffer" ], "devDependencies": { "ava": "^0.25.0", "xo": "^0.23.0" } } strip-final-newline-2.0.0/readme.md000066400000000000000000000016331336527237200171740ustar00rootroot00000000000000# strip-final-newline [![Build Status](https://travis-ci.com/sindresorhus/strip-final-newline.svg?branch=master)](https://travis-ci.com/sindresorhus/strip-final-newline) > Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from a string/buffer 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. ## Install ``` $ npm install strip-final-newline ``` ## Usage ```js const stripFinalNewline = require('strip-final-newline'); stripFinalNewline('foo\nbar\n\n'); //=> 'foo\nbar\n' stripFinalNewline(Buffer.from('foo\nbar\n\n')).toString(); //=> 'foo\nbar\n' ``` ## License MIT © [Sindre Sorhus](https://sindresorhus.com) strip-final-newline-2.0.0/test.js000066400000000000000000000014551336527237200167340ustar00rootroot00000000000000import test from 'ava'; import stripFinalNewline from '.'; test('string', t => { t.is(stripFinalNewline('foo\n'), 'foo'); t.is(stripFinalNewline('foo\nbar\n'), 'foo\nbar'); t.is(stripFinalNewline('foo\n\n\n'), 'foo\n\n'); t.is(stripFinalNewline('foo\r\n'), 'foo'); t.is(stripFinalNewline('foo\r'), 'foo'); t.is(stripFinalNewline('foo\n\r\n'), 'foo\n'); }); test('buffer', t => { t.is(stripFinalNewline(Buffer.from('foo\n')).toString(), 'foo'); t.is(stripFinalNewline(Buffer.from('foo\nbar\n')).toString(), 'foo\nbar'); t.is(stripFinalNewline(Buffer.from('foo\n\n\n').toString()), 'foo\n\n'); t.is(stripFinalNewline(Buffer.from('foo\r\n')).toString(), 'foo'); t.is(stripFinalNewline(Buffer.from('foo\r')).toString(), 'foo'); t.is(stripFinalNewline(Buffer.from('foo\n\r\n')).toString(), 'foo\n'); });