dsv-dataset
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -152,4 +152,2 @@ (function (global, factory) { | ||
var dsvString = dataset.dsvString; | ||
// Handle the case where `metadata` is not speficied. | ||
@@ -162,10 +160,16 @@ dataset.metadata = dataset.metadata || {}; | ||
// Default to CSV if no delimiter speficied. | ||
var delimiter = metadata.delimiter || ","; | ||
var columnParsers = generateColumnParsers(metadata); | ||
var numColumns = columnParsers.length; | ||
dataset.data = dsv(delimiter).parse(dsvString, function (d){ | ||
var data; | ||
if(dataset.data){ | ||
data = dataset.data; | ||
} else { | ||
// Default to CSV if no delimiter speficied. | ||
data = dsv(metadata.delimiter || ",") | ||
.parse(dataset.dsvString); | ||
} | ||
dataset.data = data.map(function (d){ | ||
// Old school for loop as an optimization. | ||
@@ -172,0 +176,0 @@ for(var i = 0; i < numColumns; i++){ |
16
index.js
@@ -32,4 +32,2 @@ import { dsv } from "d3-dsv"; | ||
var dsvString = dataset.dsvString; | ||
// Handle the case where `metadata` is not speficied. | ||
@@ -42,10 +40,16 @@ dataset.metadata = dataset.metadata || {}; | ||
// Default to CSV if no delimiter speficied. | ||
var delimiter = metadata.delimiter || ","; | ||
var columnParsers = generateColumnParsers(metadata); | ||
var numColumns = columnParsers.length; | ||
dataset.data = dsv(delimiter).parse(dsvString, function (d){ | ||
var data; | ||
if(dataset.data){ | ||
data = dataset.data; | ||
} else { | ||
// Default to CSV if no delimiter speficied. | ||
data = dsv(metadata.delimiter || ",") | ||
.parse(dataset.dsvString); | ||
} | ||
dataset.data = data.map(function (d){ | ||
// Old school for loop as an optimization. | ||
@@ -52,0 +56,0 @@ for(var i = 0; i < numColumns; i++){ |
{ | ||
"name": "dsv-dataset", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A metadata specification and parsing library for data sets.", | ||
@@ -11,3 +11,3 @@ "main": "dsv-dataset.js", | ||
"scripts": { | ||
"pretest": "rollup --format=umd --name dsvDataset --external moment --output dsv-dataset.js index.js", | ||
"pretest": "rollup --format=umd --name dsvDataset --output dsv-dataset.js index.js", | ||
"test": "mocha" | ||
@@ -14,0 +14,0 @@ }, |
29
test.js
var dsvDataset = require("./dsv-dataset.js"); | ||
var assert = require("assert"); | ||
var ChiasmDataset = require("chiasm-dataset"); | ||
var csv = require("d3-dsv").csv; | ||
@@ -166,2 +167,30 @@ describe("dsv-dataset", function () { | ||
}); | ||
it("should accept 'data' argument instead of 'dsvString'", function(done) { | ||
var dataset = dsvDataset.parse({ | ||
data: csv.parse(dsvStrings.iris), | ||
metadata: { | ||
delimiter: ",", | ||
columns: [ | ||
{ name: "sepal_length", type: "number" }, | ||
{ name: "sepal_width", type: "number" }, | ||
{ name: "petal_length", type: "number" }, | ||
{ name: "petal_width", type: "number" }, | ||
{ name: "class", type: "string" } | ||
] | ||
} | ||
}); | ||
var row = dataset.data[0]; | ||
assert.equal(dataset.data.length, dsvStrings.iris.split("\n").length - 1); | ||
assert.equal(typeof row.sepal_length, "number"); | ||
assert.equal(typeof row.sepal_width, "number"); | ||
assert.equal(typeof row.petal_length, "number"); | ||
assert.equal(typeof row.petal_width, "number"); | ||
assert.equal(typeof row.class, "string"); | ||
ChiasmDataset.validate(dataset).then(done, console.log); | ||
}); | ||
}); |
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
24895
426