Comparing version 0.1.14 to 0.2.0
@@ -1,1 +0,1 @@ | ||
var version = "0.1.14"; export * from "../index"; export {version}; | ||
var version = "0.2.0"; export * from "../index"; export {version}; |
@@ -7,6 +7,2 @@ (function (global, factory) { | ||
function dsv(delimiter) { | ||
return new Dsv(delimiter); | ||
} | ||
function objectConverter(columns) { | ||
@@ -41,8 +37,8 @@ return new Function("d", "return {" + columns.map(function(name, i) { | ||
function Dsv(delimiter) { | ||
function dsv(delimiter) { | ||
var reFormat = new RegExp("[\"" + delimiter + "\n]"), | ||
delimiterCode = delimiter.charCodeAt(0); | ||
this.parse = function(text, f) { | ||
var convert, columns, rows = this.parseRows(text, function(row, i) { | ||
function parse(text, f) { | ||
var convert, columns, rows = parseRows(text, function(row, i) { | ||
if (convert) return convert(row, i - 1); | ||
@@ -53,5 +49,5 @@ columns = row, convert = f ? customConverter(row, f) : objectConverter(row); | ||
return rows; | ||
}; | ||
} | ||
this.parseRows = function(text, f) { | ||
function parseRows(text, f) { | ||
var EOL = {}, // sentinel value for end-of-line | ||
@@ -118,3 +114,3 @@ EOF = {}, // sentinel value for end-of-file | ||
this.format = function(rows, columns) { | ||
function format(rows, columns) { | ||
if (columns == null) columns = inferColumns(rows); | ||
@@ -126,7 +122,7 @@ return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) { | ||
})).join("\n"); | ||
}; | ||
} | ||
this.formatRows = function(rows) { | ||
function formatRows(rows) { | ||
return rows.map(formatRow).join("\n"); | ||
}; | ||
} | ||
@@ -140,16 +136,38 @@ function formatRow(row) { | ||
} | ||
return { | ||
parse: parse, | ||
parseRows: parseRows, | ||
format: format, | ||
formatRows: formatRows | ||
}; | ||
} | ||
dsv.prototype = Dsv.prototype; | ||
var csv = dsv(","); | ||
var csv = dsv(","); | ||
var csvParse = csv.parse; | ||
var csvParseRows = csv.parseRows; | ||
var csvFormat = csv.format; | ||
var csvFormatRows = csv.formatRows; | ||
var tsv = dsv("\t"); | ||
var version = "0.1.14"; | ||
var tsvParse = tsv.parse; | ||
var tsvParseRows = tsv.parseRows; | ||
var tsvFormat = tsv.format; | ||
var tsvFormatRows = tsv.formatRows; | ||
var version = "0.2.0"; | ||
exports.version = version; | ||
exports.dsv = dsv; | ||
exports.csv = csv; | ||
exports.tsv = tsv; | ||
exports.csvParse = csvParse; | ||
exports.csvParseRows = csvParseRows; | ||
exports.csvFormat = csvFormat; | ||
exports.csvFormatRows = csvFormatRows; | ||
exports.tsvParse = tsvParse; | ||
exports.tsvParseRows = tsvParseRows; | ||
exports.tsvFormat = tsvFormat; | ||
exports.tsvFormatRows = tsvFormatRows; | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.d3_dsv={})}(this,function(n){"use strict";function r(n){return new i(n)}function t(n){return new Function("d","return {"+n.map(function(n,r){return JSON.stringify(n)+": d["+r+"]"}).join(",")+"}")}function e(n,r){var e=t(n);return function(t,o){return r(e(t),o,n)}}function o(n){var r=Object.create(null),t=[];return n.forEach(function(n){for(var e in n)e in r||t.push(r[e]=e)}),t}function i(n){function r(r){return r.map(i).join(n)}function i(n){return u.test(n)?'"'+n.replace(/\"/g,'""')+'"':n}var u=new RegExp('["'+n+"\n]"),c=n.charCodeAt(0);this.parse=function(n,r){var o,i,u=this.parseRows(n,function(n,u){return o?o(n,u-1):(i=n,void(o=r?e(n,r):t(n)))});return u.columns=i,u},this.parseRows=function(n,r){function t(){if(s>=a)return u;if(o)return o=!1,i;var r,t=s;if(34===n.charCodeAt(t)){for(var e=t;e++<a;)if(34===n.charCodeAt(e)){if(34!==n.charCodeAt(e+1))break;++e}return s=e+2,r=n.charCodeAt(e+1),13===r?(o=!0,10===n.charCodeAt(e+2)&&++s):10===r&&(o=!0),n.slice(t+1,e).replace(/""/g,'"')}for(;a>s;){var f=1;if(r=n.charCodeAt(s++),10===r)o=!0;else if(13===r)o=!0,10===n.charCodeAt(s)&&(++s,++f);else if(r!==c)continue;return n.slice(t,s-f)}return n.slice(t)}for(var e,o,i={},u={},f=[],a=n.length,s=0,p=0;(e=t())!==u;){for(var d=[];e!==i&&e!==u;)d.push(e),e=t();r&&null==(d=r(d,p++))||f.push(d)}return f},this.format=function(r,t){return null==t&&(t=o(r)),[t.map(i).join(n)].concat(r.map(function(r){return t.map(function(n){return i(r[n])}).join(n)})).join("\n")},this.formatRows=function(n){return n.map(r).join("\n")}}r.prototype=i.prototype;var u=r(","),c=r(" "),f="0.1.14";n.version=f,n.dsv=r,n.csv=u,n.tsv=c}); | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(r.d3_dsv={})}(this,function(r){"use strict";function n(r){return new Function("d","return {"+r.map(function(r,n){return JSON.stringify(r)+": d["+n+"]"}).join(",")+"}")}function t(r,t){var e=n(r);return function(n,o){return t(e(n),o,r)}}function e(r){var n=Object.create(null),t=[];return r.forEach(function(r){for(var e in r)e in n||t.push(n[e]=e)}),t}function o(r){function o(r,e){var o,a,i=u(r,function(r,u){return o?o(r,u-1):(a=r,void(o=e?t(r,e):n(r)))});return i.columns=a,i}function u(r,n){function t(){if(s>=f)return a;if(o)return o=!1,u;var n,t=s;if(34===r.charCodeAt(t)){for(var e=t;e++<f;)if(34===r.charCodeAt(e)){if(34!==r.charCodeAt(e+1))break;++e}return s=e+2,n=r.charCodeAt(e+1),13===n?(o=!0,10===r.charCodeAt(e+2)&&++s):10===n&&(o=!0),r.slice(t+1,e).replace(/""/g,'"')}for(;f>s;){var i=1;if(n=r.charCodeAt(s++),10===n)o=!0;else if(13===n)o=!0,10===r.charCodeAt(s)&&(++s,++i);else if(n!==p)continue;return r.slice(t,s-i)}return r.slice(t)}for(var e,o,u={},a={},i=[],f=r.length,s=0,c=0;(e=t())!==a;){for(var v=[];e!==u&&e!==a;)v.push(e),e=t();n&&null==(v=n(v,c++))||i.push(v)}return i}function a(n,t){return null==t&&(t=e(n)),[t.map(s).join(r)].concat(n.map(function(n){return t.map(function(r){return s(n[r])}).join(r)})).join("\n")}function i(r){return r.map(f).join("\n")}function f(n){return n.map(s).join(r)}function s(r){return c.test(r)?'"'+r.replace(/\"/g,'""')+'"':r}var c=new RegExp('["'+r+"\n]"),p=r.charCodeAt(0);return{parse:o,parseRows:u,format:a,formatRows:i}}var u=o(","),a=u.parse,i=u.parseRows,f=u.format,s=u.formatRows,c=o(" "),p=c.parse,v=c.parseRows,d=c.format,m=c.formatRows,l="0.2.0";r.version=l,r.dsv=o,r.csvParse=a,r.csvParseRows=i,r.csvFormat=f,r.csvFormatRows=s,r.tsvParse=p,r.tsvParseRows=v,r.tsvFormat=d,r.tsvFormatRows=m}); |
@@ -1,4 +0,3 @@ | ||
import dsv from "./src/dsv"; | ||
export {dsv}; | ||
export var csv = dsv(","); | ||
export var tsv = dsv("\t"); | ||
export {default as dsv} from "./src/dsv"; | ||
export {csvParse, csvParseRows, csvFormat, csvFormatRows} from "./src/csv"; | ||
export {tsvParse, tsvParseRows, tsvFormat, tsvFormatRows} from "./src/tsv"; |
{ | ||
"name": "d3-dsv", | ||
"version": "0.1.14", | ||
"version": "0.2.0", | ||
"description": "A parser and formatter for delimiter-separated values, such as CSV and TSV", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
"prepublish": "npm run test && uglifyjs build/d3-dsv.js -c -m -o build/d3-dsv.min.js && rm -f build/d3-dsv.zip && zip -j build/d3-dsv.zip -- LICENSE README.md build/d3-dsv.js build/d3-dsv.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-dsv.js ../d3.github.com/d3-dsv.v0.1.js && cp build/d3-dsv.min.js ../d3.github.com/d3-dsv.v0.1.min.js && cd ../d3.github.com && git add d3-dsv.v0.1.js d3-dsv.v0.1.min.js && git commit -m \"d3-dsv ${VERSION}\" && git push" | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-dsv.js ../d3.github.com/d3-dsv.v0.2.js && cp build/d3-dsv.min.js ../d3.github.com/d3-dsv.v0.2.min.js && cd ../d3.github.com && git add d3-dsv.v0.2.js d3-dsv.v0.2.min.js && git commit -m \"d3-dsv ${VERSION}\" && git push" | ||
}, | ||
@@ -41,3 +41,6 @@ "devDependencies": { | ||
"uglify-js": "2" | ||
}, | ||
"dependencies": { | ||
"rw": "~1.1.1" | ||
} | ||
} |
@@ -5,8 +5,22 @@ # d3-dsv | ||
[Comma](#csv) and [tab](#tsv) delimiters are built-in. To use a different delimiter, such as “|” for pipe-separated values, use the [dsv constructor](#dsv): | ||
Comma (CSV) and tab (TSV) delimiters are built-in. For example, to parse: | ||
```js | ||
d3.csvParse("foo,bar\n1,2"); // [{foo: "1", bar: "2"}, columns: ["foo", "bar"]] | ||
d3.tsvParse("foo\tbar\n1\t2"); // [{foo: "1", bar: "2"}, columns: ["foo", "bar"]] | ||
``` | ||
Or to format: | ||
```js | ||
d3.csvFormat([{foo: "1", bar: "2"}]); // "foo,bar\n1,2" | ||
d3.tsvFormat([{foo: "1", bar: "2"}]); // "foo\tbar\n1\t2" | ||
``` | ||
To use a different delimiter, such as “|” for pipe-separated values, use the [dsv constructor](#dsv): | ||
```js | ||
var psv = d3.dsv("|"); | ||
console.log(psv.parse("foo|bar\n1|2")); // [{foo: "1", bar: "2"}] | ||
console.log(psv.parse("foo|bar\n1|2")); // [{foo: "1", bar: "2"}, columns: ["foo", "bar"]] | ||
``` | ||
@@ -21,3 +35,3 @@ | ||
```html | ||
<script src="https://d3js.org/d3-dsv.v0.1.min.js"></script> | ||
<script src="https://d3js.org/d3-dsv.v0.2.min.js"></script> | ||
``` | ||
@@ -29,2 +43,34 @@ | ||
<a name="csvParse" href="#csvParse">#</a> d3.<b>csvParse</b>(<i>string</i>[, <i>row</i>]) | ||
Equivalent to [dsv](#dsv)(",").[parse](#dsv_parse). | ||
<a name="csvParseRows" href="#csvParseRows">#</a> d3.<b>csvParseRows</b>(<i>string</i>[, <i>row</i>]) | ||
Equivalent to [dsv](#dsv)(",").[parseRows](#dsv_parseRows). | ||
<a name="csvFormat" href="#csvFormat">#</a> d3.<b>csvFormat</b>(<i>rows</i>[, <i>columns</i>]) | ||
Equivalent to [dsv](#dsv)(",").[format](#dsv_format). | ||
<a name="csvFormatRows" href="#csvFormatRows">#</a> d3.<b>csvFormatRows</b>(<i>rows</i>) | ||
Equivalent to [dsv](#dsv)(",").[formatRows](#dsv_formatRows). | ||
<a name="tsvParse" href="#tsvParse">#</a> d3.<b>tsvParse</b>(<i>string</i>[, <i>row</i>]) | ||
Equivalent to [dsv](#dsv)("\t").[parse](#dsv_parse). | ||
<a name="tsvParseRows" href="#tsvParseRows">#</a> d3.<b>tsvParseRows</b>(<i>string</i>[, <i>row</i>]) | ||
Equivalent to [dsv](#dsv)("\t").[parseRows](#dsv_parseRows). | ||
<a name="tsvFormat" href="#tsvFormat">#</a> d3.<b>tsvFormat</b>(<i>rows</i>[, <i>columns</i>]) | ||
Equivalent to [dsv](#dsv)("\t").[format](#dsv_format). | ||
<a name="tsvFormatRows" href="#tsvFormatRows">#</a> d3.<b>tsvFormatRows</b>(<i>rows</i>) | ||
Equivalent to [dsv](#dsv)("\t").[formatRows](#dsv_formatRows). | ||
<a name="dsv" href="#dsv">#</a> d3.<b>dsv</b>(<i>delimiter</i>) | ||
@@ -64,3 +110,3 @@ | ||
```js | ||
var data = d3.csv.parse(string, function(d) { | ||
var data = d3.csvParse(string, function(d) { | ||
return { | ||
@@ -100,3 +146,3 @@ year: new Date(+d.Year, 0, 1), // convert "Year" column to Date | ||
```js | ||
var data = d3.csv.parseRows(string, function(d, i) { | ||
var data = d3.csvParseRows(string, function(d, i) { | ||
return { | ||
@@ -120,3 +166,3 @@ year: new Date(+d[0], 0, 1), // convert first colum column to Date | ||
```js | ||
var string = d3.csv.format(data, ["year", "make", "model", "length"]); | ||
var string = d3.csvFormat(data, ["year", "make", "model", "length"]); | ||
``` | ||
@@ -133,3 +179,3 @@ | ||
```js | ||
var string = d3.csv.formatRows(data.map(function(d, i) { | ||
var string = d3.csvFormatRows(data.map(function(d, i) { | ||
return [ | ||
@@ -147,3 +193,3 @@ d.year.getFullYear(), // Assuming d.year is a Date object. | ||
```js | ||
var string = d3.csv.formatRows([[ | ||
var string = d3.csvFormatRows([[ | ||
"year", | ||
@@ -163,18 +209,2 @@ "make", | ||
<a name="csv" href="#csv">#</a> d3.<b>csv</b> | ||
A parser and formatter for comma-separated values (CSV), defined as: | ||
```js | ||
var csv = d3.dsv(","); | ||
``` | ||
<a name="tsv" href="#tsv">#</a> d3.<b>tsv</b> | ||
A parser and formatter for tab-separated values (TSV), defined as: | ||
```js | ||
var tsv = d3.dsv("\t"); | ||
``` | ||
### Content Security Policy | ||
@@ -198,3 +228,4 @@ | ||
csv2json < file.csv > file.json | ||
csv2json - < file.csv > file.json | ||
cat file.csv | csv2json - > file.json | ||
``` |
@@ -1,5 +0,1 @@ | ||
function dsv(delimiter) { | ||
return new Dsv(delimiter); | ||
} | ||
function objectConverter(columns) { | ||
@@ -34,8 +30,8 @@ return new Function("d", "return {" + columns.map(function(name, i) { | ||
function Dsv(delimiter) { | ||
export default function(delimiter) { | ||
var reFormat = new RegExp("[\"" + delimiter + "\n]"), | ||
delimiterCode = delimiter.charCodeAt(0); | ||
this.parse = function(text, f) { | ||
var convert, columns, rows = this.parseRows(text, function(row, i) { | ||
function parse(text, f) { | ||
var convert, columns, rows = parseRows(text, function(row, i) { | ||
if (convert) return convert(row, i - 1); | ||
@@ -46,5 +42,5 @@ columns = row, convert = f ? customConverter(row, f) : objectConverter(row); | ||
return rows; | ||
}; | ||
} | ||
this.parseRows = function(text, f) { | ||
function parseRows(text, f) { | ||
var EOL = {}, // sentinel value for end-of-line | ||
@@ -111,3 +107,3 @@ EOF = {}, // sentinel value for end-of-file | ||
this.format = function(rows, columns) { | ||
function format(rows, columns) { | ||
if (columns == null) columns = inferColumns(rows); | ||
@@ -119,7 +115,7 @@ return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) { | ||
})).join("\n"); | ||
}; | ||
} | ||
this.formatRows = function(rows) { | ||
function formatRows(rows) { | ||
return rows.map(formatRow).join("\n"); | ||
}; | ||
} | ||
@@ -133,6 +129,9 @@ function formatRow(row) { | ||
} | ||
return { | ||
parse: parse, | ||
parseRows: parseRows, | ||
format: format, | ||
formatRows: formatRows | ||
}; | ||
} | ||
dsv.prototype = Dsv.prototype; | ||
export default dsv; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
26203
16
269
222
0
1