connect-csv
Advanced tools
Comparing version 0.0.1 to 0.0.2
49
index.js
(function(){ | ||
var connect, CSV, EnumHeaderConfig, DefaultHeaderConfig, split$ = ''.split, replace$ = ''.replace; | ||
connect = require('connect'); | ||
CSV = require('csv-string'); | ||
CSV = require('csv'); | ||
EnumHeaderConfig = ['strict', 'guess', 'present', 'absent']; | ||
@@ -46,27 +46,32 @@ DefaultHeaderConfig = 'strict'; | ||
x$.on('end', function(){ | ||
var res$, i$, to$, i, e; | ||
var e; | ||
try { | ||
buf = replace$.call(buf, /\n*$/, ''); | ||
req.body = CSV.parse(buf); | ||
if (header === 'guess') { | ||
if (req.body.length && req.body[0].some((function(it){ | ||
return /^[-\d]/.exec(it); | ||
}))) { | ||
header = 'absent'; | ||
} else { | ||
header = 'present'; | ||
return CSV().from(buf, { | ||
delimiter: ',' | ||
}).to.array(function(body){ | ||
var res$, i$, to$, i; | ||
req.body = body; | ||
if (header === 'guess') { | ||
if (req.body.length && req.body[0].some((function(it){ | ||
return /^[-\d]/.exec(it); | ||
}))) { | ||
header = 'absent'; | ||
} else { | ||
header = 'present'; | ||
} | ||
} | ||
} | ||
if (header === 'absent' && req.body.length) { | ||
res$ = []; | ||
for (i$ = 0, to$ = req.body[0].length; i$ < to$; ++i$) { | ||
i = i$; | ||
res$.push("_" + i); | ||
if (header === 'absent' && req.body.length) { | ||
res$ = []; | ||
for (i$ = 0, to$ = req.body[0].length; i$ < to$; ++i$) { | ||
i = i$; | ||
res$.push("_" + i); | ||
} | ||
header = res$; | ||
} | ||
header = res$; | ||
} | ||
if (Array.isArray(header)) { | ||
req.body.unshift(header); | ||
} | ||
return next(); | ||
if (Array.isArray(header)) { | ||
req.body.unshift(header); | ||
} | ||
return next(); | ||
}); | ||
} catch (e$) { | ||
@@ -73,0 +78,0 @@ e = e$; |
@@ -9,9 +9,4 @@ { | ||
"name": "connect-csv", | ||
"keywords": [ | ||
"connect", | ||
"middleware", | ||
"csv" | ||
], | ||
"description": "Connect middleware for accepting text/csv data type", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "lib/index.js", | ||
@@ -30,3 +25,3 @@ "repository": { | ||
"dependencies": { | ||
"csv-string": "*", | ||
"csv": "*", | ||
"connect": "*" | ||
@@ -33,0 +28,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
7547
92
+ Addedcsv@*
+ Addedcsv@6.3.11(transitive)
+ Addedcsv-generate@4.4.2(transitive)
+ Addedcsv-parse@5.6.0(transitive)
+ Addedcsv-stringify@6.5.2(transitive)
+ Addedstream-transform@3.3.3(transitive)
- Removedcsv-string@*
- Removedcsv-string@4.1.1(transitive)