Comparing version 0.3.9 to 0.3.10
@@ -27,50 +27,2 @@ /** | ||
exports.zip = zip; | ||
function inferColumns(rows) { | ||
var columns = []; | ||
var seen = {}; | ||
rows.forEach(function (row) { | ||
// each object might be a string, array, or object, but only objects matter here. | ||
if (typeof (row) !== 'string' && !Array.isArray(row)) { | ||
Object.keys(row).forEach(function (key) { | ||
// if (row.hasOwnProperty(key)) { | ||
// maybe should also check that row[key] != null | ||
if (!(key in seen)) { | ||
columns.push(key); | ||
seen[key] = 1; | ||
} | ||
// } | ||
}); | ||
} | ||
}); | ||
return columns; | ||
} | ||
exports.inferColumns = inferColumns; | ||
/** | ||
returns a single char code (a byte) denoting the inferred delimiter. | ||
*/ | ||
function inferDelimiter(buffer) { | ||
var counts = {}; | ||
// we look at the first newline or 256 chars, whichever is greater, | ||
// but without going through the whole file | ||
var upto = Math.min(256, buffer.length); | ||
for (var i = 0; i < upto && buffer[i] != 10 && buffer[i] != 13; i++) { | ||
var char_code = buffer[i]; | ||
counts[char_code] = (counts[char_code] || 0) + 1; | ||
} | ||
// we'll go through, prioritizing characters that aren't likely to show | ||
// up unless they are a delimiter. | ||
var candidates = [ | ||
9, | ||
59, | ||
44, | ||
32, | ||
]; | ||
// TODO: make this more robust (that's why I even counted them) | ||
for (var candidate, j = 0; (candidate = candidates[j]); j++) { | ||
if (counts[candidate] > 0) { | ||
return candidate; | ||
} | ||
} | ||
} | ||
exports.inferDelimiter = inferDelimiter; | ||
function commonPrefix(filepaths) { | ||
@@ -77,0 +29,0 @@ var prefix = filepaths[0]; |
{ | ||
"name": "sv", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "Any separated values.", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"mocha": "*", | ||
"typescript": "next" | ||
"typescript": "*" | ||
}, | ||
@@ -33,0 +33,0 @@ "scripts": { |
@@ -17,2 +17,30 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
/** | ||
returns a single char code (a byte) denoting the inferred delimiter. | ||
*/ | ||
function inferDelimiter(buffer) { | ||
var counts = {}; | ||
// we look at the first newline or 256 chars, whichever is greater, | ||
// but without going through the whole file | ||
var upto = Math.min(256, buffer.length); | ||
for (var i = 0; i < upto && buffer[i] != 10 && buffer[i] != 13; i++) { | ||
var char_code = buffer[i]; | ||
counts[char_code] = (counts[char_code] || 0) + 1; | ||
} | ||
// we'll go through, prioritizing characters that aren't likely to show | ||
// up unless they are a delimiter. | ||
var candidates = [ | ||
9, | ||
59, | ||
44, | ||
32, | ||
]; | ||
// TODO: make this more robust (that's why I even counted them) | ||
for (var candidate, j = 0; (candidate = candidates[j]); j++) { | ||
if (counts[candidate] > 0) { | ||
return candidate; | ||
} | ||
} | ||
} | ||
exports.inferDelimiter = inferDelimiter; | ||
/** | ||
- `byteBuffer` is a buffer (of bytes) that have yet to be processed (and sent to output). | ||
@@ -67,3 +95,3 @@ - `cellBuffer` is a list of strings that have yet to be processed (and sent to output). | ||
// should we wait for some minimum amount of data? | ||
this.delimiterByte = common_1.inferDelimiter(buffer); | ||
this.delimiterByte = inferDelimiter(buffer); | ||
} | ||
@@ -70,0 +98,0 @@ var start = 0; |
@@ -17,2 +17,22 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}; | ||
function inferColumns(rows) { | ||
var columns = []; | ||
var seen = {}; | ||
rows.forEach(function (row) { | ||
// each object might be a string, array, or object, but only objects matter here. | ||
if (typeof (row) !== 'string' && !Array.isArray(row)) { | ||
Object.keys(row).forEach(function (key) { | ||
// if (row.hasOwnProperty(key)) { | ||
// maybe should also check that row[key] != null | ||
if (!(key in seen)) { | ||
columns.push(key); | ||
seen[key] = 1; | ||
} | ||
// } | ||
}); | ||
} | ||
}); | ||
return columns; | ||
} | ||
exports.inferColumns = inferColumns; | ||
/** Stringifier class | ||
@@ -103,3 +123,3 @@ new Stringifier(); | ||
// infer columns | ||
this.config.columns = common_1.inferColumns(this.rowBuffer); | ||
this.config.columns = inferColumns(this.rowBuffer); | ||
this.writeObject(this.config.columns); | ||
@@ -106,0 +126,0 @@ } |
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
31283