@teselagen/file-utils 0.3.15 → 0.3.17
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/{index.mjs → index.cjs} +1743 -6152
- package/index.d.ts +1 -1
- package/index.js +1662 -6071
- package/{index.umd.js → index.umd.cjs} +1643 -6052
- package/package.json +2 -2
- package/src/file-utils.js +14 -3
package/package.json
CHANGED
package/src/file-utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
|
|
2
|
-
import { camelCase, flatMap, remove, startsWith, snakeCase } from "lodash";
|
|
2
|
+
import { camelCase, flatMap, remove, startsWith, snakeCase } from "lodash-es";
|
|
3
3
|
import { loadAsync } from "jszip";
|
|
4
4
|
import Promise from "bluebird";
|
|
5
5
|
import { parse, unparse } from "papaparse";
|
|
@@ -21,7 +21,8 @@ export const isZipFile = file => {
|
|
|
21
21
|
return type === "application/zip" || type === "application/x-zip-compressed";
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export const getExt = file =>
|
|
24
|
+
export const getExt = file =>
|
|
25
|
+
(file?.name || file?.originalname)?.split(".").pop();
|
|
25
26
|
export const isExcelFile = file => getExt(file) === "xlsx";
|
|
26
27
|
export const isCsvFile = file => getExt(file) === "csv";
|
|
27
28
|
export const isTextFile = file => ["text", "txt"].includes(getExt(file));
|
|
@@ -74,7 +75,6 @@ export const extractZipFiles = async allFiles => {
|
|
|
74
75
|
const defaultCsvParserOptions = {
|
|
75
76
|
header: true,
|
|
76
77
|
skipEmptyLines: "greedy",
|
|
77
|
-
trimHeaders: true
|
|
78
78
|
};
|
|
79
79
|
export const setupCsvParserOptions = (parserOptions = {}) => {
|
|
80
80
|
const {
|
|
@@ -122,6 +122,17 @@ export const setupCsvParserOptions = (parserOptions = {}) => {
|
|
|
122
122
|
return transHeader;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
// tnw: the papaparse trimHeaders option was removed so we need to trim headers manually
|
|
126
|
+
const transformToAlwaysRun = header => header.trim();
|
|
127
|
+
if (parserOptions.transformHeader) {
|
|
128
|
+
const existingTransformHeader = parserOptions.transformHeader;
|
|
129
|
+
papaParseOpts.transformHeader = header => {
|
|
130
|
+
const trimmedHeader = transformToAlwaysRun(header);
|
|
131
|
+
return existingTransformHeader(trimmedHeader);
|
|
132
|
+
};
|
|
133
|
+
} else {
|
|
134
|
+
papaParseOpts.transformHeader = transformToAlwaysRun;
|
|
135
|
+
}
|
|
125
136
|
|
|
126
137
|
return papaParseOpts;
|
|
127
138
|
};
|