index.js (347B)
1 export default function stripFinalNewline(input) { 2 const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt(); 3 const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt(); 4 5 if (input[input.length - 1] === LF) { 6 input = input.slice(0, -1); 7 } 8 9 if (input[input.length - 1] === CR) { 10 input = input.slice(0, -1); 11 } 12 13 return input; 14 }