parse-columns
Advanced tools
Comparing version 1.2.0 to 1.3.0
39
index.js
@@ -67,23 +67,32 @@ 'use strict'; | ||
var transform = opts.transform; | ||
var els; | ||
for (var i = 0, els; i < lines.length; i++) { | ||
els = splitAt(lines[i], splits, {remove: true}); | ||
if (!headers) { | ||
headers = []; | ||
els = splitAt(lines[0], splits, {remove: true}); | ||
if (i !== 0) { | ||
var row = {}; | ||
for (var j = 0, el, header; j < headers.length; j++) { | ||
el = (els[j] || '').trim(); | ||
header = headers[j]; | ||
row[header] = transform ? transform(el, header, j, i) : el; | ||
for (var index = 0, el; index < els.length; ++index) { | ||
el = els[index].trim(); | ||
if (el) { | ||
headers.push(el); | ||
} else { | ||
splits[index - 1] = null; | ||
} | ||
} | ||
rows.push(row); | ||
} else if (!headers) { | ||
headers = []; | ||
splits = splits.filter(Boolean); | ||
} | ||
for (var j2 = 0; j2 < els.length; j2++) { | ||
headers.push(els[j2].trim()); | ||
} | ||
for (var i = 1; i < lines.length; i++) { | ||
els = splitAt(lines[i], splits, {remove: true}); | ||
var row = {}; | ||
for (var j = 0, el, header; j < headers.length; j++) { | ||
el = (els[j] || '').trim(); | ||
header = headers[j]; | ||
row[header] = transform ? transform(el, header, j, i) : el; | ||
} | ||
rows.push(row); | ||
} | ||
@@ -90,0 +99,0 @@ |
{ | ||
"name": "parse-columns", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Parse text columns, like the output of unix commands", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "ava" | ||
}, | ||
@@ -49,4 +49,4 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "^0.2.0" | ||
"ava": "*" | ||
} | ||
} |
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
6208
77