@loaders.gl/csv 3.1.0-alpha.2 → 3.1.0-beta.1

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.
Files changed (55) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +1501 -5
  4. package/dist/csv-loader.d.ts +34 -0
  5. package/dist/csv-loader.d.ts.map +1 -0
  6. package/dist/csv-loader.js +247 -220
  7. package/dist/csv-writer.d.ts +1 -0
  8. package/dist/csv-writer.d.ts.map +1 -0
  9. package/dist/csv-writer.js +6 -2
  10. package/dist/es5/bundle.js +7 -0
  11. package/dist/es5/bundle.js.map +1 -0
  12. package/dist/es5/csv-loader.js +259 -0
  13. package/dist/es5/csv-loader.js.map +1 -0
  14. package/dist/es5/csv-writer.js +2 -0
  15. package/dist/{csv-writer.js.map → es5/csv-writer.js.map} +0 -0
  16. package/dist/es5/index.js +14 -0
  17. package/dist/es5/index.js.map +1 -0
  18. package/dist/es5/papaparse/async-iterator-streamer.js +47 -0
  19. package/dist/es5/papaparse/async-iterator-streamer.js.map +1 -0
  20. package/{src/libs → dist/es5/papaparse}/papaparse.js +170 -404
  21. package/dist/es5/papaparse/papaparse.js.map +1 -0
  22. package/dist/esm/bundle.js +5 -0
  23. package/dist/esm/bundle.js.map +1 -0
  24. package/dist/esm/csv-loader.js +240 -0
  25. package/dist/esm/csv-loader.js.map +1 -0
  26. package/dist/esm/csv-writer.js +2 -0
  27. package/dist/esm/csv-writer.js.map +1 -0
  28. package/dist/esm/index.js +2 -0
  29. package/dist/esm/index.js.map +1 -0
  30. package/dist/{lib → esm/papaparse}/async-iterator-streamer.js +1 -1
  31. package/dist/esm/papaparse/async-iterator-streamer.js.map +1 -0
  32. package/dist/esm/papaparse/papaparse.js +860 -0
  33. package/dist/esm/papaparse/papaparse.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +5 -2
  37. package/dist/papaparse/async-iterator-streamer.d.ts +6 -0
  38. package/dist/papaparse/async-iterator-streamer.d.ts.map +1 -0
  39. package/dist/papaparse/async-iterator-streamer.js +60 -32
  40. package/dist/papaparse/papaparse.d.ts +30 -0
  41. package/dist/papaparse/papaparse.d.ts.map +1 -0
  42. package/dist/papaparse/papaparse.js +935 -0
  43. package/package.json +8 -8
  44. package/src/bundle.ts +2 -3
  45. package/src/csv-loader.ts +4 -4
  46. package/src/{lib → papaparse}/async-iterator-streamer.ts +2 -2
  47. package/{dist/libs/papaparse.js → src/papaparse/papaparse.ts} +48 -73
  48. package/dist/bundle.js.map +0 -1
  49. package/dist/csv-loader.js.map +0 -1
  50. package/dist/dist.min.js +0 -9
  51. package/dist/dist.min.js.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/lib/async-iterator-streamer.js.map +0 -1
  54. package/dist/papaparse/async-iterator-streamer.js.map +0 -1
  55. package/src/papaparse/async-iterator-streamer.js +0 -71
@@ -0,0 +1,34 @@
1
+ import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
+ import type { Batch } from '@loaders.gl/schema';
3
+ export declare type CSVLoaderOptions = LoaderOptions & {
4
+ csv?: {
5
+ shape?: 'array-row-table' | 'object-row-table' | 'columnar-table';
6
+ /** optimizes memory usage but increases parsing time. */
7
+ optimizeMemoryUsage?: boolean;
8
+ columnPrefix?: string;
9
+ header?: 'auto';
10
+ quoteChar?: string;
11
+ escapeChar?: string;
12
+ dynamicTyping?: boolean;
13
+ comments?: boolean;
14
+ skipEmptyLines?: boolean | 'greedy';
15
+ delimitersToGuess?: string[];
16
+ };
17
+ };
18
+ export declare const CSVLoader: {
19
+ id: string;
20
+ module: string;
21
+ name: string;
22
+ version: any;
23
+ extensions: string[];
24
+ mimeTypes: string[];
25
+ category: string;
26
+ parse: (arrayBuffer: ArrayBuffer, options?: CSVLoaderOptions | undefined) => Promise<any>;
27
+ parseText: (text: string, options?: CSVLoaderOptions | undefined) => Promise<any>;
28
+ parseInBatches: typeof parseCSVInBatches;
29
+ options: CSVLoaderOptions;
30
+ };
31
+ declare function parseCSVInBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: CSVLoaderOptions): AsyncIterable<Batch>;
32
+ export declare const _typecheckCSVLoader: LoaderWithParser;
33
+ export {};
34
+ //# sourceMappingURL=csv-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-loader.d.ts","sourceRoot":"","sources":["../src/csv-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAgB9C,oBAAY,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QAEJ,KAAK,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;QAClE,yDAAyD;QACzD,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAKhB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QAEpB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,cAAc,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;QAEpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAE9B,CAAC;CACH,CAAC;AAsBF,eAAO,MAAM,SAAS;;;;;;;;yBAQO,WAAW;sBAEpB,MAAM;;;CAKzB,CAAC;AAsDF,iBAAS,iBAAiB,CACxB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,OAAO,CAAC,EAAE,gBAAgB,GACzB,aAAa,CAAC,KAAK,CAAC,CAoHtB;AAgFD,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
@@ -1,240 +1,267 @@
1
- import { AsyncQueue, TableBatchBuilder, convertToArrayRow, convertToObjectRow } from '@loaders.gl/schema';
2
- import Papa from './libs/papaparse';
3
- import AsyncIteratorStreamer from './lib/async-iterator-streamer';
4
- const VERSION = typeof "3.1.0-alpha.2" !== 'undefined' ? "3.1.0-alpha.2" : 'latest';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._typecheckCSVLoader = exports.CSVLoader = void 0;
7
+ const schema_1 = require("@loaders.gl/schema");
8
+ const papaparse_1 = __importDefault(require("./papaparse/papaparse"));
9
+ const async_iterator_streamer_1 = __importDefault(require("./papaparse/async-iterator-streamer"));
10
+ // __VERSION__ is injected by babel-plugin-version-inline
11
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
12
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
5
13
  const DEFAULT_CSV_LOADER_OPTIONS = {
6
- csv: {
7
- shape: 'object-row-table',
8
- optimizeMemoryUsage: false,
9
- header: 'auto',
10
- columnPrefix: 'column',
11
- quoteChar: '"',
12
- escapeChar: '"',
13
- dynamicTyping: true,
14
- comments: false,
15
- skipEmptyLines: true,
16
- delimitersToGuess: [',', '\t', '|', ';']
17
- }
14
+ csv: {
15
+ shape: 'object-row-table',
16
+ optimizeMemoryUsage: false,
17
+ // CSV options
18
+ header: 'auto',
19
+ columnPrefix: 'column',
20
+ // delimiter: auto
21
+ // newline: auto
22
+ quoteChar: '"',
23
+ escapeChar: '"',
24
+ dynamicTyping: true,
25
+ comments: false,
26
+ skipEmptyLines: true,
27
+ // transform: null?
28
+ delimitersToGuess: [',', '\t', '|', ';']
29
+ // fastMode: auto
30
+ }
18
31
  };
19
- export const CSVLoader = {
20
- id: 'csv',
21
- module: 'csv',
22
- name: 'CSV',
23
- version: VERSION,
24
- extensions: ['csv'],
25
- mimeTypes: ['text/csv'],
26
- category: 'table',
27
- parse: async (arrayBuffer, options) => parseCSV(new TextDecoder().decode(arrayBuffer), options),
28
- parseText: (text, options) => parseCSV(text, options),
29
- parseInBatches: parseCSVInBatches,
30
- options: DEFAULT_CSV_LOADER_OPTIONS
32
+ exports.CSVLoader = {
33
+ id: 'csv',
34
+ module: 'csv',
35
+ name: 'CSV',
36
+ version: VERSION,
37
+ extensions: ['csv', 'tsv', 'dsv'],
38
+ mimeTypes: ['text/csv', 'text/tab-separated-values', 'text/dsv'],
39
+ category: 'table',
40
+ parse: async (arrayBuffer, options) => parseCSV(new TextDecoder().decode(arrayBuffer), options),
41
+ parseText: (text, options) => parseCSV(text, options),
42
+ parseInBatches: parseCSVInBatches,
43
+ // @ts-ignore
44
+ // testText: null,
45
+ options: DEFAULT_CSV_LOADER_OPTIONS
31
46
  };
32
-
33
47
  async function parseCSV(csvText, options) {
34
- const csvOptions = { ...DEFAULT_CSV_LOADER_OPTIONS.csv,
35
- ...(options === null || options === void 0 ? void 0 : options.csv)
36
- };
37
- const firstRow = readFirstRow(csvText);
38
- const header = csvOptions.header === 'auto' ? isHeaderRow(firstRow) : Boolean(csvOptions.header);
39
- const parseWithHeader = header;
40
- const papaparseConfig = { ...csvOptions,
41
- header: parseWithHeader,
42
- download: false,
43
- transformHeader: parseWithHeader ? duplicateColumnTransformer() : undefined,
44
- error: e => {
45
- throw new Error(e);
48
+ // Apps can call the parse method directly, we so apply default options here
49
+ const csvOptions = { ...DEFAULT_CSV_LOADER_OPTIONS.csv, ...options?.csv };
50
+ const firstRow = readFirstRow(csvText);
51
+ const header = csvOptions.header === 'auto' ? isHeaderRow(firstRow) : Boolean(csvOptions.header);
52
+ const parseWithHeader = header;
53
+ const papaparseConfig = {
54
+ // dynamicTyping: true,
55
+ ...csvOptions,
56
+ header: parseWithHeader,
57
+ download: false,
58
+ transformHeader: parseWithHeader ? duplicateColumnTransformer() : undefined,
59
+ error: (e) => {
60
+ throw new Error(e);
61
+ }
62
+ };
63
+ const result = papaparse_1.default.parse(csvText, papaparseConfig);
64
+ let { data: rows } = result;
65
+ const headerRow = result.meta.fields || generateHeader(csvOptions.columnPrefix, firstRow.length);
66
+ switch (csvOptions.shape) {
67
+ case 'object-row-table':
68
+ rows = rows.map((row) => (Array.isArray(row) ? (0, schema_1.convertToObjectRow)(row, headerRow) : row));
69
+ break;
70
+ case 'array-row-table':
71
+ rows = rows.map((row) => (Array.isArray(row) ? row : (0, schema_1.convertToArrayRow)(row, headerRow)));
72
+ break;
73
+ default:
74
+ }
75
+ /*
76
+ if (!header && shape === 'object-row-table') {
77
+ // If the dataset has no header, transform the array result into an object shape with an
78
+ // autogenerated header
79
+ return result.data.map((row) =>
80
+ row.reduce((acc, value, i) => {
81
+ acc[headerRow[i]] = value;
82
+ return acc;
83
+ }, {})
84
+ );
46
85
  }
47
- };
48
- const result = Papa.parse(csvText, papaparseConfig);
49
- let {
50
- data: rows
51
- } = result;
52
- const headerRow = result.meta.fields || generateHeader(csvOptions.columnPrefix, firstRow.length);
53
-
54
- switch (csvOptions.shape) {
55
- case 'object-row-table':
56
- rows = rows.map(row => Array.isArray(row) ? convertToObjectRow(row, headerRow) : row);
57
- break;
58
-
59
- case 'array-row-table':
60
- rows = rows.map(row => Array.isArray(row) ? row : convertToArrayRow(row, headerRow));
61
- break;
62
-
63
- default:
64
- }
65
-
66
- return rows;
86
+ */
87
+ return rows;
67
88
  }
68
-
89
+ // TODO - support batch size 0 = no batching/single batch?
69
90
  function parseCSVInBatches(asyncIterator, options) {
70
- var _options;
71
-
72
- options = { ...options
73
- };
74
-
75
- if (options.batchSize === 'auto') {
76
- options.batchSize = 4000;
77
- }
78
-
79
- const csvOptions = { ...DEFAULT_CSV_LOADER_OPTIONS.csv,
80
- ...((_options = options) === null || _options === void 0 ? void 0 : _options.csv)
81
- };
82
- const asyncQueue = new AsyncQueue();
83
- let isFirstRow = true;
84
- let headerRow = null;
85
- let tableBatchBuilder = null;
86
- let schema = null;
87
- const config = { ...csvOptions,
88
- header: false,
89
- download: false,
90
- chunkSize: 1024 * 1024 * 5,
91
- skipEmptyLines: false,
92
-
93
- step(results) {
94
- let row = results.data;
95
-
96
- if (csvOptions.skipEmptyLines) {
97
- const collapsedRow = row.flat().join('').trim();
98
-
99
- if (collapsedRow === '') {
100
- return;
101
- }
102
- }
103
-
104
- const bytesUsed = results.meta.cursor;
105
-
106
- if (isFirstRow && !headerRow) {
107
- const header = csvOptions.header === 'auto' ? isHeaderRow(row) : Boolean(csvOptions.header);
108
-
109
- if (header) {
110
- headerRow = row.map(duplicateColumnTransformer());
111
- return;
112
- }
113
- }
114
-
115
- if (isFirstRow) {
116
- isFirstRow = false;
117
-
118
- if (!headerRow) {
119
- headerRow = generateHeader(csvOptions.columnPrefix, row.length);
120
- }
121
-
122
- schema = deduceSchema(row, headerRow);
123
- }
124
-
125
- if (csvOptions.optimizeMemoryUsage) {
126
- row = JSON.parse(JSON.stringify(row));
127
- }
128
-
129
- tableBatchBuilder = tableBatchBuilder || new TableBatchBuilder(schema, {
130
- shape: csvOptions.shape || 'array-row-table',
131
- ...options
132
- });
133
-
134
- try {
135
- tableBatchBuilder.addRow(row);
136
- const batch = tableBatchBuilder && tableBatchBuilder.getFullBatch({
137
- bytesUsed
138
- });
139
-
140
- if (batch) {
141
- asyncQueue.enqueue(batch);
142
- }
143
- } catch (error) {
144
- asyncQueue.enqueue(error);
145
- }
146
- },
147
-
148
- complete(results) {
149
- try {
150
- const bytesUsed = results.meta.cursor;
151
- const batch = tableBatchBuilder && tableBatchBuilder.getFinalBatch({
152
- bytesUsed
153
- });
154
-
155
- if (batch) {
156
- asyncQueue.enqueue(batch);
157
- }
158
- } catch (error) {
159
- asyncQueue.enqueue(error);
160
- }
161
-
162
- asyncQueue.close();
91
+ // Papaparse does not support standard batch size handling
92
+ // TODO - investigate papaparse chunks mode
93
+ options = { ...options };
94
+ if (options.batchSize === 'auto') {
95
+ options.batchSize = 4000;
163
96
  }
164
-
165
- };
166
- Papa.parse(asyncIterator, config, AsyncIteratorStreamer);
167
- return asyncQueue;
97
+ // Apps can call the parse method directly, we so apply default options here
98
+ const csvOptions = { ...DEFAULT_CSV_LOADER_OPTIONS.csv, ...options?.csv };
99
+ const asyncQueue = new schema_1.AsyncQueue();
100
+ let isFirstRow = true;
101
+ let headerRow = null;
102
+ let tableBatchBuilder = null;
103
+ let schema = null;
104
+ const config = {
105
+ // dynamicTyping: true, // Convert numbers and boolean values in rows from strings,
106
+ ...csvOptions,
107
+ header: false,
108
+ download: false,
109
+ // chunkSize is set to 5MB explicitly (same as Papaparse default) due to a bug where the
110
+ // streaming parser gets stuck if skipEmptyLines and a step callback are both supplied.
111
+ // See https://github.com/mholt/PapaParse/issues/465
112
+ chunkSize: 1024 * 1024 * 5,
113
+ // skipEmptyLines is set to a boolean value if supplied. Greedy is set to true
114
+ // skipEmptyLines is handled manually given two bugs where the streaming parser gets stuck if
115
+ // both of the skipEmptyLines and step callback options are provided:
116
+ // - true doesn't work unless chunkSize is set: https://github.com/mholt/PapaParse/issues/465
117
+ // - greedy doesn't work: https://github.com/mholt/PapaParse/issues/825
118
+ skipEmptyLines: false,
119
+ // step is called on every row
120
+ // eslint-disable-next-line complexity
121
+ step(results) {
122
+ let row = results.data;
123
+ if (csvOptions.skipEmptyLines) {
124
+ // Manually reject lines that are empty
125
+ const collapsedRow = row.flat().join('').trim();
126
+ if (collapsedRow === '') {
127
+ return;
128
+ }
129
+ }
130
+ const bytesUsed = results.meta.cursor;
131
+ // Check if we need to save a header row
132
+ if (isFirstRow && !headerRow) {
133
+ // Auto detects or can be forced with csvOptions.header
134
+ const header = csvOptions.header === 'auto' ? isHeaderRow(row) : Boolean(csvOptions.header);
135
+ if (header) {
136
+ headerRow = row.map(duplicateColumnTransformer());
137
+ return;
138
+ }
139
+ }
140
+ // If first data row, we can deduce the schema
141
+ if (isFirstRow) {
142
+ isFirstRow = false;
143
+ if (!headerRow) {
144
+ headerRow = generateHeader(csvOptions.columnPrefix, row.length);
145
+ }
146
+ schema = deduceSchema(row, headerRow);
147
+ }
148
+ if (csvOptions.optimizeMemoryUsage) {
149
+ // A workaround to allocate new strings and don't retain pointers to original strings.
150
+ // https://bugs.chromium.org/p/v8/issues/detail?id=2869
151
+ row = JSON.parse(JSON.stringify(row));
152
+ }
153
+ // Add the row
154
+ tableBatchBuilder =
155
+ tableBatchBuilder ||
156
+ new schema_1.TableBatchBuilder(schema, {
157
+ // @ts-expect-error
158
+ shape: csvOptions.shape || 'array-row-table',
159
+ ...options
160
+ });
161
+ try {
162
+ tableBatchBuilder.addRow(row);
163
+ // If a batch has been completed, emit it
164
+ const batch = tableBatchBuilder && tableBatchBuilder.getFullBatch({ bytesUsed });
165
+ if (batch) {
166
+ asyncQueue.enqueue(batch);
167
+ }
168
+ }
169
+ catch (error) {
170
+ asyncQueue.enqueue(error);
171
+ }
172
+ },
173
+ // complete is called when all rows have been read
174
+ complete(results) {
175
+ try {
176
+ const bytesUsed = results.meta.cursor;
177
+ // Ensure any final (partial) batch gets emitted
178
+ const batch = tableBatchBuilder && tableBatchBuilder.getFinalBatch({ bytesUsed });
179
+ if (batch) {
180
+ asyncQueue.enqueue(batch);
181
+ }
182
+ }
183
+ catch (error) {
184
+ asyncQueue.enqueue(error);
185
+ }
186
+ asyncQueue.close();
187
+ }
188
+ };
189
+ papaparse_1.default.parse(asyncIterator, config, async_iterator_streamer_1.default);
190
+ // TODO - Does it matter if we return asyncIterable or asyncIterator
191
+ // return asyncQueue[Symbol.asyncIterator]();
192
+ return asyncQueue;
168
193
  }
169
-
194
+ /**
195
+ * Checks if a certain row is a header row
196
+ * @param row the row to check
197
+ * @returns true if the row looks like a header
198
+ */
170
199
  function isHeaderRow(row) {
171
- return row && row.every(value => typeof value === 'string');
200
+ return row && row.every((value) => typeof value === 'string');
172
201
  }
173
-
202
+ /**
203
+ * Reads, parses, and returns the first row of a CSV text
204
+ * @param csvText the csv text to parse
205
+ * @returns the first row
206
+ */
174
207
  function readFirstRow(csvText) {
175
- const result = Papa.parse(csvText, {
176
- download: false,
177
- dynamicTyping: true,
178
- preview: 1
179
- });
180
- return result.data[0];
208
+ const result = papaparse_1.default.parse(csvText, {
209
+ download: false,
210
+ dynamicTyping: true,
211
+ preview: 1
212
+ });
213
+ return result.data[0];
181
214
  }
182
-
215
+ /**
216
+ * Creates a transformer that renames duplicate columns. This is needed as Papaparse doesn't handle
217
+ * duplicate header columns and would use the latest occurrence by default.
218
+ * See the header option in https://www.papaparse.com/docs#config
219
+ * @returns a transform function that returns sanitized names for duplicate fields
220
+ */
183
221
  function duplicateColumnTransformer() {
184
- const observedColumns = new Set();
185
- return col => {
186
- let colName = col;
187
- let counter = 1;
188
-
189
- while (observedColumns.has(colName)) {
190
- colName = `${col}.${counter}`;
191
- counter++;
192
- }
193
-
194
- observedColumns.add(colName);
195
- return colName;
196
- };
222
+ const observedColumns = new Set();
223
+ return (col) => {
224
+ let colName = col;
225
+ let counter = 1;
226
+ while (observedColumns.has(colName)) {
227
+ colName = `${col}.${counter}`;
228
+ counter++;
229
+ }
230
+ observedColumns.add(colName);
231
+ return colName;
232
+ };
197
233
  }
198
-
234
+ /**
235
+ * Generates the header of a CSV given a prefix and a column count
236
+ * @param columnPrefix the columnPrefix to use
237
+ * @param count the count of column names to generate
238
+ * @returns an array of column names
239
+ */
199
240
  function generateHeader(columnPrefix, count = 0) {
200
- const headers = [];
201
-
202
- for (let i = 0; i < count; i++) {
203
- headers.push(`${columnPrefix}${i + 1}`);
204
- }
205
-
206
- return headers;
241
+ const headers = [];
242
+ for (let i = 0; i < count; i++) {
243
+ headers.push(`${columnPrefix}${i + 1}`);
244
+ }
245
+ return headers;
207
246
  }
208
-
209
247
  function deduceSchema(row, headerRow) {
210
- const schema = headerRow ? {} : [];
211
-
212
- for (let i = 0; i < row.length; i++) {
213
- const columnName = headerRow && headerRow[i] || i;
214
- const value = row[i];
215
-
216
- switch (typeof value) {
217
- case 'number':
218
- case 'boolean':
219
- schema[columnName] = {
220
- name: String(columnName),
221
- index: i,
222
- type: Float32Array
223
- };
224
- break;
225
-
226
- case 'string':
227
- default:
228
- schema[columnName] = {
229
- name: String(columnName),
230
- index: i,
231
- type: Array
232
- };
248
+ const schema = headerRow ? {} : [];
249
+ for (let i = 0; i < row.length; i++) {
250
+ const columnName = (headerRow && headerRow[i]) || i;
251
+ const value = row[i];
252
+ switch (typeof value) {
253
+ case 'number':
254
+ case 'boolean':
255
+ // TODO - booleans could be handled differently...
256
+ schema[columnName] = { name: String(columnName), index: i, type: Float32Array };
257
+ break;
258
+ case 'string':
259
+ default:
260
+ schema[columnName] = { name: String(columnName), index: i, type: Array };
261
+ // We currently only handle numeric rows
262
+ // TODO we could offer a function to map strings to numbers?
263
+ }
233
264
  }
234
- }
235
-
236
- return schema;
265
+ return schema;
237
266
  }
238
-
239
- export const _typecheckCSVLoader = CSVLoader;
240
- //# sourceMappingURL=csv-loader.js.map
267
+ exports._typecheckCSVLoader = exports.CSVLoader;
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=csv-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv-writer.d.ts","sourceRoot":"","sources":["../src/csv-writer.ts"],"names":[],"mappings":""}
@@ -1,2 +1,6 @@
1
-
2
- //# sourceMappingURL=csv-writer.js.map
1
+ "use strict";
2
+ /* @typedef {import('@loaders.gl/loader-utils').Writer} Writer */
3
+ /*
4
+ * CSV exporter
5
+ * type {Writer}
6
+ */
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ const moduleExports = require('./index');
4
+
5
+ globalThis.loaders = globalThis.loaders || {};
6
+ module.exports = Object.assign(globalThis.loaders, moduleExports);
7
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}