Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace some foreach callback with simple for loops

  • Loading branch information...
commit 9333d0b62129d28b63ce335c4dc5148c158d14d1 1 parent 9b9fd16
@wdavidw authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 lib/csv.js
View
21 lib/csv.js
@@ -75,10 +75,10 @@ module.exports = function(){
if( csv.writeOptions.lineBreaks === null ){
csv.writeOptions.lineBreaks = "\r\n";
}
- data.forEach(function(line){
- state.line = line;
+ for(var i=0; i<data.length; i++){
+ state.line = data[i];
flush();
- })
+ }
}else{
try{
parse(data);
@@ -330,9 +330,10 @@ module.exports = function(){
return;
}
var line = {};
- csv.readOptions.columns.forEach(function(column, i){
+ for(var i=0; i<csv.readOptions.columns.length; i++){
+ var column = csv.readOptions.columns[i];
line[column] = state.line[i]||null;
- })
+ }
state.line = line;
line = null;
}
@@ -373,9 +374,10 @@ module.exports = function(){
var columns = csv.writeOptions.columns || csv.readOptions.columns;
var _line = [];
if(columns){
- columns.forEach(function(column, i){
+ for(var i=0; i<columns.length; i++){
+ var column = columns[i];
_line[i] = (typeof line[column] === 'undefined' || line[column] === null) ? '' : line[column];
- })
+ }
}else{
for(var column in line){
_line.push(line[column]);
@@ -390,7 +392,8 @@ module.exports = function(){
}
if(line instanceof Array){
var newLine = state.countWriten ? csv.writeOptions.lineBreaks || "\r" : '';
- line.forEach(function(field,i){
+ for(var i=0; i<line.length; i++){
+ var field = line[i];
if(typeof field === 'string'){
// fine 99% of the cases, keep going
}else if(typeof field === 'number'){
@@ -421,7 +424,7 @@ module.exports = function(){
if(i!==line.length-1){
newLine += csv.writeOptions.delimiter || csv.readOptions.delimiter;
}
- });
+ }
line = newLine;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.