Comparing version 0.1.12 to 0.1.13
@@ -1,1 +0,1 @@ | ||
var version = "0.1.12"; export * from "../index"; export {version}; | ||
var version = "0.1.13"; export * from "../index"; export {version}; |
@@ -141,3 +141,3 @@ (function (global, factory) { | ||
var version = "0.1.12"; | ||
var version = "0.1.13"; | ||
@@ -144,0 +144,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-dsv",["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=s;if(34===n.charCodeAt(r)){for(var t=r;t++<a;)if(34===n.charCodeAt(t)){if(34!==n.charCodeAt(t+1))break;++t}s=t+2;var e=n.charCodeAt(t+1);return 13===e?(o=!0,10===n.charCodeAt(t+2)&&++s):10===e&&(o=!0),n.slice(r+1,t).replace(/""/g,'"')}for(;a>s;){var e=n.charCodeAt(s++),f=1;if(10===e)o=!0;else if(13===e)o=!0,10===n.charCodeAt(s)&&(++s,++f);else if(e!==c)continue;return n.slice(r,s-f)}return n.slice(r)}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 arguments.length<2&&(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.12";n.version=f,n.dsv=r,n.csv=u,n.tsv=c}); | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-dsv",["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=s;if(34===n.charCodeAt(r)){for(var t=r;t++<a;)if(34===n.charCodeAt(t)){if(34!==n.charCodeAt(t+1))break;++t}s=t+2;var e=n.charCodeAt(t+1);return 13===e?(o=!0,10===n.charCodeAt(t+2)&&++s):10===e&&(o=!0),n.slice(r+1,t).replace(/""/g,'"')}for(;a>s;){var e=n.charCodeAt(s++),f=1;if(10===e)o=!0;else if(13===e)o=!0,10===n.charCodeAt(s)&&(++s,++f);else if(e!==c)continue;return n.slice(r,s-f)}return n.slice(r)}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 arguments.length<2&&(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.13";n.version=f,n.dsv=r,n.csv=u,n.tsv=c}); |
{ | ||
"name": "d3-dsv", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "A parser and formatter for delimiter-separated values, such as CSV and TSV", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# d3-dsv | ||
A parser and formatter for delimiter-separated values, most commonly [comma-separated values](https://en.wikipedia.org/wiki/Comma-separated_values) (CSV) and tab-separated values (TSV). These tabular formats are popular with spreadsheet programs such as Microsoft Excel, and are often more space-efficient than JSON for large datasets. This implementation is based on [RFC 4180](http://tools.ietf.org/html/rfc4180). | ||
This module provides a parser and formatter for delimiter-separated values, most commonly [comma-](https://en.wikipedia.org/wiki/Comma-separated_values) (CSV) or tab-separated values (TSV). These tabular formats are popular with spreadsheet programs such as Microsoft Excel, and are often more space-efficient than JSON. This implementation is based on [RFC 4180](http://tools.ietf.org/html/rfc4180). | ||
Supports [comma-](#csv) and [tab-](#tsv)separated values out of the box. To define a new delimiter, such as `"|"` for pipe-separated values, use the [dsv constructor](#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): | ||
```js | ||
var psv = dsv("|"); | ||
var psv = d3_dsv.dsv("|"); | ||
@@ -13,9 +13,17 @@ console.log(psv.parse("foo|bar\n1|2")); // [{foo: "1", bar: "2"}] | ||
For easy loading of DSV files in a browser, see [d3-request](https://github.com/d3/d3-request)’s [csv](https://github.com/d3/d3-request#csv) and [tsv](https://github.com/d3/d3-request#tsv) methods. | ||
## Installing | ||
If you use NPM, `npm install d3-dsv`. Otherwise, download the [latest release](https://github.com/d3/d3-dsv/releases/latest). | ||
If you use NPM, `npm install d3-dsv`. Otherwise, download the [latest release](https://github.com/d3/d3-dsv/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org): | ||
```html | ||
<script src="https://d3js.org/d3-dsv.v0.1.min.js"></script> | ||
``` | ||
In a vanilla environment, a `d3_dsv` global is exported. [Try d3-dsv in your browser.](https://tonicdev.com/npm/d3-dsv) | ||
## API Reference | ||
<a name="dsv" href="#dsv">#</a> <b>dsv</b>(<i>delimiter</i>) | ||
<a name="dsv" href="#dsv">#</a> d3_dsv.<b>dsv</b>(<i>delimiter</i>) | ||
@@ -54,3 +62,3 @@ Constructs a new DSV parser and formatter for the specified *delimiter*. The *delimiter* must be a single character (*i.e.*, a single 16-bit code unit); so, ASCII delimiters are fine, but emoji delimiters are not. | ||
```js | ||
var data = csv.parse(string, function(d) { | ||
var data = d3_dsv.csv.parse(string, function(d) { | ||
return { | ||
@@ -90,3 +98,3 @@ year: new Date(+d.Year, 0, 1), // convert "Year" column to Date | ||
```js | ||
var data = csv.parseRows(string, function(d, i) { | ||
var data = d3_dsv.csv.parseRows(string, function(d, i) { | ||
return { | ||
@@ -110,3 +118,3 @@ year: new Date(+d[0], 0, 1), // convert first colum column to Date | ||
```js | ||
var string = csv.format(data, ["year", "make", "model", "length"]); | ||
var string = d3_dsv.csv.format(data, ["year", "make", "model", "length"]); | ||
``` | ||
@@ -120,6 +128,6 @@ | ||
To convert an array of objects to an array of arrays while explicitly specifying the columns, use [array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map). For example: | ||
To convert an array of objects to an array of arrays while explicitly specifying the columns, use [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map). For example: | ||
```js | ||
var string = csv.formatRows(data.map(function(d, i) { | ||
var string = d3_dsv.csv.formatRows(data.map(function(d, i) { | ||
return [ | ||
@@ -134,6 +142,6 @@ d.year.getFullYear(), // Assuming d.year is a Date object. | ||
If you like, you can also [array.concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) this result with an array of column names to generate the first row: | ||
If you like, you can also [*array*.concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) this result with an array of column names to generate the first row: | ||
```js | ||
var string = csv.formatRows([[ | ||
var string = d3_dsv.csv.formatRows([[ | ||
"year", | ||
@@ -153,3 +161,3 @@ "make", | ||
<a name="csv" href="#csv">#</a> <b>csv</b> | ||
<a name="csv" href="#csv">#</a> d3_dsv.<b>csv</b> | ||
@@ -159,6 +167,6 @@ A parser and formatter for comma-separated values (CSV), defined as: | ||
```js | ||
var csv = dsv(","); | ||
var csv = d3_dsv.dsv(","); | ||
``` | ||
<a name="tsv" href="#tsv">#</a> <b>tsv</b> | ||
<a name="tsv" href="#tsv">#</a> d3_dsv.<b>tsv</b> | ||
@@ -168,3 +176,3 @@ A parser and formatter for tab-separated values (TSV), defined as: | ||
```js | ||
var tsv = dsv("\t"); | ||
var tsv = d3_dsv.dsv("\t"); | ||
``` | ||
@@ -178,3 +186,3 @@ | ||
The d3-dsv module comes with a few binaries to convert DSV files: | ||
This module comes with a few binaries to convert DSV files: | ||
@@ -181,0 +189,0 @@ * csv2json |
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
23488
191