Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dsv-dataset

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dsv-dataset - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

16

dsv-dataset.js

@@ -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++){

@@ -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 @@ },

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);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc