advent-of-code

Entries to advent of code, multiple years
git clone git://git.finwo.net/misc/advent-of-code
Log | Files | Refs

normalize-newlines.js (437B)


      1 const through = require('through2');
      2 
      3 module.exports = () => through(function(chunk, enc, cb) {
      4   chunk = chunk.toString();
      5   switch(chunk) {
      6     case '\r':
      7       if (this.osx) {
      8         this.push('\n');
      9       }
     10       this.osx = true;
     11       break;
     12     default:
     13       if (this.osx) {
     14         if (chunk !== '\n') {
     15           this.push('\n');
     16         }
     17         this.osx = false;
     18       }
     19       this.push(chunk);
     20       break;
     21   }
     22   cb();
     23 });