Permalink
Browse files

Fixed error in filter sample

  • Loading branch information...
Qard committed Feb 16, 2012
1 parent 2aef35a commit 9be0538acaf5bebf7c04917a538f5047d427ba19
Showing with 19 additions and 21 deletions.
  1. +19 −21 README.md
View
@@ -70,29 +70,27 @@ or
// Let's try a csv-to-json filter
Crsh.addFilter('csv', function () {
var csv = require('csv')
- return function () {
- this.addType('json', 'csv')
-
- return function (data, next) {
- var pattern = /(?:^|,)("(?:[^"]+)*"|[^,]*)/g
- , lines = data.split("\n")
- , keys = lines.shift()
- .split(pattern)
- .map(function (key) {
- return key.toLowerCase()
- })
- , rows = lines.map(function (line) {
- var res = {}
- line.split(pattern).forEach(function (val, i) {
- if (keys[i]) {
- res[keys[i]] = val.replace(/"/g, '')
- }
- })
- return res
+ this.addType('json', 'csv')
+
+ return function (data, next) {
+ var pattern = /(?:^|,)("(?:[^"]+)*"|[^,]*)/g
+ , lines = data.split("\n")
+ , keys = lines.shift()
+ .split(pattern)
+ .map(function (key) {
+ return key.toLowerCase()
})
+ , rows = lines.map(function (line) {
+ var res = {}
+ line.split(pattern).forEach(function (val, i) {
+ if (keys[i]) {
+ res[keys[i]] = val.replace(/"/g, '')
+ }
+ })
+ return res
+ })
- callback(null, JSON.stringify(rows))
- }
+ callback(null, JSON.stringify(rows))
}
})

0 comments on commit 9be0538

Please sign in to comment.