'use strict';

var through = require('through2')
  , pumpify = require('pumpify')
  , split = require('split')
  , regex = /^[ \t]+$/;

//
// Expose the transform.
//
module.exports = condenseify;

/**
 * Browserify transform to condense multiple blank lines
 * into a single blank line.
 *
 * @param {String} file File name
 * @param {Object} [options] Options object
 * @returns {Stream} Transform stream
 * @api public
 */
function condenseify(file, options) {
  if (/\.json$/.test(file)) return through();

  var appendNewLine = true
    , isBlank = false;

  options = options || {};

  function transform(line, encoding, next) {
    /* jshint validthis: true */
    if (!line.length) {
      isBlank = true;
      return next();
    }

    line = line.toString();
    if (!options['keep-non-empty'] && regex.test(line)) return next();

    if (isBlank) {
      isBlank = false;
      this.push('\n');
    }
    appendNewLine = false;
    this.push(line +'\n');
    next();
  }

  function flush(done) {
    /* jshint validthis: true */
    if (appendNewLine) this.push('\n');
    done();
  }

  return pumpify(split(), through(transform, flush));
}

@@ -107,33 +107,10 @@
 it')
-%0A  , regex = /%5E%5B %5Ct%5D+$/
 ;%0A
+
 %0A//%0A
@@ -491,28 +491,82 @@
 var 
-appendNewLine = true
+eol = new Buffer('%5Cn')%0A    , appendNewLine = true%0A    , regex = /%5E%5B %5Ct%5D+$/
 %0A   
@@ -700,18 +700,44 @@
     
+var length = line.length;%0A%0A    
 if (!
-line.
 leng
@@ -796,36 +796,8 @@
  %7D%0A%0A
-    line = line.toString();%0A
     
@@ -918,28 +918,27 @@
   this.push(
-'%5Cn'
+eol
 );%0A    %7D%0A   
@@ -979,18 +979,46 @@
 ush(
-line +'%5Cn'
+Buffer.concat(%5B line, eol %5D, ++length)
 );%0A 
@@ -1124,20 +1124,19 @@
 is.push(
-'%5Cn'
+eol
 );%0A    d

Use buffers to prevent node from doing unwanted checks