Comparing version 0.0.1 to 0.0.2
@@ -11,14 +11,17 @@ "use strict"; | ||
const csv = require('../csv'); | ||
const linq = require('../linq'); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = function run([filename, options]) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let maxSize = 0; | ||
let maxSizes = []; | ||
let maxLineNumberSize = 1; | ||
yield csv.read(filename, (line, linenumber) => { | ||
const values = csv.parse(line, options.delimiter); | ||
maxSize = linq.max(values, val => val.length); | ||
maxSizes = values.map((val, i) => { | ||
return (maxSizes[i] || -1) > val.length ? maxSizes[i] : val.length; | ||
}); | ||
maxLineNumberSize = linenumber; | ||
}); | ||
maxLineNumberSize = `${maxLineNumberSize}`.length; | ||
if (options.lineNumbers) { | ||
maxSizes.unshift(`${maxLineNumberSize}`.length); | ||
} | ||
yield csv.read(filename, (line, lineNumber) => { | ||
@@ -30,4 +33,3 @@ const values = csv.parse(line, options.delimiter); | ||
console.log(values.map((val, i) => { | ||
let size = options.lineNumbers && !i ? maxLineNumberSize : maxSize; | ||
const complement = size - val.length; | ||
const complement = maxSizes[i] - val.length; | ||
return ` ${val}${' '.repeat(complement)} `; | ||
@@ -34,0 +36,0 @@ }).join('|')); |
{ | ||
"name": "dcsv", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Do things with csv files.", | ||
@@ -5,0 +5,0 @@ "main": "built/ahgora-service.js", |
8048
177