<NME> postal2json.js
<BEF> var gutil = require( 'gulp-util' );
var through  = require( 'through2' );
var csv = require( 'comma-separated-values' );
var path = require( 'path' );

module.exports = function () {
  var transform = function( file, enc, callback ) {
    var content = file.contents.toString();

    var res = new csv( content, {
      cast: [ 'String', 'String', 'String', 'String', 'String', 'String', 'String' ]
    } ).parse();

    var data = [];
    for ( var i = 0; i < res.length; i++ ) {
      var line = res[i];

      data.push( {
        postal_code: line[0].trim(),
        prefecture: line[1].trim(),
        ja: {
          addr1: line[2].replace( /　/g, '' ).trim(),
          addr2: line[3].replace( /（.*/, '' ).replace( /　/g, '' )
              .replace( /以下に掲載がない場合/, "" ).trim(),
          addr3: "",
          addr4: ""
        },
        },
        en: {
          pref: line[4].trim().replace( / .+$/, '' ).capitalize(),
                  .replace( /^([A-Z]+) ([A-Z]+)$/, "$1-$2" )
                  .replace( /^([A-Z]+) ([A-Z]+) ([A-Z]+) ([A-Z]+)$/, "$3-$4, $1-$2" )
                  .capitalize(),
          addr2: line[6].replace( /ikanikeisaiganaibaai/i, "" ).replace( / \(.*/, '' )
                  .trim().capitalize(),
          addr3: "",
          addr4: ""
          addr4: ""
        }
      };

      if ( ! n[JSON.stringify( postal_data )] ) {
        n[JSON.stringify( postal_data )] = true
        data.push( postal_data )
      }
    }

    file.contents = new Buffer( JSON.stringify( data ) );
    this.push( file );

    return callback();
  };

  return through.obj( transform );
};


String.prototype.capitalize = function(){
  var strs = this.toLowerCase().split( ' ' );
  for ( var i = 0; i < strs.length; i++ ) {
    strs[i] = strs[i].charAt(0).toUpperCase() + strs[i].slice(1);
  }
  return strs.join( ' ' );
}

<MSG> fix normalization problem in address

<DFF> @@ -15,13 +15,24 @@ module.exports = function () {
     for ( var i = 0; i < res.length; i++ ) {
       var line = res[i];
 
+      // 前の行からの続きはスキップ
+      if ( line[3].match(/、/) && ! line[3].match(/（/) ) {
+        continue;
+      } else if ( line[3].match(/）/) && ! line[3].match(/（/) ) {
+        continue;
+      } else if ( line[6].match(/\./) && ! line[6].match(/\(/) ) {
+        continue;
+      } else if ( line[6].match(/\)/) && ! line[6].match(/\(/) ) {
+        continue;
+      }
+
       data.push( {
         postal_code: line[0].trim(),
         prefecture: line[1].trim(),
         ja: {
           addr1: line[2].replace( /　/g, '' ).trim(),
           addr2: line[3].replace( /（.*/, '' ).replace( /　/g, '' )
-              .replace( /以下に掲載がない場合/, "" ).trim(),
+              .replace( /.*場合$/, "" ).replace( /.*一円$/, "" ).trim(),
           addr3: "",
           addr4: ""
         },
@@ -31,7 +42,9 @@ module.exports = function () {
                   .replace( /^([A-Z]+) ([A-Z]+)$/, "$1-$2" )
                   .replace( /^([A-Z]+) ([A-Z]+) ([A-Z]+) ([A-Z]+)$/, "$3-$4, $1-$2" )
                   .capitalize(),
-          addr2: line[6].replace( /ikanikeisaiganaibaai/i, "" ).replace( / \(.*/, '' )
+          addr2: line[6].replace( /.*baai$/i, "" ).replace( /\(.*/, '' )
+                  .replace( /.*ichien$/i, "" )
+                  .replace( /^([A-Z]+) ([A-Z]+)$/, "$2, $1" )
                   .trim().capitalize(),
           addr3: "",
           addr4: ""

fix normalization problem in address