furkot-driving-log
Advanced tools
Comparing version 2.0.0 to 2.0.1
2.0.1 / 2017-09-02 | ||
================== | ||
* implement generator as a Readable stream | ||
2.0.0 / 2017-07-18 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -0,1 +1,2 @@ | ||
var Readable = require('stream').Readable; | ||
var format = require('./format'); | ||
@@ -12,8 +13,8 @@ | ||
function write(out, line) { | ||
line = line.map(function(item) { | ||
if(typeof item === 'number') { | ||
function prepare(line) { | ||
return line.map(function(item) { | ||
if (typeof item === 'number') { | ||
return '' + item; | ||
} | ||
if(typeof item === 'string') { | ||
if (typeof item === 'string') { | ||
// quote strings | ||
@@ -24,4 +25,3 @@ return '"' + item.replace(/"/g, '""') + '"'; | ||
return ''; | ||
}).join(','); | ||
out.write(line + '\n'); | ||
}).join(',') + '\n'; | ||
} | ||
@@ -58,6 +58,12 @@ | ||
write(out, header); | ||
var steps = options.routes[0].points; | ||
options.routes[0].points.forEach(function (step, i, steps) { | ||
var line = [], next = steps[i + 1], travel; | ||
function getLine(i) { | ||
if (i < 0) { | ||
return prepare(header); | ||
} | ||
var step = steps[i]; | ||
var next = steps[i + 1]; | ||
if (!next) { | ||
@@ -72,2 +78,3 @@ return; | ||
var travel; | ||
if (mode === next.mode || next.mode === undefined) { | ||
@@ -79,5 +86,8 @@ travel = next; | ||
} | ||
totals.driving += travel.driving; | ||
totals.distance += travel.distance; | ||
var line = []; | ||
line.push(step.name); | ||
@@ -97,5 +107,23 @@ line.push(step.address); | ||
write(out, line); | ||
return prepare(line); | ||
} | ||
var maxLine = steps.length - 1; | ||
var currentLine = -1; | ||
var stream = new Readable({ | ||
read: function read() { | ||
while (currentLine < maxLine) { | ||
if (!this.push(getLine(currentLine++))) { | ||
break; | ||
} | ||
} | ||
if (currentLine >= maxLine) { | ||
this.push(null); | ||
} | ||
} | ||
}); | ||
out.end(); | ||
stream.pipe(out); | ||
} |
{ | ||
"name": "furkot-driving-log", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Generate CSV driving log from Furkot trip data.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://trips.furkot.com", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5710
146