From d8f2138d2a10750362ff45812d418eb81adac904 Mon Sep 17 00:00:00 2001 From: utvk Date: Tue, 8 Jul 2014 23:44:32 +0200 Subject: Bug with header 0 --- README.md | 22 ++++++++++++++++++++++ bin/etatsbasen.js | 6 +++--- lib/etatsbasen.js | 48 ++++++++++++++++++++++++------------------------ test/etatsbasen_test.js | 5 +++-- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 641a7f6..07123c3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ etatsbasen ========== + +Verktøy til å eksportere fra https://github.com/mimesbronn/etatsbasen-data +Lager import som er egnet for import til alaveteli. + +usage +----- + +```sh +$ etatsbasen -h + Usage: etatsbasen [options] + + -c [all|[c1,c2,..]] Categories to include (defaults: `12,14,17,18,27,33,38,66,68,76`) + -f [file] File to read from (defaults: `etatsbasen.csv`) + -o h1[,h2,h3] Include only these headers in output (id or name) + -v Print version. + -h Write this help. +``` + +examples +-------- + +TODO diff --git a/bin/etatsbasen.js b/bin/etatsbasen.js index 0960900..67f8287 100755 --- a/bin/etatsbasen.js +++ b/bin/etatsbasen.js @@ -55,9 +55,9 @@ if (argv.h || fileNotFound()) { console.log([ 'usage: etatsbasen [options]', '', - ' -c [all|[c1,c2,..]] Categories to include (defaults: `' + defaultCategories.join(',') + '`)', - ' -f [file] File to read from (defaults: `etatsbasen.csv`)', - ' -o h1[,h2,h3] Include only these headers in output (id or name)', + ' [-c all|-c c1 -c c2] Categories to include (defaults: `' + defaultCategories.join(',') + '`)', + ' [-f file] File to read from (defaults: `etatsbasen.csv`)', + ' [-o h1 -o h1] Include only these headers in output (id or name)', ' -v Print version.', ' -h Write this help.' ].join('\n')); diff --git a/lib/etatsbasen.js b/lib/etatsbasen.js index cb29076..095904f 100644 --- a/lib/etatsbasen.js +++ b/lib/etatsbasen.js @@ -123,14 +123,12 @@ function removeColumns(csvdata, headerFilter) { if (headerFilter.length) { // expand names to number headerFilter = headerFilter.map(function(item) { - if (item) { - if (null !== item.toString().match(/^\d+$/)) { - return Number(item); - } else if (headernameToIndex[item]) { - return headernameToIndex[item]; - } else { - throw 'Can\'t find header \'' + item + '\'. Possible values: ' + Object.keys(headernameToIndex).join(','); - } + if (null !== item.toString().match(/^\d+$/)) { + return Number(item); + } else if (headernameToIndex[item]) { + return headernameToIndex[item]; + } else { + throw 'Can\'t find header \'' + item + '\'. Possible values: ' + Object.keys(headernameToIndex).join(','); } }); @@ -216,22 +214,24 @@ exports.printCSV = function(cb, options) { } // This is just for fun - csv().from.path(filename, { comment: '#'}).to.array( function(data) { - print( - removeColumns( - addURL( - addTags( - renameHeader( - filter(data, - options.categories - ) - ) - ) - ), options.headers - ) - ); - cb(); - } ); + csv().from.path(filename, + { comment: '#'}).to.array( function(data) { + print( + removeColumns( + addURL( + addTags( + renameHeader( + filter(data, + options.categories + ) + ) + ) + ), + options.headers + ) + ); + cb(); + } ); return true; }; diff --git a/test/etatsbasen_test.js b/test/etatsbasen_test.js index 6f42db7..af66789 100644 --- a/test/etatsbasen_test.js +++ b/test/etatsbasen_test.js @@ -78,17 +78,18 @@ exports.etatsbasen = { 'filter headers': function(test) { var oldLogger = console.log; console.log = function(str) { - test.expect(5); + test.expect(6); test.ok(str.match(/.*request\_email.*/), 'Can\'t find filtered header email'); test.equal(str.split('\n').length, 10); test.ok(!str.match(/\,\,/), 'Found empty entries (WARNING: suspect test)'); test.ok(str.match(/.*name\.nn.*/, 'Missing name.nn header')); + test.ok(str.match(/^\#id/, 'Missing id header')); }; etatsbasen.printCSV(function(err) { console.log = oldLogger; test.ok(!err); test.done(); - }, { filename: 'fixtures/2.csv', headers: ['request_email', 3] }); + }, { filename: 'fixtures/2.csv', headers: ['request_email', 3, 0] }); } } }; -- cgit v1.2.3