index.js 347 B

1234567891011121314
  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. if (input[input.length - 1] === LF) {
  5. input = input.slice(0, -1);
  6. }
  7. if (input[input.length - 1] === CR) {
  8. input = input.slice(0, -1);
  9. }
  10. return input;
  11. }