@depup/d3-dsv 3.0.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2013-2021 Mike Bostock
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # @depup/d3-dsv
2
+
3
+ > Dependency-bumped version of [d3-dsv](https://www.npmjs.com/package/d3-dsv)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/d3-dsv
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [d3-dsv](https://www.npmjs.com/package/d3-dsv) @ 3.0.1 |
17
+ | Processed | 2026-03-17 |
18
+ | Smoke test | passed |
19
+ | Deps updated | 3 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | commander | 7 | ^14.0.3 |
26
+ | iconv-lite | 0.6 | ^0.7.2 |
27
+ | rw | 1 | ^1.3.3 |
28
+
29
+ ---
30
+
31
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/d3-dsv
32
+
33
+ License inherited from the original package.
package/bin/dsv2dsv.js ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {EOL} from "os";
4
+ import {basename, dirname, resolve} from "path";
5
+ import {readFileSync} from "fs";
6
+ import {fileURLToPath} from "url";
7
+ import rw from "rw";
8
+ import {program} from "commander";
9
+ import iconv from "iconv-lite";
10
+ import {dsvFormat} from "../src/index.js";
11
+
12
+ const progname = basename(process.argv[1]);
13
+ const defaultInDelimiter = progname.slice(0, 3) === "tsv" ? "\t" : ",";
14
+ const defaultOutDelimiter = progname.slice(-3) === "tsv" ? "\t" : ",";
15
+
16
+ const options = program
17
+ .version(JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version)
18
+ .usage("[options] [file]")
19
+ .option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
20
+ .option("-r, --input-delimiter <character>", "input delimiter character", defaultInDelimiter)
21
+ .option("-w, --output-delimiter <character>", "output delimiter character", defaultOutDelimiter)
22
+ .option("--input-encoding <encoding>", "input character encoding; defaults to “utf8”", "utf8")
23
+ .option("--output-encoding <encoding>", "output character encoding; defaults to “utf8”", "utf8")
24
+ .parse(process.argv)
25
+ .opts();
26
+
27
+ const inFormat = dsvFormat(options.inputDelimiter);
28
+ const outFormat = dsvFormat(options.outputDelimiter);
29
+
30
+ rw.dash.readFile(program.args[0] || "-", (error, text) => {
31
+ if (error) throw error;
32
+ rw.dash.writeFile("-", iconv.encode(outFormat.format(inFormat.parse(iconv.decode(text, options.inputEncoding))) + EOL, options.outputEncoding), (error) => {
33
+ if (error) throw error;
34
+ });
35
+ });
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {EOL} from "os";
4
+ import {basename, dirname, resolve} from "path";
5
+ import {readFileSync} from "fs";
6
+ import {fileURLToPath} from "url";
7
+ import rw from "rw";
8
+ import {program} from "commander";
9
+ import iconv from "iconv-lite";
10
+ import {dsvFormat} from "../src/index.js";
11
+
12
+ const progname = basename(process.argv[1]);
13
+ const defaultInDelimiter = progname.slice(0, 3) === "tsv" ? "\t" : ",";
14
+
15
+ const options = program
16
+ .version(JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version)
17
+ .usage("[options] [file]")
18
+ .option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
19
+ .option("-r, --input-delimiter <character>", "input delimiter character", defaultInDelimiter)
20
+ .option("-a, --auto-type", "parse rows with type inference (see d3.autoType)")
21
+ .option("-n, --newline-delimited", "output newline-delimited JSON")
22
+ .option("--input-encoding <encoding>", "input character encoding; defaults to “utf8”", "utf8")
23
+ .option("--output-encoding <encoding>", "output character encoding; defaults to “utf8”", "utf8")
24
+ .parse(process.argv)
25
+ .opts();
26
+
27
+ const inFormat = dsvFormat(options.inputDelimiter);
28
+
29
+ rw.dash.readFile(program.args[0] || "-", (error, text) => {
30
+ if (error) throw error;
31
+ const rowConverter = options.autoType ? dsv.autoType : null
32
+ const rows = inFormat.parse(iconv.decode(text, options.inputEncoding), rowConverter);
33
+ rw.dash.writeFile(options.out, iconv.encode(options.newlineDelimited
34
+ ? rows.map((row) => JSON.stringify(row)).join("\n") + "\n"
35
+ : JSON.stringify(rows) + EOL, options.outputEncoding), (error) => {
36
+ if (error) throw error;
37
+ });
38
+ });
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {EOL} from "os";
4
+ import {basename, dirname, resolve} from "path";
5
+ import {readFileSync} from "fs";
6
+ import {fileURLToPath} from "url";
7
+ import rw from "rw";
8
+ import {program} from "commander";
9
+ import iconv from "iconv-lite";
10
+ import {dsvFormat} from "../src/index.js";
11
+
12
+ const progname = basename(process.argv[1]);
13
+ const defaultOutDelimiter = progname.slice(-3) === "tsv" ? "\t" : ",";
14
+
15
+ const options = program
16
+ .version(JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../package.json"))).version)
17
+ .usage("[options] [file]")
18
+ .option("-o, --out <file>", "output file name; defaults to “-” for stdout", "-")
19
+ .option("-w, --output-delimiter <character>", "output delimiter character", defaultOutDelimiter)
20
+ .option("-n, --newline-delimited", "accept newline-delimited JSON")
21
+ .option("--input-encoding <encoding>", "input character encoding; defaults to “utf8”", "utf8")
22
+ .option("--output-encoding <encoding>", "output character encoding; defaults to “utf8”", "utf8")
23
+ .parse(process.argv)
24
+ .opts();
25
+
26
+ const outFormat = dsvFormat(options.outputDelimiter);
27
+
28
+ rw.dash.readFile(program.args[0] || "-", (error, text) => {
29
+ if (error) throw error;
30
+ text = iconv.decode(text, options.inputEncoding);
31
+ rw.dash.writeFile(options.out, iconv.encode(outFormat.format(options.newlineDelimited
32
+ ? text.trim().split(/\r?\n/g).map((line) => JSON.parse(line))
33
+ : JSON.parse(text)) + EOL, options.outputEncoding), (error) => {
34
+ if (error) throw error;
35
+ });
36
+ });
package/changes.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "bumped": {
3
+ "commander": {
4
+ "from": "7",
5
+ "to": "^14.0.3"
6
+ },
7
+ "iconv-lite": {
8
+ "from": "0.6",
9
+ "to": "^0.7.2"
10
+ },
11
+ "rw": {
12
+ "from": "1",
13
+ "to": "^1.3.3"
14
+ }
15
+ },
16
+ "timestamp": "2026-03-17T16:35:24.438Z",
17
+ "totalUpdated": 3
18
+ }
package/dist/d3-dsv.js ADDED
@@ -0,0 +1,233 @@
1
+ // https://d3js.org/d3-dsv/ v3.0.1 Copyright 2013-2021 Mike Bostock
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
6
+ }(this, (function (exports) { 'use strict';
7
+
8
+ var EOL = {},
9
+ EOF = {},
10
+ QUOTE = 34,
11
+ NEWLINE = 10,
12
+ RETURN = 13;
13
+
14
+ function objectConverter(columns) {
15
+ return new Function("d", "return {" + columns.map(function(name, i) {
16
+ return JSON.stringify(name) + ": d[" + i + "] || \"\"";
17
+ }).join(",") + "}");
18
+ }
19
+
20
+ function customConverter(columns, f) {
21
+ var object = objectConverter(columns);
22
+ return function(row, i) {
23
+ return f(object(row), i, columns);
24
+ };
25
+ }
26
+
27
+ // Compute unique columns in order of discovery.
28
+ function inferColumns(rows) {
29
+ var columnSet = Object.create(null),
30
+ columns = [];
31
+
32
+ rows.forEach(function(row) {
33
+ for (var column in row) {
34
+ if (!(column in columnSet)) {
35
+ columns.push(columnSet[column] = column);
36
+ }
37
+ }
38
+ });
39
+
40
+ return columns;
41
+ }
42
+
43
+ function pad(value, width) {
44
+ var s = value + "", length = s.length;
45
+ return length < width ? new Array(width - length + 1).join(0) + s : s;
46
+ }
47
+
48
+ function formatYear(year) {
49
+ return year < 0 ? "-" + pad(-year, 6)
50
+ : year > 9999 ? "+" + pad(year, 6)
51
+ : pad(year, 4);
52
+ }
53
+
54
+ function formatDate(date) {
55
+ var hours = date.getUTCHours(),
56
+ minutes = date.getUTCMinutes(),
57
+ seconds = date.getUTCSeconds(),
58
+ milliseconds = date.getUTCMilliseconds();
59
+ return isNaN(date) ? "Invalid Date"
60
+ : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
61
+ + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
62
+ : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
63
+ : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
64
+ : "");
65
+ }
66
+
67
+ function dsv(delimiter) {
68
+ var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
69
+ DELIMITER = delimiter.charCodeAt(0);
70
+
71
+ function parse(text, f) {
72
+ var convert, columns, rows = parseRows(text, function(row, i) {
73
+ if (convert) return convert(row, i - 1);
74
+ columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
75
+ });
76
+ rows.columns = columns || [];
77
+ return rows;
78
+ }
79
+
80
+ function parseRows(text, f) {
81
+ var rows = [], // output rows
82
+ N = text.length,
83
+ I = 0, // current character index
84
+ n = 0, // current line number
85
+ t, // current token
86
+ eof = N <= 0, // current token followed by EOF?
87
+ eol = false; // current token followed by EOL?
88
+
89
+ // Strip the trailing newline.
90
+ if (text.charCodeAt(N - 1) === NEWLINE) --N;
91
+ if (text.charCodeAt(N - 1) === RETURN) --N;
92
+
93
+ function token() {
94
+ if (eof) return EOF;
95
+ if (eol) return eol = false, EOL;
96
+
97
+ // Unescape quotes.
98
+ var i, j = I, c;
99
+ if (text.charCodeAt(j) === QUOTE) {
100
+ while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
101
+ if ((i = I) >= N) eof = true;
102
+ else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
103
+ else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
104
+ return text.slice(j + 1, i - 1).replace(/""/g, "\"");
105
+ }
106
+
107
+ // Find next delimiter or newline.
108
+ while (I < N) {
109
+ if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
110
+ else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
111
+ else if (c !== DELIMITER) continue;
112
+ return text.slice(j, i);
113
+ }
114
+
115
+ // Return last token before EOF.
116
+ return eof = true, text.slice(j, N);
117
+ }
118
+
119
+ while ((t = token()) !== EOF) {
120
+ var row = [];
121
+ while (t !== EOL && t !== EOF) row.push(t), t = token();
122
+ if (f && (row = f(row, n++)) == null) continue;
123
+ rows.push(row);
124
+ }
125
+
126
+ return rows;
127
+ }
128
+
129
+ function preformatBody(rows, columns) {
130
+ return rows.map(function(row) {
131
+ return columns.map(function(column) {
132
+ return formatValue(row[column]);
133
+ }).join(delimiter);
134
+ });
135
+ }
136
+
137
+ function format(rows, columns) {
138
+ if (columns == null) columns = inferColumns(rows);
139
+ return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
140
+ }
141
+
142
+ function formatBody(rows, columns) {
143
+ if (columns == null) columns = inferColumns(rows);
144
+ return preformatBody(rows, columns).join("\n");
145
+ }
146
+
147
+ function formatRows(rows) {
148
+ return rows.map(formatRow).join("\n");
149
+ }
150
+
151
+ function formatRow(row) {
152
+ return row.map(formatValue).join(delimiter);
153
+ }
154
+
155
+ function formatValue(value) {
156
+ return value == null ? ""
157
+ : value instanceof Date ? formatDate(value)
158
+ : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
159
+ : value;
160
+ }
161
+
162
+ return {
163
+ parse: parse,
164
+ parseRows: parseRows,
165
+ format: format,
166
+ formatBody: formatBody,
167
+ formatRows: formatRows,
168
+ formatRow: formatRow,
169
+ formatValue: formatValue
170
+ };
171
+ }
172
+
173
+ var csv = dsv(",");
174
+
175
+ var csvParse = csv.parse;
176
+ var csvParseRows = csv.parseRows;
177
+ var csvFormat = csv.format;
178
+ var csvFormatBody = csv.formatBody;
179
+ var csvFormatRows = csv.formatRows;
180
+ var csvFormatRow = csv.formatRow;
181
+ var csvFormatValue = csv.formatValue;
182
+
183
+ var tsv = dsv("\t");
184
+
185
+ var tsvParse = tsv.parse;
186
+ var tsvParseRows = tsv.parseRows;
187
+ var tsvFormat = tsv.format;
188
+ var tsvFormatBody = tsv.formatBody;
189
+ var tsvFormatRows = tsv.formatRows;
190
+ var tsvFormatRow = tsv.formatRow;
191
+ var tsvFormatValue = tsv.formatValue;
192
+
193
+ function autoType(object) {
194
+ for (var key in object) {
195
+ var value = object[key].trim(), number, m;
196
+ if (!value) value = null;
197
+ else if (value === "true") value = true;
198
+ else if (value === "false") value = false;
199
+ else if (value === "NaN") value = NaN;
200
+ else if (!isNaN(number = +value)) value = number;
201
+ else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
202
+ if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
203
+ value = new Date(value);
204
+ }
205
+ else continue;
206
+ object[key] = value;
207
+ }
208
+ return object;
209
+ }
210
+
211
+ // https://github.com/d3/d3-dsv/issues/45
212
+ const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
213
+
214
+ exports.autoType = autoType;
215
+ exports.csvFormat = csvFormat;
216
+ exports.csvFormatBody = csvFormatBody;
217
+ exports.csvFormatRow = csvFormatRow;
218
+ exports.csvFormatRows = csvFormatRows;
219
+ exports.csvFormatValue = csvFormatValue;
220
+ exports.csvParse = csvParse;
221
+ exports.csvParseRows = csvParseRows;
222
+ exports.dsvFormat = dsv;
223
+ exports.tsvFormat = tsvFormat;
224
+ exports.tsvFormatBody = tsvFormatBody;
225
+ exports.tsvFormatRow = tsvFormatRow;
226
+ exports.tsvFormatRows = tsvFormatRows;
227
+ exports.tsvFormatValue = tsvFormatValue;
228
+ exports.tsvParse = tsvParse;
229
+ exports.tsvParseRows = tsvParseRows;
230
+
231
+ Object.defineProperty(exports, '__esModule', { value: true });
232
+
233
+ })));
@@ -0,0 +1,2 @@
1
+ // https://d3js.org/d3-dsv/ v3.0.1 Copyright 2013-2021 Mike Bostock
2
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3=e.d3||{})}(this,(function(e){"use strict";var t={},r={};function n(e){return new Function("d","return {"+e.map((function(e,t){return JSON.stringify(e)+": d["+t+'] || ""'})).join(",")+"}")}function o(e){var t=Object.create(null),r=[];return e.forEach((function(e){for(var n in e)n in t||r.push(t[n]=n)})),r}function a(e,t){var r=e+"",n=r.length;return n<t?new Array(t-n+1).join(0)+r:r}function u(e){var t,r=e.getUTCHours(),n=e.getUTCMinutes(),o=e.getUTCSeconds(),u=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":((t=e.getUTCFullYear())<0?"-"+a(-t,6):t>9999?"+"+a(t,6):a(t,4))+"-"+a(e.getUTCMonth()+1,2)+"-"+a(e.getUTCDate(),2)+(u?"T"+a(r,2)+":"+a(n,2)+":"+a(o,2)+"."+a(u,3)+"Z":o?"T"+a(r,2)+":"+a(n,2)+":"+a(o,2)+"Z":n||r?"T"+a(r,2)+":"+a(n,2)+"Z":"")}function i(e){var a=new RegExp('["'+e+"\n\r]"),i=e.charCodeAt(0);function f(e,n){var o,a=[],u=e.length,f=0,s=0,c=u<=0,l=!1;function d(){if(c)return r;if(l)return l=!1,t;var n,o,a=f;if(34===e.charCodeAt(a)){for(;f++<u&&34!==e.charCodeAt(f)||34===e.charCodeAt(++f););return(n=f)>=u?c=!0:10===(o=e.charCodeAt(f++))?l=!0:13===o&&(l=!0,10===e.charCodeAt(f)&&++f),e.slice(a+1,n-1).replace(/""/g,'"')}for(;f<u;){if(10===(o=e.charCodeAt(n=f++)))l=!0;else if(13===o)l=!0,10===e.charCodeAt(f)&&++f;else if(o!==i)continue;return e.slice(a,n)}return c=!0,e.slice(a,u)}for(10===e.charCodeAt(u-1)&&--u,13===e.charCodeAt(u-1)&&--u;(o=d())!==r;){for(var m=[];o!==t&&o!==r;)m.push(o),o=d();n&&null==(m=n(m,s++))||a.push(m)}return a}function s(t,r){return t.map((function(t){return r.map((function(e){return l(t[e])})).join(e)}))}function c(t){return t.map(l).join(e)}function l(e){return null==e?"":e instanceof Date?u(e):a.test(e+="")?'"'+e.replace(/"/g,'""')+'"':e}return{parse:function(e,t){var r,o,a=f(e,(function(e,a){if(r)return r(e,a-1);o=e,r=t?function(e,t){var r=n(e);return function(n,o){return t(r(n),o,e)}}(e,t):n(e)}));return a.columns=o||[],a},parseRows:f,format:function(t,r){return null==r&&(r=o(t)),[r.map(l).join(e)].concat(s(t,r)).join("\n")},formatBody:function(e,t){return null==t&&(t=o(e)),s(e,t).join("\n")},formatRows:function(e){return e.map(c).join("\n")},formatRow:c,formatValue:l}}var f=i(","),s=f.parse,c=f.parseRows,l=f.format,d=f.formatBody,m=f.formatRows,v=f.formatRow,p=f.formatValue,h=i("\t"),w=h.parse,g=h.parseRows,C=h.format,T=h.formatBody,R=h.formatRows,y=h.formatRow,F=h.formatValue;const j=new Date("2019-01-01T00:00").getHours()||new Date("2019-07-01T00:00").getHours();e.autoType=function(e){for(var t in e){var r,n,o=e[t].trim();if(o)if("true"===o)o=!0;else if("false"===o)o=!1;else if("NaN"===o)o=NaN;else if(isNaN(r=+o)){if(!(n=o.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)))continue;j&&n[4]&&!n[7]&&(o=o.replace(/-/g,"/").replace(/T/," ")),o=new Date(o)}else o=r;else o=null;e[t]=o}return e},e.csvFormat=l,e.csvFormatBody=d,e.csvFormatRow=v,e.csvFormatRows=m,e.csvFormatValue=p,e.csvParse=s,e.csvParseRows=c,e.dsvFormat=i,e.tsvFormat=C,e.tsvFormatBody=T,e.tsvFormatRow=y,e.tsvFormatRows=R,e.tsvFormatValue=F,e.tsvParse=w,e.tsvParseRows=g,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@depup/d3-dsv",
3
+ "version": "3.0.1-depup.0",
4
+ "description": "[DepUp] A parser and formatter for delimiter-separated values, such as CSV and TSV",
5
+ "homepage": "https://d3js.org/d3-dsv/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/d3/d3-dsv.git"
9
+ },
10
+ "keywords": [
11
+ "depup",
12
+ "dependency-bumped",
13
+ "updated-deps",
14
+ "d3-dsv",
15
+ "d3",
16
+ "d3-module",
17
+ "dsv",
18
+ "csv",
19
+ "tsv"
20
+ ],
21
+ "license": "ISC",
22
+ "author": {
23
+ "name": "Mike Bostock",
24
+ "url": "http://bost.ocks.org/mike"
25
+ },
26
+ "type": "module",
27
+ "files": [
28
+ "bin/*.js",
29
+ "dist/**/*.js",
30
+ "src/**/*.js",
31
+ "changes.json",
32
+ "README.md"
33
+ ],
34
+ "module": "src/index.js",
35
+ "main": "src/index.js",
36
+ "jsdelivr": "dist/d3-dsv.min.js",
37
+ "unpkg": "dist/d3-dsv.min.js",
38
+ "exports": {
39
+ "umd": "./dist/d3-dsv.min.js",
40
+ "default": "./src/index.js"
41
+ },
42
+ "sideEffects": false,
43
+ "dependencies": {
44
+ "commander": "^14.0.3",
45
+ "iconv-lite": "^0.7.2",
46
+ "rw": "^1.3.3"
47
+ },
48
+ "devDependencies": {
49
+ "csv-spectrum": "1",
50
+ "eslint": "7",
51
+ "mocha": "8",
52
+ "rollup": "2",
53
+ "rollup-plugin-terser": "7"
54
+ },
55
+ "scripts": {
56
+ "test": "TZ=America/Los_Angeles mocha 'test/**/*-test.js' && eslint src test",
57
+ "postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
58
+ },
59
+ "engines": {
60
+ "node": ">=12"
61
+ },
62
+ "bin": {
63
+ "csv2json": "bin/dsv2json.js",
64
+ "csv2tsv": "bin/dsv2dsv.js",
65
+ "dsv2dsv": "bin/dsv2dsv.js",
66
+ "dsv2json": "bin/dsv2json.js",
67
+ "json2csv": "bin/json2dsv.js",
68
+ "json2dsv": "bin/json2dsv.js",
69
+ "json2tsv": "bin/json2dsv.js",
70
+ "tsv2csv": "bin/dsv2dsv.js",
71
+ "tsv2json": "bin/dsv2json.js"
72
+ },
73
+ "depup": {
74
+ "changes": {
75
+ "commander": {
76
+ "from": "7",
77
+ "to": "^14.0.3"
78
+ },
79
+ "iconv-lite": {
80
+ "from": "0.6",
81
+ "to": "^0.7.2"
82
+ },
83
+ "rw": {
84
+ "from": "1",
85
+ "to": "^1.3.3"
86
+ }
87
+ },
88
+ "depsUpdated": 3,
89
+ "originalPackage": "d3-dsv",
90
+ "originalVersion": "3.0.1",
91
+ "processedAt": "2026-03-17T16:35:28.035Z",
92
+ "smokeTest": "passed"
93
+ }
94
+ }
@@ -0,0 +1,20 @@
1
+ export default function autoType(object) {
2
+ for (var key in object) {
3
+ var value = object[key].trim(), number, m;
4
+ if (!value) value = null;
5
+ else if (value === "true") value = true;
6
+ else if (value === "false") value = false;
7
+ else if (value === "NaN") value = NaN;
8
+ else if (!isNaN(number = +value)) value = number;
9
+ else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
10
+ if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
11
+ value = new Date(value);
12
+ }
13
+ else continue;
14
+ object[key] = value;
15
+ }
16
+ return object;
17
+ }
18
+
19
+ // https://github.com/d3/d3-dsv/issues/45
20
+ const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
package/src/csv.js ADDED
@@ -0,0 +1,11 @@
1
+ import dsv from "./dsv.js";
2
+
3
+ var csv = dsv(",");
4
+
5
+ export var csvParse = csv.parse;
6
+ export var csvParseRows = csv.parseRows;
7
+ export var csvFormat = csv.format;
8
+ export var csvFormatBody = csv.formatBody;
9
+ export var csvFormatRows = csv.formatRows;
10
+ export var csvFormatRow = csv.formatRow;
11
+ export var csvFormatValue = csv.formatValue;
package/src/dsv.js ADDED
@@ -0,0 +1,164 @@
1
+ var EOL = {},
2
+ EOF = {},
3
+ QUOTE = 34,
4
+ NEWLINE = 10,
5
+ RETURN = 13;
6
+
7
+ function objectConverter(columns) {
8
+ return new Function("d", "return {" + columns.map(function(name, i) {
9
+ return JSON.stringify(name) + ": d[" + i + "] || \"\"";
10
+ }).join(",") + "}");
11
+ }
12
+
13
+ function customConverter(columns, f) {
14
+ var object = objectConverter(columns);
15
+ return function(row, i) {
16
+ return f(object(row), i, columns);
17
+ };
18
+ }
19
+
20
+ // Compute unique columns in order of discovery.
21
+ function inferColumns(rows) {
22
+ var columnSet = Object.create(null),
23
+ columns = [];
24
+
25
+ rows.forEach(function(row) {
26
+ for (var column in row) {
27
+ if (!(column in columnSet)) {
28
+ columns.push(columnSet[column] = column);
29
+ }
30
+ }
31
+ });
32
+
33
+ return columns;
34
+ }
35
+
36
+ function pad(value, width) {
37
+ var s = value + "", length = s.length;
38
+ return length < width ? new Array(width - length + 1).join(0) + s : s;
39
+ }
40
+
41
+ function formatYear(year) {
42
+ return year < 0 ? "-" + pad(-year, 6)
43
+ : year > 9999 ? "+" + pad(year, 6)
44
+ : pad(year, 4);
45
+ }
46
+
47
+ function formatDate(date) {
48
+ var hours = date.getUTCHours(),
49
+ minutes = date.getUTCMinutes(),
50
+ seconds = date.getUTCSeconds(),
51
+ milliseconds = date.getUTCMilliseconds();
52
+ return isNaN(date) ? "Invalid Date"
53
+ : formatYear(date.getUTCFullYear(), 4) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
54
+ + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
55
+ : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
56
+ : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
57
+ : "");
58
+ }
59
+
60
+ export default function(delimiter) {
61
+ var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
62
+ DELIMITER = delimiter.charCodeAt(0);
63
+
64
+ function parse(text, f) {
65
+ var convert, columns, rows = parseRows(text, function(row, i) {
66
+ if (convert) return convert(row, i - 1);
67
+ columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
68
+ });
69
+ rows.columns = columns || [];
70
+ return rows;
71
+ }
72
+
73
+ function parseRows(text, f) {
74
+ var rows = [], // output rows
75
+ N = text.length,
76
+ I = 0, // current character index
77
+ n = 0, // current line number
78
+ t, // current token
79
+ eof = N <= 0, // current token followed by EOF?
80
+ eol = false; // current token followed by EOL?
81
+
82
+ // Strip the trailing newline.
83
+ if (text.charCodeAt(N - 1) === NEWLINE) --N;
84
+ if (text.charCodeAt(N - 1) === RETURN) --N;
85
+
86
+ function token() {
87
+ if (eof) return EOF;
88
+ if (eol) return eol = false, EOL;
89
+
90
+ // Unescape quotes.
91
+ var i, j = I, c;
92
+ if (text.charCodeAt(j) === QUOTE) {
93
+ while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
94
+ if ((i = I) >= N) eof = true;
95
+ else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
96
+ else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
97
+ return text.slice(j + 1, i - 1).replace(/""/g, "\"");
98
+ }
99
+
100
+ // Find next delimiter or newline.
101
+ while (I < N) {
102
+ if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
103
+ else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
104
+ else if (c !== DELIMITER) continue;
105
+ return text.slice(j, i);
106
+ }
107
+
108
+ // Return last token before EOF.
109
+ return eof = true, text.slice(j, N);
110
+ }
111
+
112
+ while ((t = token()) !== EOF) {
113
+ var row = [];
114
+ while (t !== EOL && t !== EOF) row.push(t), t = token();
115
+ if (f && (row = f(row, n++)) == null) continue;
116
+ rows.push(row);
117
+ }
118
+
119
+ return rows;
120
+ }
121
+
122
+ function preformatBody(rows, columns) {
123
+ return rows.map(function(row) {
124
+ return columns.map(function(column) {
125
+ return formatValue(row[column]);
126
+ }).join(delimiter);
127
+ });
128
+ }
129
+
130
+ function format(rows, columns) {
131
+ if (columns == null) columns = inferColumns(rows);
132
+ return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
133
+ }
134
+
135
+ function formatBody(rows, columns) {
136
+ if (columns == null) columns = inferColumns(rows);
137
+ return preformatBody(rows, columns).join("\n");
138
+ }
139
+
140
+ function formatRows(rows) {
141
+ return rows.map(formatRow).join("\n");
142
+ }
143
+
144
+ function formatRow(row) {
145
+ return row.map(formatValue).join(delimiter);
146
+ }
147
+
148
+ function formatValue(value) {
149
+ return value == null ? ""
150
+ : value instanceof Date ? formatDate(value)
151
+ : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
152
+ : value;
153
+ }
154
+
155
+ return {
156
+ parse: parse,
157
+ parseRows: parseRows,
158
+ format: format,
159
+ formatBody: formatBody,
160
+ formatRows: formatRows,
161
+ formatRow: formatRow,
162
+ formatValue: formatValue
163
+ };
164
+ }
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export {default as dsvFormat} from "./dsv.js";
2
+ export {csvParse, csvParseRows, csvFormat, csvFormatBody, csvFormatRows, csvFormatRow, csvFormatValue} from "./csv.js";
3
+ export {tsvParse, tsvParseRows, tsvFormat, tsvFormatBody, tsvFormatRows, tsvFormatRow, tsvFormatValue} from "./tsv.js";
4
+ export {default as autoType} from "./autoType.js";
package/src/tsv.js ADDED
@@ -0,0 +1,11 @@
1
+ import dsv from "./dsv.js";
2
+
3
+ var tsv = dsv("\t");
4
+
5
+ export var tsvParse = tsv.parse;
6
+ export var tsvParseRows = tsv.parseRows;
7
+ export var tsvFormat = tsv.format;
8
+ export var tsvFormatBody = tsv.formatBody;
9
+ export var tsvFormatRows = tsv.formatRows;
10
+ export var tsvFormatRow = tsv.formatRow;
11
+ export var tsvFormatValue = tsv.formatValue;