@punks/backend-core 0.0.19 → 0.0.20
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/dist/cjs/index.js +13 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/csv.d.ts +1 -1
- package/dist/esm/index.js +13 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/csv.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
export declare const csvParseRaw: (data: string | string[] | Buffer, separator
|
|
2
|
+
export declare const csvParseRaw: (data: string | string[] | Buffer, separator?: string) => Record<string, any>[];
|
|
3
3
|
export interface CsvColumnDefinition<T> {
|
|
4
4
|
name: string;
|
|
5
5
|
value: (item: T) => any;
|
package/dist/esm/index.js
CHANGED
|
@@ -211,14 +211,22 @@ const splitRows = (data) => {
|
|
|
211
211
|
}
|
|
212
212
|
return data;
|
|
213
213
|
};
|
|
214
|
-
const csvParseRaw = (data, separator) => {
|
|
214
|
+
const csvParseRaw = (data, separator = DEFAULT_DELIMITER) => {
|
|
215
215
|
const rows = splitRows(data);
|
|
216
216
|
const records = [];
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
if (rows.length === 0) {
|
|
218
|
+
return records;
|
|
219
|
+
}
|
|
220
|
+
const headers = rows[0].split(separator);
|
|
221
|
+
for (let i = 1; i < rows.length; i++) {
|
|
222
|
+
const values = rows[i].split(separator);
|
|
223
|
+
const record = {};
|
|
224
|
+
for (let j = 0; j < headers.length; j++) {
|
|
225
|
+
const header = headers[j];
|
|
226
|
+
const value = values[j];
|
|
227
|
+
record[header] = value;
|
|
221
228
|
}
|
|
229
|
+
records.push(record);
|
|
222
230
|
}
|
|
223
231
|
return records;
|
|
224
232
|
};
|