@graphysdk/data-import-utils 1.8.0 → 1.8.1-beta.1786024899180
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.md +17 -0
- package/README.md +11 -15
- package/dist/buffer.cjs +1 -1
- package/dist/buffer.mjs +4 -1
- package/dist/constants-BSk6SyUk.cjs +1 -0
- package/dist/constants-PA0Uh9bi.js +5 -0
- package/dist/csv.cjs +1 -1
- package/dist/csv.mjs +4 -1
- package/dist/file.cjs +1 -1
- package/dist/file.mjs +17 -1
- package/dist/format-detection-1kqWtVpP.cjs +1 -0
- package/dist/format-detection-MwlOpP6Y.js +18 -0
- package/dist/from-csv-Ccr_5k9u.cjs +1 -0
- package/dist/from-csv-CrQ_H-s5.js +5 -0
- package/dist/from-csv.d.ts +13 -0
- package/dist/from-json-DC712HdK.js +48 -0
- package/dist/from-json-lzRNXlod.cjs +1 -0
- package/dist/{json.d.ts → from-json.d.ts} +4 -18
- package/dist/from-spreadsheet-D2kWRyr3.js +79 -0
- package/dist/from-spreadsheet-EfBhqj2z.cjs +1 -0
- package/dist/from-spreadsheet.d.ts +20 -0
- package/dist/from-tsv-B02B59Ey.cjs +1 -0
- package/dist/from-tsv-CPj6UzXC.js +5 -0
- package/dist/from-tsv.d.ts +11 -0
- package/dist/index-buffer.d.ts +2 -0
- package/dist/index-csv.d.ts +2 -0
- package/dist/index-file.d.ts +2 -0
- package/dist/index-json.d.ts +3 -0
- package/dist/index-ods.d.ts +2 -0
- package/dist/index-text.d.ts +2 -0
- package/dist/index-tsv.d.ts +2 -0
- package/dist/index-url.d.ts +2 -0
- package/dist/index-xls.d.ts +2 -0
- package/dist/index-xlsx.d.ts +8 -0
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +8 -44
- package/dist/index.mjs +0 -1
- package/dist/json.cjs +1 -1
- package/dist/json.mjs +4 -1
- package/dist/map-rows-1hzHO_rN.cjs +1 -0
- package/dist/map-rows-GOmUltJ3.js +35 -0
- package/dist/ods.cjs +1 -1
- package/dist/ods.mjs +4 -1
- package/dist/parse-delimited-BSoFIVFq.cjs +1 -0
- package/dist/parse-delimited-qsjX5KAa.js +28 -0
- package/dist/parse-delimited.d.ts +7 -0
- package/dist/parse-file.d.ts +12 -0
- package/dist/parse-string-DpdSP3xh.cjs +1 -0
- package/dist/parse-string-VVlSsL2Y.js +47 -0
- package/dist/parse-string.d.ts +29 -0
- package/dist/parse-url.d.ts +14 -0
- package/dist/spreadsheet/cell-primitive.d.ts +7 -0
- package/dist/spreadsheet/load-workbook.d.ts +3 -0
- package/dist/spreadsheet/read-region.d.ts +39 -0
- package/dist/spreadsheet/workbook-index.d.ts +50 -0
- package/dist/text.cjs +1 -1
- package/dist/text.mjs +4 -1
- package/dist/tsv.cjs +1 -1
- package/dist/tsv.mjs +4 -1
- package/dist/{url.d.ts → types.d.ts} +18 -24
- package/dist/url.cjs +1 -1
- package/dist/url.mjs +87 -1
- package/dist/utils/build-columns.d.ts +10 -0
- package/dist/utils/column-index-to-property-key.d.ts +2 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/format-detection.d.ts +4 -0
- package/dist/utils/map-rows.d.ts +13 -0
- package/dist/utils/normalize-value.d.ts +12 -0
- package/dist/utils/url-validation.d.ts +2 -0
- package/dist/wire-data.types.d.ts +13 -0
- package/dist/xls.cjs +1 -1
- package/dist/xls.mjs +4 -1
- package/dist/xlsx.cjs +1 -1
- package/dist/xlsx.mjs +172 -1
- package/package.json +52 -38
- package/dist/README.md +0 -78
- package/dist/buffer.d.ts +0 -36
- package/dist/csv.d.ts +0 -32
- package/dist/file.d.ts +0 -42
- package/dist/ods.d.ts +0 -31
- package/dist/text.d.ts +0 -32
- package/dist/tsv.d.ts +0 -30
- package/dist/xls.d.ts +0 -32
- package/dist/xlsx.d.ts +0 -127
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Data, VizLocale } from '../types';
|
|
2
|
+
import { CellValue } from './normalize-value';
|
|
3
|
+
type Column = Data['columns'][number];
|
|
4
|
+
/**
|
|
5
|
+
* Maps raw data rows into the record format expected by `Data`.
|
|
6
|
+
*
|
|
7
|
+
* Each cell is normalized:
|
|
8
|
+
* - Numbers are preserved directly
|
|
9
|
+
* - Strings are trimmed and coerced to numbers when possible (locale-aware)
|
|
10
|
+
* - Empty / null / undefined values become `null`
|
|
11
|
+
*/
|
|
12
|
+
export declare const mapRows: (dataRows: unknown[][], columns: Column[], locale: VizLocale) => Array<Record<string, CellValue>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VizLocale } from '../types';
|
|
2
|
+
/** A cell value after normalization. */
|
|
3
|
+
export type CellValue = string | number | null;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes a raw string cell value:
|
|
6
|
+
* - Trims whitespace
|
|
7
|
+
* - Replaces unicode dashes before digits with ASCII minus
|
|
8
|
+
* - Replaces non-breaking spaces with regular spaces
|
|
9
|
+
* - Converts empty strings to `null`
|
|
10
|
+
* - Coerces plain numeric strings to `number` (locale-aware)
|
|
11
|
+
*/
|
|
12
|
+
export declare const normalizeValue: (raw: string, locale?: VizLocale) => CellValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type VizLocale = (typeof VIZ_LOCALES)[number];
|
|
2
|
+
export type Data = {
|
|
3
|
+
columns: Array<{
|
|
4
|
+
key: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
}>;
|
|
7
|
+
rows: Array<Record<string, string | number | null>>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Wire data types for parsers (independent of Classic `@graphysdk/core`).
|
|
11
|
+
* Shape matches agents-sdk `GraphConfigData` / Classic `GraphConfig['data']`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const VIZ_LOCALES: readonly ["EN_GB", "EN_US", "AR", "PT_PT"];
|
package/dist/xls.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./from-spreadsheet-EfBhqj2z.cjs");exports.fromXLS=e.fromXLS;
|
package/dist/xls.mjs
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { n as r } from "./from-spreadsheet-D2kWRyr3.js";
|
|
2
|
+
export {
|
|
3
|
+
r as fromXLS
|
|
4
|
+
};
|
package/dist/xlsx.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./constants-BSk6SyUk.cjs"),M=require("./from-spreadsheet-EfBhqj2z.cjs");var L=5e4,I=1048576,b=16384;function g(o,e,n,c){const{rowMin:r,rowMax:l,colMin:t,colMax:s}=n;if(x("rowMin",r,I),x("rowMax",l,I),x("colMin",t,b),x("colMax",s,b),r>l||t>s)throw new Error(`Invalid region bounds: rowMin=${r}, rowMax=${l}, colMin=${t}, colMax=${s}`);const a=F(c),m=T(o,e),d=m.name,w=s-t+1;if(w>a)throw new Error(`Region requires ${w} cells per row, which exceeds maxCells (${a}); cannot return complete rows.`);const i=[];let u=0,N=!1;for(let h=r;h<=l;h++){if(u+w>a){N=!0;break}const _=[],R=m.getRow(h);for(let E=t;E<=s;E++)_.push(M.extractCellPrimitive(R.getCell(E)));i.push(_),u+=w}return{sheetIndex:e,sheetName:d,rowMin:r,rowMax:r+i.length-1,colMin:t,colMax:s,rows:i,truncated:N,returnedCellCount:u}}function A(o,e,n){return g(o,e.sheetIndex,{rowMin:e.rowMin,rowMax:e.rowMax,colMin:e.colMin,colMax:e.colMax},n)}function x(o,e,n){if(!Number.isInteger(e)||e<1||e>n)throw new Error(`${o} must be an integer between 1 and ${n} (1-based Excel index), got ${String(e)}`)}function F(o){const e=o?.maxCells??5e4;if(!Number.isInteger(e)||!Number.isFinite(e)||e<1)throw new Error(`maxCells must be a finite integer >= 1, got ${String(o?.maxCells)}`);return e}function T(o,e){const n=o.worksheets[e];if(!n)throw new Error(`Sheet index ${e} is out of range. Workbook has ${o.worksheets.length} sheet(s).`);return n}var W=1,k=X.DEFAULT_MAX_CELLS,C=65536;function S(o,e){const n=e?.maxNonEmptyCells??k;if(!Number.isInteger(n)||!Number.isFinite(n)||n<1)throw new Error(`maxNonEmptyCells must be a finite integer >= 1, got ${String(e?.maxNonEmptyCells)}`);const c=[],r=[],l={remaining:n};return o.worksheets.forEach((t,s)=>{const{sheet:a,islands:m}=P(t,s,l,n);c.push(a),r.push(...m)}),{schemaVersion:1,sheets:c,islands:r}}async function $(o,e){return S(await M.loadWorkbookFromXlsxBuffer(o),e)}var O=(o,e)=>o*C+e,f=o=>[Math.floor(o/C),o%C];function p(o){let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,c=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(const l of o){const[t,s]=f(l);e=Math.min(e,t),n=Math.max(n,t),c=Math.min(c,s),r=Math.max(r,s)}return{rowMin:e,rowMax:n,colMin:c,colMax:r}}function v(o,e,n){const c=new Set;return o.eachRow({includeEmpty:!1},(r,l)=>{r.eachCell({includeEmpty:!1},(t,s)=>{if(M.extractCellPrimitive(t)!==null){if(e.remaining<=0)throw new Error(`Workbook index exceeded maxNonEmptyCells limit (${n}). Refine the workbook or pass a higher maxNonEmptyCells.`);e.remaining-=1,c.add(O(l,s))}})}),c}function D(o){const e=[...o].sort((r,l)=>{const[t,s]=f(r),[a,m]=f(l);return t!==a?t-a:s-m}),n=new Set,c=[];for(const r of e){if(n.has(r))continue;const l=[],t=[r];for(n.add(r);t.length>0;){const s=t.pop();if(s===void 0)throw new Error("Unexpected empty DFS stack");l.push(s);const[a,m]=f(s);for(const[d,w]of[[1,0],[-1,0],[0,1],[0,-1]]){const i=O(a+d,m+w);o.has(i)&&!n.has(i)&&(n.add(i),t.push(i))}}c.push(l)}return c}function P(o,e,n,c){const r=o.name,l=v(o,n,c),t=l.size;if(t===0)return{sheet:{sheetName:r,sheetIndex:e,rowMin:null,rowMax:null,colMin:null,colMax:null,nonEmptyCellCount:0},islands:[]};const{rowMin:s,rowMax:a,colMin:m,colMax:d}=p([...l]),w=D(l).map(i=>{const u=p(i);return{sheetIndex:e,sheetName:r,...u,cellCount:i.length}}).sort((i,u)=>i.rowMin-u.rowMin||i.colMin-u.colMin||i.rowMax-u.rowMax||i.colMax-u.colMax).map((i,u)=>({...i,localId:`${e}:${u}`}));return{sheet:{sheetName:r,sheetIndex:e,rowMin:s,rowMax:a,colMin:m,colMax:d,nonEmptyCellCount:t},islands:w}}exports.DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS=k;exports.DEFAULT_READ_REGION_MAX_CELLS=L;exports.WORKBOOK_INDEX_SCHEMA_VERSION=W;exports.buildWorkbookIndex=S;exports.buildWorkbookIndexFromXlsxBuffer=$;exports.extractCellPrimitive=M.extractCellPrimitive;exports.fromXLSX=M.fromXLSX;exports.loadWorkbookFromXlsxBuffer=M.loadWorkbookFromXlsxBuffer;exports.readIslandRegion=A;exports.readSheetRegion=g;
|
package/dist/xlsx.mjs
CHANGED
|
@@ -1 +1,172 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { t as S } from "./constants-PA0Uh9bi.js";
|
|
2
|
+
import { a as b, i as R, r as V } from "./from-spreadsheet-D2kWRyr3.js";
|
|
3
|
+
var y = 5e4, N = 1048576, I = 16384;
|
|
4
|
+
function $(e, o, n, i) {
|
|
5
|
+
const { rowMin: r, rowMax: c, colMin: t, colMax: s } = n;
|
|
6
|
+
if (x("rowMin", r, N), x("rowMax", c, N), x("colMin", t, I), x("colMax", s, I), r > c || t > s) throw new Error(`Invalid region bounds: rowMin=${r}, rowMax=${c}, colMin=${t}, colMax=${s}`);
|
|
7
|
+
const a = O(i), m = A(e, o), M = m.name, w = s - t + 1;
|
|
8
|
+
if (w > a) throw new Error(`Region requires ${w} cells per row, which exceeds maxCells (${a}); cannot return complete rows.`);
|
|
9
|
+
const l = [];
|
|
10
|
+
let u = 0, C = !1;
|
|
11
|
+
for (let f = r; f <= c; f++) {
|
|
12
|
+
if (u + w > a) {
|
|
13
|
+
C = !0;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
const p = [], k = m.getRow(f);
|
|
17
|
+
for (let d = t; d <= s; d++) p.push(b(k.getCell(d)));
|
|
18
|
+
l.push(p), u += w;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
sheetIndex: o,
|
|
22
|
+
sheetName: M,
|
|
23
|
+
rowMin: r,
|
|
24
|
+
rowMax: r + l.length - 1,
|
|
25
|
+
colMin: t,
|
|
26
|
+
colMax: s,
|
|
27
|
+
rows: l,
|
|
28
|
+
truncated: C,
|
|
29
|
+
returnedCellCount: u
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function K(e, o, n) {
|
|
33
|
+
return $(e, o.sheetIndex, {
|
|
34
|
+
rowMin: o.rowMin,
|
|
35
|
+
rowMax: o.rowMax,
|
|
36
|
+
colMin: o.colMin,
|
|
37
|
+
colMax: o.colMax
|
|
38
|
+
}, n);
|
|
39
|
+
}
|
|
40
|
+
function x(e, o, n) {
|
|
41
|
+
if (!Number.isInteger(o) || o < 1 || o > n) throw new Error(`${e} must be an integer between 1 and ${n} (1-based Excel index), got ${String(o)}`);
|
|
42
|
+
}
|
|
43
|
+
function O(e) {
|
|
44
|
+
const o = e?.maxCells ?? 5e4;
|
|
45
|
+
if (!Number.isInteger(o) || !Number.isFinite(o) || o < 1) throw new Error(`maxCells must be a finite integer >= 1, got ${String(e?.maxCells)}`);
|
|
46
|
+
return o;
|
|
47
|
+
}
|
|
48
|
+
function A(e, o) {
|
|
49
|
+
const n = e.worksheets[o];
|
|
50
|
+
if (!n) throw new Error(`Sheet index ${o} is out of range. Workbook has ${e.worksheets.length} sheet(s).`);
|
|
51
|
+
return n;
|
|
52
|
+
}
|
|
53
|
+
var P = 1, F = S, E = 65536;
|
|
54
|
+
function L(e, o) {
|
|
55
|
+
const n = o?.maxNonEmptyCells ?? F;
|
|
56
|
+
if (!Number.isInteger(n) || !Number.isFinite(n) || n < 1) throw new Error(`maxNonEmptyCells must be a finite integer >= 1, got ${String(o?.maxNonEmptyCells)}`);
|
|
57
|
+
const i = [], r = [], c = { remaining: n };
|
|
58
|
+
return e.worksheets.forEach((t, s) => {
|
|
59
|
+
const { sheet: a, islands: m } = v(t, s, c, n);
|
|
60
|
+
i.push(a), r.push(...m);
|
|
61
|
+
}), {
|
|
62
|
+
schemaVersion: 1,
|
|
63
|
+
sheets: i,
|
|
64
|
+
islands: r
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function Y(e, o) {
|
|
68
|
+
return L(await R(e), o);
|
|
69
|
+
}
|
|
70
|
+
var _ = (e, o) => e * E + o, h = (e) => [Math.floor(e / E), e % E];
|
|
71
|
+
function g(e) {
|
|
72
|
+
let o = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY, i = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY;
|
|
73
|
+
for (const c of e) {
|
|
74
|
+
const [t, s] = h(c);
|
|
75
|
+
o = Math.min(o, t), n = Math.max(n, t), i = Math.min(i, s), r = Math.max(r, s);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
rowMin: o,
|
|
79
|
+
rowMax: n,
|
|
80
|
+
colMin: i,
|
|
81
|
+
colMax: r
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function T(e, o, n) {
|
|
85
|
+
const i = /* @__PURE__ */ new Set();
|
|
86
|
+
return e.eachRow({ includeEmpty: !1 }, (r, c) => {
|
|
87
|
+
r.eachCell({ includeEmpty: !1 }, (t, s) => {
|
|
88
|
+
if (b(t) !== null) {
|
|
89
|
+
if (o.remaining <= 0) throw new Error(`Workbook index exceeded maxNonEmptyCells limit (${n}). Refine the workbook or pass a higher maxNonEmptyCells.`);
|
|
90
|
+
o.remaining -= 1, i.add(_(c, s));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}), i;
|
|
94
|
+
}
|
|
95
|
+
function X(e) {
|
|
96
|
+
const o = [...e].sort((r, c) => {
|
|
97
|
+
const [t, s] = h(r), [a, m] = h(c);
|
|
98
|
+
return t !== a ? t - a : s - m;
|
|
99
|
+
}), n = /* @__PURE__ */ new Set(), i = [];
|
|
100
|
+
for (const r of o) {
|
|
101
|
+
if (n.has(r)) continue;
|
|
102
|
+
const c = [], t = [r];
|
|
103
|
+
for (n.add(r); t.length > 0; ) {
|
|
104
|
+
const s = t.pop();
|
|
105
|
+
if (s === void 0) throw new Error("Unexpected empty DFS stack");
|
|
106
|
+
c.push(s);
|
|
107
|
+
const [a, m] = h(s);
|
|
108
|
+
for (const [M, w] of [
|
|
109
|
+
[1, 0],
|
|
110
|
+
[-1, 0],
|
|
111
|
+
[0, 1],
|
|
112
|
+
[0, -1]
|
|
113
|
+
]) {
|
|
114
|
+
const l = _(a + M, m + w);
|
|
115
|
+
e.has(l) && !n.has(l) && (n.add(l), t.push(l));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
i.push(c);
|
|
119
|
+
}
|
|
120
|
+
return i;
|
|
121
|
+
}
|
|
122
|
+
function v(e, o, n, i) {
|
|
123
|
+
const r = e.name, c = T(e, n, i), t = c.size;
|
|
124
|
+
if (t === 0) return {
|
|
125
|
+
sheet: {
|
|
126
|
+
sheetName: r,
|
|
127
|
+
sheetIndex: o,
|
|
128
|
+
rowMin: null,
|
|
129
|
+
rowMax: null,
|
|
130
|
+
colMin: null,
|
|
131
|
+
colMax: null,
|
|
132
|
+
nonEmptyCellCount: 0
|
|
133
|
+
},
|
|
134
|
+
islands: []
|
|
135
|
+
};
|
|
136
|
+
const { rowMin: s, rowMax: a, colMin: m, colMax: M } = g([...c]), w = X(c).map((l) => {
|
|
137
|
+
const u = g(l);
|
|
138
|
+
return {
|
|
139
|
+
sheetIndex: o,
|
|
140
|
+
sheetName: r,
|
|
141
|
+
...u,
|
|
142
|
+
cellCount: l.length
|
|
143
|
+
};
|
|
144
|
+
}).sort((l, u) => l.rowMin - u.rowMin || l.colMin - u.colMin || l.rowMax - u.rowMax || l.colMax - u.colMax).map((l, u) => ({
|
|
145
|
+
...l,
|
|
146
|
+
localId: `${o}:${u}`
|
|
147
|
+
}));
|
|
148
|
+
return {
|
|
149
|
+
sheet: {
|
|
150
|
+
sheetName: r,
|
|
151
|
+
sheetIndex: o,
|
|
152
|
+
rowMin: s,
|
|
153
|
+
rowMax: a,
|
|
154
|
+
colMin: m,
|
|
155
|
+
colMax: M,
|
|
156
|
+
nonEmptyCellCount: t
|
|
157
|
+
},
|
|
158
|
+
islands: w
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
F as DEFAULT_MAX_WORKBOOK_INDEX_NON_EMPTY_CELLS,
|
|
163
|
+
y as DEFAULT_READ_REGION_MAX_CELLS,
|
|
164
|
+
P as WORKBOOK_INDEX_SCHEMA_VERSION,
|
|
165
|
+
L as buildWorkbookIndex,
|
|
166
|
+
Y as buildWorkbookIndexFromXlsxBuffer,
|
|
167
|
+
b as extractCellPrimitive,
|
|
168
|
+
V as fromXLSX,
|
|
169
|
+
R as loadWorkbookFromXlsxBuffer,
|
|
170
|
+
K as readIslandRegion,
|
|
171
|
+
$ as readSheetRegion
|
|
172
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphysdk/data-import-utils",
|
|
3
3
|
"author": "Graphy",
|
|
4
|
-
"
|
|
4
|
+
"description": "Parse CSV/TSV/JSON/spreadsheets into Graphy { columns, rows } data",
|
|
5
|
+
"homepage": "https://docs.graphy.dev/data-import-utils",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"graphy",
|
|
9
|
+
"csv",
|
|
10
|
+
"xlsx",
|
|
11
|
+
"spreadsheet",
|
|
12
|
+
"data-import",
|
|
13
|
+
"parser"
|
|
14
|
+
],
|
|
15
|
+
"version": "1.8.1-beta.1786024899180",
|
|
5
16
|
"type": "module",
|
|
6
17
|
"sideEffects": false,
|
|
7
18
|
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"LICENSE.md",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
8
24
|
"exports": {
|
|
9
25
|
".": {
|
|
10
26
|
"types": "./dist/index.d.ts",
|
|
@@ -12,52 +28,52 @@
|
|
|
12
28
|
"require": "./dist/index.cjs"
|
|
13
29
|
},
|
|
14
30
|
"./csv": {
|
|
15
|
-
"types": "./dist/csv.d.ts",
|
|
31
|
+
"types": "./dist/index-csv.d.ts",
|
|
16
32
|
"import": "./dist/csv.mjs",
|
|
17
33
|
"require": "./dist/csv.cjs"
|
|
18
34
|
},
|
|
19
35
|
"./tsv": {
|
|
20
|
-
"types": "./dist/tsv.d.ts",
|
|
36
|
+
"types": "./dist/index-tsv.d.ts",
|
|
21
37
|
"import": "./dist/tsv.mjs",
|
|
22
38
|
"require": "./dist/tsv.cjs"
|
|
23
39
|
},
|
|
24
40
|
"./json": {
|
|
25
|
-
"types": "./dist/json.d.ts",
|
|
41
|
+
"types": "./dist/index-json.d.ts",
|
|
26
42
|
"import": "./dist/json.mjs",
|
|
27
43
|
"require": "./dist/json.cjs"
|
|
28
44
|
},
|
|
29
45
|
"./xlsx": {
|
|
30
|
-
"types": "./dist/xlsx.d.ts",
|
|
46
|
+
"types": "./dist/index-xlsx.d.ts",
|
|
31
47
|
"import": "./dist/xlsx.mjs",
|
|
32
48
|
"require": "./dist/xlsx.cjs"
|
|
33
49
|
},
|
|
34
50
|
"./xls": {
|
|
35
|
-
"types": "./dist/xls.d.ts",
|
|
51
|
+
"types": "./dist/index-xls.d.ts",
|
|
36
52
|
"import": "./dist/xls.mjs",
|
|
37
53
|
"require": "./dist/xls.cjs"
|
|
38
54
|
},
|
|
39
55
|
"./ods": {
|
|
40
|
-
"types": "./dist/ods.d.ts",
|
|
56
|
+
"types": "./dist/index-ods.d.ts",
|
|
41
57
|
"import": "./dist/ods.mjs",
|
|
42
58
|
"require": "./dist/ods.cjs"
|
|
43
59
|
},
|
|
44
60
|
"./file": {
|
|
45
|
-
"types": "./dist/file.d.ts",
|
|
61
|
+
"types": "./dist/index-file.d.ts",
|
|
46
62
|
"import": "./dist/file.mjs",
|
|
47
63
|
"require": "./dist/file.cjs"
|
|
48
64
|
},
|
|
49
65
|
"./url": {
|
|
50
|
-
"types": "./dist/url.d.ts",
|
|
66
|
+
"types": "./dist/index-url.d.ts",
|
|
51
67
|
"import": "./dist/url.mjs",
|
|
52
68
|
"require": "./dist/url.cjs"
|
|
53
69
|
},
|
|
54
70
|
"./text": {
|
|
55
|
-
"types": "./dist/text.d.ts",
|
|
71
|
+
"types": "./dist/index-text.d.ts",
|
|
56
72
|
"import": "./dist/text.mjs",
|
|
57
73
|
"require": "./dist/text.cjs"
|
|
58
74
|
},
|
|
59
75
|
"./buffer": {
|
|
60
|
-
"types": "./dist/buffer.d.ts",
|
|
76
|
+
"types": "./dist/index-buffer.d.ts",
|
|
61
77
|
"import": "./dist/buffer.mjs",
|
|
62
78
|
"require": "./dist/buffer.cjs"
|
|
63
79
|
}
|
|
@@ -65,70 +81,68 @@
|
|
|
65
81
|
"typesVersions": {
|
|
66
82
|
"*": {
|
|
67
83
|
"csv": [
|
|
68
|
-
"dist/csv.d.ts"
|
|
84
|
+
"dist/index-csv.d.ts"
|
|
69
85
|
],
|
|
70
86
|
"tsv": [
|
|
71
|
-
"dist/tsv.d.ts"
|
|
87
|
+
"dist/index-tsv.d.ts"
|
|
72
88
|
],
|
|
73
89
|
"json": [
|
|
74
|
-
"dist/json.d.ts"
|
|
90
|
+
"dist/index-json.d.ts"
|
|
75
91
|
],
|
|
76
92
|
"xlsx": [
|
|
77
|
-
"dist/xlsx.d.ts"
|
|
93
|
+
"dist/index-xlsx.d.ts"
|
|
78
94
|
],
|
|
79
95
|
"xls": [
|
|
80
|
-
"dist/xls.d.ts"
|
|
96
|
+
"dist/index-xls.d.ts"
|
|
81
97
|
],
|
|
82
98
|
"ods": [
|
|
83
|
-
"dist/ods.d.ts"
|
|
99
|
+
"dist/index-ods.d.ts"
|
|
84
100
|
],
|
|
85
101
|
"file": [
|
|
86
|
-
"dist/file.d.ts"
|
|
102
|
+
"dist/index-file.d.ts"
|
|
87
103
|
],
|
|
88
104
|
"url": [
|
|
89
|
-
"dist/url.d.ts"
|
|
105
|
+
"dist/index-url.d.ts"
|
|
90
106
|
],
|
|
91
107
|
"text": [
|
|
92
|
-
"dist/text.d.ts"
|
|
108
|
+
"dist/index-text.d.ts"
|
|
93
109
|
],
|
|
94
110
|
"buffer": [
|
|
95
|
-
"dist/buffer.d.ts"
|
|
111
|
+
"dist/index-buffer.d.ts"
|
|
96
112
|
]
|
|
97
113
|
}
|
|
98
114
|
},
|
|
99
115
|
"dependencies": {
|
|
100
116
|
"exceljs": "^4.4.0",
|
|
101
|
-
"papaparse": "^5.5.2"
|
|
102
|
-
"@graphysdk/core": "1.8.0"
|
|
117
|
+
"papaparse": "^5.5.2"
|
|
103
118
|
},
|
|
104
119
|
"devDependencies": {
|
|
105
|
-
"@
|
|
106
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
107
|
-
"@rollup/plugin-terser": "^1.0.0",
|
|
108
|
-
"@rollup/plugin-typescript": "^12.1.4",
|
|
120
|
+
"@types/node": "^24.1.0",
|
|
109
121
|
"@types/papaparse": "^5.3.15",
|
|
110
|
-
"rollup": "^4.59.0",
|
|
111
|
-
"rollup-plugin-clear": "^2.0.7",
|
|
112
|
-
"rollup-plugin-copy": "^3.5.0",
|
|
113
|
-
"rollup-plugin-dts": "^6.2.3",
|
|
114
122
|
"rollup-plugin-node-externals": "^8.1.1",
|
|
115
123
|
"tslib": "^2.8.1",
|
|
124
|
+
"vite": "^8.1.5",
|
|
125
|
+
"vite-plugin-dts": "^4.5.4",
|
|
116
126
|
"vitest": "^4.1.0",
|
|
117
|
-
"@graphysdk/core": "1.8.0",
|
|
118
127
|
"@graphytools/eslint-config": "0.0.1",
|
|
128
|
+
"@graphytools/eslint-plugin-graphy": "1.0.0",
|
|
119
129
|
"@graphytools/typescript-config": "0.0.1",
|
|
120
130
|
"@graphytools/vitest-config": "1.0.0"
|
|
121
131
|
},
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
132
|
+
"lint-staged": {
|
|
133
|
+
"*.{ts,tsx,js,jsx,json,css,md}": [
|
|
134
|
+
"prettier --write"
|
|
135
|
+
],
|
|
136
|
+
"*.{ts,tsx}": [
|
|
137
|
+
"eslint --max-warnings=0 --fix"
|
|
138
|
+
]
|
|
139
|
+
},
|
|
126
140
|
"scripts": {
|
|
127
|
-
"build": "
|
|
128
|
-
"build:dev": "rollup -c --watch",
|
|
141
|
+
"build": "vite build",
|
|
129
142
|
"test": "vitest run",
|
|
130
143
|
"test:watch": "TZ=utc vitest",
|
|
131
144
|
"lint": "eslint . --max-warnings 0",
|
|
145
|
+
"lint:fix": "eslint . --fix",
|
|
132
146
|
"format": "prettier --write .",
|
|
133
147
|
"format:check": "prettier --check .",
|
|
134
148
|
"typecheck": "tsc --noEmit"
|
package/dist/README.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# `@graphysdk/data-import-utils`
|
|
2
|
-
|
|
3
|
-
Parse CSV, TSV, and spreadsheet files into the `{ columns, rows }` data shape expected by `@graphysdk/core`.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add @graphysdk/data-import-utils
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### Peer Dependencies
|
|
12
|
-
|
|
13
|
-
`@graphysdk/core` is required:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
pnpm add @graphysdk/core
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
### Parse a file from disk
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { fromFile } from '@graphysdk/data-import-utils/file';
|
|
25
|
-
|
|
26
|
-
const data = await fromFile('sales.csv');
|
|
27
|
-
const data = await fromFile('report.xlsx', { sheet: 'Revenue' });
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Parse from a URL
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import { fromURL } from '@graphysdk/data-import-utils/url';
|
|
34
|
-
|
|
35
|
-
const data = await fromURL('https://example.com/sales.csv');
|
|
36
|
-
const data = await fromURL('https://example.com/report.xlsx', { sheet: 'Revenue' });
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Format-specific imports
|
|
40
|
-
|
|
41
|
-
Each format has a dedicated entrypoint so you only bundle what you need:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
import { fromCSV } from '@graphysdk/data-import-utils/csv';
|
|
45
|
-
import { fromTSV } from '@graphysdk/data-import-utils/tsv';
|
|
46
|
-
import { fromXLSX } from '@graphysdk/data-import-utils/xlsx';
|
|
47
|
-
import { fromXLS } from '@graphysdk/data-import-utils/xls';
|
|
48
|
-
import { fromODS } from '@graphysdk/data-import-utils/ods';
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Feeding into `generateGraph()`
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
import { fromFile } from '@graphysdk/data-import-utils/file';
|
|
55
|
-
import { GraphyAiSdk } from '@graphysdk/agents-sdk';
|
|
56
|
-
|
|
57
|
-
const data = await fromFile('revenue.csv');
|
|
58
|
-
|
|
59
|
-
const ai = new GraphyAiSdk({ apiKey: process.env.GRAPHY_API_KEY });
|
|
60
|
-
const result = await ai.generateGraph({
|
|
61
|
-
config: { data },
|
|
62
|
-
userPrompt: 'bar chart of revenue by company',
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Supported Formats
|
|
67
|
-
|
|
68
|
-
| Format | Function | Input type |
|
|
69
|
-
| ------ | ------------ | ------------- |
|
|
70
|
-
| CSV | `fromCSV()` | `string` |
|
|
71
|
-
| TSV | `fromTSV()` | `string` |
|
|
72
|
-
| XLSX | `fromXLSX()` | `ArrayBuffer` |
|
|
73
|
-
| XLS | `fromXLS()` | `ArrayBuffer` |
|
|
74
|
-
| ODS | `fromODS()` | `ArrayBuffer` |
|
|
75
|
-
|
|
76
|
-
## Docs
|
|
77
|
-
|
|
78
|
-
Full documentation: [https://docs.graphy.app/data-import-utils](https://docs.graphy.app/data-import-utils)
|
package/dist/buffer.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { VizLocale, GraphConfig } from '@graphysdk/core/node';
|
|
2
|
-
|
|
3
|
-
/** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
|
|
4
|
-
type Data = GraphConfig['data'];
|
|
5
|
-
/** Binary formats that accept ArrayBuffer input. */
|
|
6
|
-
type BinaryFileFormat = 'xlsx' | 'xls' | 'ods';
|
|
7
|
-
/** Shared base options for all parsers. */
|
|
8
|
-
interface BaseParseOptions {
|
|
9
|
-
/** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
|
|
10
|
-
locale?: VizLocale;
|
|
11
|
-
/** Maximum allowed input size in megabytes. @default 5 */
|
|
12
|
-
maxFileSize?: number;
|
|
13
|
-
}
|
|
14
|
-
/** Options for XLSX / XLS / ODS parsing. */
|
|
15
|
-
interface SpreadsheetParseOptions extends BaseParseOptions {
|
|
16
|
-
/** Sheet to parse — name (string) or 0-based index (number). @default 0 (first sheet) */
|
|
17
|
-
sheet?: string | number;
|
|
18
|
-
/** Maximum number of data rows to process. @default 100_000 */
|
|
19
|
-
maxRows?: number;
|
|
20
|
-
/** Maximum total cells to process. @default 5_000_000 */
|
|
21
|
-
maxCells?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Parses a binary buffer (XLSX, XLS, or ODS) into the `Data` shape expected by `generateGraph()`.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const data = await fromBuffer(xlsxBuffer, 'xlsx');
|
|
30
|
-
* const data = await fromBuffer(odsBuffer, 'ods', { sheet: 'Revenue' });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare const fromBuffer: (input: ArrayBuffer, format: BinaryFileFormat, options?: SpreadsheetParseOptions) => Promise<Data>;
|
|
34
|
-
|
|
35
|
-
export { fromBuffer };
|
|
36
|
-
export type { BaseParseOptions, BinaryFileFormat, Data, SpreadsheetParseOptions };
|
package/dist/csv.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { VizLocale, GraphConfig } from '@graphysdk/core/node';
|
|
2
|
-
|
|
3
|
-
/** The `data` shape returned by all parsers — same as `GraphConfig['data']`. */
|
|
4
|
-
type Data = GraphConfig['data'];
|
|
5
|
-
/** Shared base options for all parsers. */
|
|
6
|
-
interface BaseParseOptions {
|
|
7
|
-
/** Locale for number parsing. Determines thousand/decimal separator conventions. @default 'EN_US' */
|
|
8
|
-
locale?: VizLocale;
|
|
9
|
-
/** Maximum allowed input size in megabytes. @default 5 */
|
|
10
|
-
maxFileSize?: number;
|
|
11
|
-
}
|
|
12
|
-
/** Options for CSV / TSV parsing. */
|
|
13
|
-
interface DelimitedParseOptions extends BaseParseOptions {
|
|
14
|
-
/** Whether the first row contains column headers. @default true */
|
|
15
|
-
hasHeader?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Parses a CSV string into the `Data` shape expected by `generateGraph()`.
|
|
20
|
-
* The delimiter is auto-detected by PapaParse (comma, semicolon, pipe, tab, etc.).
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* const data = fromCSV('Name,Revenue\nAcme,1000\nGlobex,2000');
|
|
25
|
-
* const data = fromCSV('Name;Revenue\nAcme;1000\nGlobex;2000'); // semicolon-delimited
|
|
26
|
-
* sdk.generateGraph({ config: { data }, userPrompt: 'bar chart' });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare const fromCSV: (input: string, options?: DelimitedParseOptions) => Data;
|
|
30
|
-
|
|
31
|
-
export { fromCSV };
|
|
32
|
-
export type { BaseParseOptions, DelimitedParseOptions };
|