@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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@teselagen/file-utils",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "dependencies": {
5
5
  "bluebird": "^3.7.2",
6
6
  "jszip": "^3.10.1",
7
- "lodash": "^4.17.21",
7
+ "lodash-es": "^4.17.21",
8
8
  "papaparse": "^5.4.1"
9
9
  },
10
10
  "devDependencies": {
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 => file?.name?.split(".").pop();
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
  };