connect-csv
Advanced tools
Comparing version
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
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
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
0.88%92
5.75%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed