bank-csv-importer
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -24,3 +24,3 @@ { | ||
"type": "module", | ||
"version": "1.0.1" | ||
"version": "1.0.2" | ||
} |
@@ -18,2 +18,6 @@ The goal of this project is to be able to import any exported CSV (comma or semi colon separated) data from any bank account into a standard format, with everything such as CSV separator and column headings auto-detected. It's a work in progress. Please try it, and if some CSV file doesn't work for you, let me know. | ||
typedRecords : [], // same as above but with some fields converted to Date or Number where possible | ||
numColumns, | ||
// For each column, whether all the typedRecords in that column are of the same type | ||
// Will be null if there are mixed types | ||
entireColumnTypes : ["String", "Number", "Date", null], | ||
headerGuesses : { // if any of these could not be guessed it will be null | ||
@@ -20,0 +24,0 @@ date : 0, |
@@ -145,2 +145,14 @@ import {findTypes} from "./parseTypes.js"; | ||
function getEntireColumnTypes(typedRecords) { | ||
const numColumns = typedRecords[0].length; | ||
return new Array(numColumns).fill(null).map((_columnType, i) => { | ||
const firstValueType = typedRecords[0][i].constructor.name; | ||
// Check if each value is of the same type | ||
return typedRecords.every(row => row[i].constructor.name === firstValueType) ? | ||
firstValueType : null; | ||
}); | ||
} | ||
export default function(data, options = {headerKeywordMatching : true}) { | ||
@@ -228,4 +240,5 @@ let lines = getLines(data); | ||
numColumns : longestFieldCount, | ||
entireColumnTypes : getEntireColumnTypes(typedRecords), | ||
headerGuesses | ||
}; | ||
} |
12
test.js
@@ -105,12 +105,12 @@ import fs from "fs"; | ||
// Compare if entire columns match the type given by expected.entireRowTypes array | ||
// Compare if entire columns match the type given by expected.entireColumnTypes array | ||
result.typedRecords.forEach((row, index) => { | ||
for (let i = 0; i < expected.entireRowTypes.length; i ++) { | ||
if (expected.entireRowTypes[i] === null) { | ||
for (let i = 0; i < expected.entireColumnTypes.length; i ++) { | ||
if (expected.entireColumnTypes[i] === null) { | ||
continue; // skip null | ||
} | ||
if (row[i].constructor.name !== expected.entireRowTypes[i]) { | ||
errors.push(`Expected entire row type mismatch: ${testDataPath}: ` | ||
+ "Expected " + expected.entireRowTypes[i] + " but got: " | ||
if (row[i].constructor.name !== expected.entireColumnTypes[i]) { | ||
errors.push(`Expected entire column type mismatch: ${testDataPath}: ` | ||
+ "Expected " + expected.entireColumnTypes[i] + " but got: " | ||
+ `"${row[i]}" (${row[i].constructor.name})` | ||
@@ -117,0 +117,0 @@ + `\n Column: ${i}` |
{ | ||
"entireRowTypes" : [null, "Date", null, "Number", null, null], | ||
"entireColumnTypes" : [null, "Date", null, "Number", null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
{ | ||
"entireRowTypes" : [null, "Date", null, "Number", null, null], | ||
"entireColumnTypes" : [null, "Date", null, "Number", null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
{ | ||
"entireRowTypes" : [null, "Date", null, "Number", null, null, null], | ||
"entireColumnTypes" : [null, "Date", null, "Number", null, null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
{ | ||
"entireRowTypes" : ["Date", null, null, "Number"], | ||
"entireColumnTypes" : ["Date", null, null, "Number"], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 0, |
{ | ||
"entireRowTypes" : ["Date", null, null, "Number", "Number", null, null], | ||
"entireColumnTypes" : ["Date", null, null, "Number", "Number", null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 0, |
{ | ||
"entireRowTypes" : [null, "Date", null, "Number", null, null], | ||
"entireColumnTypes" : [null, "Date", null, "Number", null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
@@ -95,2 +95,10 @@ { | ||
"numColumns": 6, | ||
"entireColumnTypes": [ | ||
null, | ||
"Date", | ||
"String", | ||
"Number", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -97,0 +105,0 @@ "date": 1, |
@@ -111,2 +111,10 @@ { | ||
"numColumns": 6, | ||
"entireColumnTypes": [ | ||
"String", | ||
"Date", | ||
"String", | ||
"Number", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -113,0 +121,0 @@ "date": 1, |
@@ -142,2 +142,11 @@ { | ||
"numColumns": 7, | ||
"entireColumnTypes": [ | ||
"Number", | ||
"Date", | ||
"String", | ||
"Number", | ||
"String", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -144,0 +153,0 @@ "date": 1, |
@@ -145,2 +145,8 @@ { | ||
"numColumns": 4, | ||
"entireColumnTypes": [ | ||
"Date", | ||
"String", | ||
"String", | ||
"Number" | ||
], | ||
"headerGuesses": { | ||
@@ -147,0 +153,0 @@ "date": 0, |
@@ -196,2 +196,11 @@ { | ||
"numColumns": 7, | ||
"entireColumnTypes": [ | ||
"Date", | ||
"String", | ||
"String", | ||
"Number", | ||
"Number", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -198,0 +207,0 @@ "date": 0, |
@@ -88,2 +88,10 @@ { | ||
"numColumns": 6, | ||
"entireColumnTypes": [ | ||
null, | ||
"Date", | ||
"String", | ||
"Number", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -90,0 +98,0 @@ "date": 1, |
@@ -480,2 +480,45 @@ { | ||
"numColumns": 41, | ||
"entireColumnTypes": [ | ||
"Date", | ||
"Date", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"Number", | ||
"Number", | ||
"Number", | ||
"String", | ||
"String", | ||
null, | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"Number", | ||
"String", | ||
"Number", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
null, | ||
"String", | ||
"Number", | ||
"String", | ||
"Number", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -482,0 +525,0 @@ "date": 0, |
@@ -163,2 +163,14 @@ { | ||
"numColumns": 10, | ||
"entireColumnTypes": [ | ||
"Date", | ||
"Date", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"Number", | ||
"String", | ||
"Number" | ||
], | ||
"headerGuesses": { | ||
@@ -165,0 +177,0 @@ "date": 0, |
@@ -24,2 +24,10 @@ { | ||
"numColumns": 6, | ||
"entireColumnTypes": [ | ||
"String", | ||
"Date", | ||
"String", | ||
"Number", | ||
"String", | ||
"String" | ||
], | ||
"headerGuesses": { | ||
@@ -26,0 +34,0 @@ "date": 1, |
@@ -322,2 +322,23 @@ { | ||
"numColumns": 19, | ||
"entireColumnTypes": [ | ||
"String", | ||
"Date", | ||
"Number", | ||
"String", | ||
"String", | ||
"String", | ||
"Number", | ||
"String", | ||
"String", | ||
null, | ||
"String", | ||
"String", | ||
null, | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"String", | ||
"Number" | ||
], | ||
"headerGuesses": { | ||
@@ -324,0 +345,0 @@ "date": 1, |
{ | ||
"entireRowTypes" : [ | ||
"entireColumnTypes" : [ | ||
"Date", null, null, null, null, null, null, "Number", "Number", "Number", null, null, null, null, null, null, null, "Number", null, "Number", null, null, null, null, null, null, null, | ||
@@ -4,0 +4,0 @@ "Number", null, "Number", null, null, null, null, null, null, null, null, null, null, null |
{ | ||
"entireRowTypes" : ["Date", null, null, null, null, null, null, "Number", null, "Number"], | ||
"entireColumnTypes" : ["Date", null, null, null, null, null, null, "Number", null, "Number"], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 0, |
{ | ||
"entireRowTypes" : [null, "Date", null, "Number", null, null], | ||
"entireColumnTypes" : [null, "Date", null, "Number", null, null], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
{ | ||
"entireRowTypes" : [null, "Date", "Number", null, null, null, "Number", null, null, null, null, null, null, null, null, null, null, null, "Number"], | ||
"entireColumnTypes" : [null, "Date", "Number", null, null, null, "Number", null, null, null, null, null, null, null, null, null, null, null, "Number"], | ||
"headerGuesses" : { | ||
@@ -4,0 +4,0 @@ "date" : 1, |
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
67723
3395
41