@teselagen/file-utils 0.2.23 → 0.2.26

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 (4) hide show
  1. package/index.js +37 -37
  2. package/index.mjs +37 -37
  3. package/index.umd.js +37 -37
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -22664,19 +22664,19 @@ var papaparse_minExports = papaparse_min.exports;
22664
22664
 
22665
22665
  /* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
22666
22666
 
22667
- const allowedCsvFileTypes = ['.csv', '.txt', '.xlsx'];
22667
+ const allowedCsvFileTypes = [".csv", ".txt", ".xlsx"];
22668
22668
 
22669
22669
  const isZipFile = (file) => {
22670
- if (getExt(file) === 'zip') return true;
22671
- if (getExt(file) === 'geneious') return false;
22670
+ if (getExt(file) === "zip") return true;
22671
+ if (getExt(file) === "geneious") return false;
22672
22672
  const type = file.mimetype || file.type;
22673
- return type === 'application/zip' || type === 'application/x-zip-compressed';
22673
+ return type === "application/zip" || type === "application/x-zip-compressed";
22674
22674
  };
22675
22675
 
22676
- const getExt = (file) => file?.name?.split('.').pop();
22677
- const isExcelFile = (file) => getExt(file) === 'xlsx';
22678
- const isCsvFile = (file) => getExt(file) === 'csv';
22679
- const isTextFile = (file) => ['text', 'txt'].includes(getExt(file));
22676
+ const getExt = (file) => file?.name?.split(".").pop();
22677
+ const isExcelFile = (file) => getExt(file) === "xlsx";
22678
+ const isCsvFile = (file) => getExt(file) === "csv";
22679
+ const isTextFile = (file) => ["text", "txt"].includes(getExt(file));
22680
22680
 
22681
22681
  const isCsvOrExcelFile = (file) => isCsvFile(file) || isExcelFile(file);
22682
22682
 
@@ -22695,12 +22695,12 @@ const extractZipFiles = async (allFiles) => {
22695
22695
  );
22696
22696
  const unzippedFiles = await Promise$1.map(zippedFiles, (file) => {
22697
22697
  // converts the compressed file to a string of its contents
22698
- return file.async('blob').then(function (fileData) {
22698
+ return file.async("blob").then(function (fileData) {
22699
22699
  const newFileObj = new File([fileData], file.name);
22700
22700
  return {
22701
22701
  name: file.name,
22702
22702
  originFileObj: newFileObj,
22703
- originalFileObj: newFileObj,
22703
+ originalFileObj: newFileObj
22704
22704
  };
22705
22705
  });
22706
22706
  });
@@ -22708,8 +22708,8 @@ const extractZipFiles = async (allFiles) => {
22708
22708
  return allFiles.concat(
22709
22709
  unzippedFiles.filter(
22710
22710
  ({ name, originFileObj }) =>
22711
- !name.includes('__MACOSX') &&
22712
- !name.includes('.DS_Store') &&
22711
+ !name.includes("__MACOSX") &&
22712
+ !name.includes(".DS_Store") &&
22713
22713
  originFileObj.size !== 0
22714
22714
  )
22715
22715
  );
@@ -22720,8 +22720,8 @@ const extractZipFiles = async (allFiles) => {
22720
22720
 
22721
22721
  const defaultCsvParserOptions = {
22722
22722
  header: true,
22723
- skipEmptyLines: 'greedy',
22724
- trimHeaders: true,
22723
+ skipEmptyLines: "greedy",
22724
+ trimHeaders: true
22725
22725
  };
22726
22726
  const setupCsvParserOptions = (parserOptions = {}) => {
22727
22727
  const {
@@ -22734,7 +22734,7 @@ const setupCsvParserOptions = (parserOptions = {}) => {
22734
22734
  if (camelCaseHeaders) {
22735
22735
  papaParseOpts.transformHeader = (header) => {
22736
22736
  let transHeader = header;
22737
- if (!lodashExports.startsWith(header.trim(), 'ext-')) {
22737
+ if (!lodashExports.startsWith(header.trim(), "ext-")) {
22738
22738
  transHeader = lodashExports.camelCase(header);
22739
22739
  }
22740
22740
 
@@ -22747,7 +22747,7 @@ const setupCsvParserOptions = (parserOptions = {}) => {
22747
22747
  } else if (lowerCaseHeaders) {
22748
22748
  papaParseOpts.transformHeader = (header) => {
22749
22749
  let transHeader = header;
22750
- if (!lodashExports.startsWith(header, 'ext-')) {
22750
+ if (!lodashExports.startsWith(header, "ext-")) {
22751
22751
  transHeader = header.toLowerCase();
22752
22752
  }
22753
22753
 
@@ -22766,7 +22766,7 @@ const normalizeCsvHeaderHelper = (h) =>
22766
22766
  lodashExports.snakeCase(h.toUpperCase()).toUpperCase();
22767
22767
 
22768
22768
  function normalizeCsvHeader(header) {
22769
- if (header.startsWith('ext-') || header.startsWith('EXT-')) {
22769
+ if (header.startsWith("ext-") || header.startsWith("EXT-")) {
22770
22770
  return header;
22771
22771
  }
22772
22772
  return normalizeCsvHeaderHelper(header);
@@ -22787,13 +22787,13 @@ const parseCsvFile = (csvFile, parserOptions = {}) => {
22787
22787
  ) {
22788
22788
  return resolve(results);
22789
22789
  } else if (results && results.errors && results.errors.length) {
22790
- return reject('Error in csv: ' + JSON.stringify(results.errors));
22790
+ return reject("Error in csv: " + JSON.stringify(results.errors));
22791
22791
  }
22792
22792
  return resolve(results);
22793
22793
  },
22794
22794
  error: (error) => {
22795
22795
  reject(error);
22796
- },
22796
+ }
22797
22797
  };
22798
22798
  papaparse_minExports.parse(csvFile.originFileObj, opts);
22799
22799
  });
@@ -22822,7 +22822,7 @@ const jsonToCsv = (jsonData, options = {}) => {
22822
22822
  const parseCsvString = (csvString, parserOptions = {}) => {
22823
22823
  const opts = {
22824
22824
  ...defaultCsvParserOptions,
22825
- ...setupCsvParserOptions(parserOptions),
22825
+ ...setupCsvParserOptions(parserOptions)
22826
22826
  };
22827
22827
  return papaparse_minExports.parse(csvString, opts);
22828
22828
  };
@@ -22842,7 +22842,7 @@ async function parseCsvOrExcelFile(
22842
22842
  else if (isTextFile(fileOrFiles)) txtFile = fileOrFiles;
22843
22843
  }
22844
22844
  if (!csvFile && !excelFile && !txtFile) {
22845
- throw new Error('No csv or excel files found');
22845
+ throw new Error("No csv or excel files found");
22846
22846
  }
22847
22847
 
22848
22848
  if (!csvFile && !excelFile) csvFile = txtFile;
@@ -22855,7 +22855,7 @@ async function parseCsvOrExcelFile(
22855
22855
  throw new Error(csvFile.error);
22856
22856
  }
22857
22857
  } else if (excelFile) {
22858
- throw new Error('Excel Parser not initialized on the window');
22858
+ throw new Error("Excel Parser not initialized on the window");
22859
22859
  }
22860
22860
  const parsedCsv = await parseCsvFile(csvFile, csvParserOptions);
22861
22861
  parsedCsv.originalFile = csvFile;
@@ -22871,9 +22871,9 @@ const validateCSVRequiredHeaders = (
22871
22871
  return !fields.includes(field);
22872
22872
  });
22873
22873
  if (missingRequiredHeaders.length) {
22874
- const name = filename ? `The file ${filename}` : 'CSV file';
22874
+ const name = filename ? `The file ${filename}` : "CSV file";
22875
22875
  return `${name} is missing required headers. (${missingRequiredHeaders.join(
22876
- ', '
22876
+ ", "
22877
22877
  )})`;
22878
22878
  }
22879
22879
  };
@@ -22888,14 +22888,14 @@ const validateCSVRow = (row, requiredHeaders, index) => {
22888
22888
  } else {
22889
22889
  return `Row ${
22890
22890
  index + 1
22891
- } is missing these required fields: ${missingRequiredFields.join(', ')}`;
22891
+ } is missing these required fields: ${missingRequiredFields.join(", ")}`;
22892
22892
  }
22893
22893
  }
22894
22894
  };
22895
22895
 
22896
22896
  const cleanCommaSeparatedCell = (cellData) =>
22897
- (cellData || '')
22898
- .split(',')
22897
+ (cellData || "")
22898
+ .split(",")
22899
22899
  .map((n) => n.trim())
22900
22900
  .filter((n) => n);
22901
22901
 
@@ -22916,7 +22916,7 @@ const cleanCsvExport = (rows) => {
22916
22916
  });
22917
22917
  rows.forEach((row) => {
22918
22918
  allHeaders.forEach((header) => {
22919
- row[header] = row[header] || '';
22919
+ row[header] = row[header] || "";
22920
22920
  });
22921
22921
  });
22922
22922
  return rows;
@@ -22926,7 +22926,7 @@ const filterFilesInZip = async (file, accepted) => {
22926
22926
  const zipExtracted = await extractZipFiles(file);
22927
22927
  const acceptedFiles = [];
22928
22928
  for (const extFile of zipExtracted) {
22929
- if (accepted.some((ext) => ext?.replace(".","") === getExt(extFile))) {
22929
+ if (accepted.some((ext) => ext?.replace(".", "") === getExt(extFile))) {
22930
22930
  acceptedFiles.push(extFile);
22931
22931
  }
22932
22932
  }
@@ -22935,14 +22935,14 @@ const filterFilesInZip = async (file, accepted) => {
22935
22935
  window.toastr.warning("Some files don't have the proper file extension.");
22936
22936
 
22937
22937
  if (!acceptedFiles.length)
22938
- window.toastr.warning('No files with the proper extension were found.');
22938
+ window.toastr.warning("No files with the proper extension were found.");
22939
22939
 
22940
22940
  return acceptedFiles;
22941
22941
  };
22942
22942
 
22943
22943
  function removeExt(filename) {
22944
- if (filename && filename.includes('.')) {
22945
- return filename.split('.').slice(0, -1).join('.');
22944
+ if (filename && filename.includes(".")) {
22945
+ return filename.split(".").slice(0, -1).join(".");
22946
22946
  } else {
22947
22947
  return filename;
22948
22948
  }
@@ -22952,16 +22952,16 @@ async function uploadAndProcessFiles(files = []) {
22952
22952
  if (!files.length) return null;
22953
22953
 
22954
22954
  const formData = new FormData();
22955
- files.forEach(({ originFileObj }) => formData.append('file', originFileObj));
22955
+ files.forEach(({ originFileObj }) => formData.append("file", originFileObj));
22956
22956
 
22957
- const response = await window.api.post('/user_uploads/', formData);
22957
+ const response = await window.api.post("/user_uploads/", formData);
22958
22958
 
22959
22959
  return response.data.map((d) => ({
22960
22960
  encoding: d.encoding,
22961
22961
  mimetype: d.mimetype,
22962
22962
  originalname: d.originalname,
22963
22963
  path: d.path,
22964
- size: d.size,
22964
+ size: d.size
22965
22965
  }));
22966
22966
  }
22967
22967
 
@@ -22969,11 +22969,11 @@ async function encodeFilesForRequest(files) {
22969
22969
  const encodedFiles = [];
22970
22970
  for (const file of files) {
22971
22971
  const encoded = await fileToBase64(file.originalFileObj);
22972
- const data = encoded.split(',');
22972
+ const data = encoded.split(",");
22973
22973
  encodedFiles.push({
22974
22974
  type: file.type,
22975
22975
  base64Data: data[1],
22976
- name: file.name,
22976
+ name: file.name
22977
22977
  });
22978
22978
  }
22979
22979
  return encodedFiles;
package/index.mjs CHANGED
@@ -22660,19 +22660,19 @@ var papaparse_minExports = papaparse_min.exports;
22660
22660
 
22661
22661
  /* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
22662
22662
 
22663
- const allowedCsvFileTypes = ['.csv', '.txt', '.xlsx'];
22663
+ const allowedCsvFileTypes = [".csv", ".txt", ".xlsx"];
22664
22664
 
22665
22665
  const isZipFile = (file) => {
22666
- if (getExt(file) === 'zip') return true;
22667
- if (getExt(file) === 'geneious') return false;
22666
+ if (getExt(file) === "zip") return true;
22667
+ if (getExt(file) === "geneious") return false;
22668
22668
  const type = file.mimetype || file.type;
22669
- return type === 'application/zip' || type === 'application/x-zip-compressed';
22669
+ return type === "application/zip" || type === "application/x-zip-compressed";
22670
22670
  };
22671
22671
 
22672
- const getExt = (file) => file?.name?.split('.').pop();
22673
- const isExcelFile = (file) => getExt(file) === 'xlsx';
22674
- const isCsvFile = (file) => getExt(file) === 'csv';
22675
- const isTextFile = (file) => ['text', 'txt'].includes(getExt(file));
22672
+ const getExt = (file) => file?.name?.split(".").pop();
22673
+ const isExcelFile = (file) => getExt(file) === "xlsx";
22674
+ const isCsvFile = (file) => getExt(file) === "csv";
22675
+ const isTextFile = (file) => ["text", "txt"].includes(getExt(file));
22676
22676
 
22677
22677
  const isCsvOrExcelFile = (file) => isCsvFile(file) || isExcelFile(file);
22678
22678
 
@@ -22691,12 +22691,12 @@ const extractZipFiles = async (allFiles) => {
22691
22691
  );
22692
22692
  const unzippedFiles = await Promise$1.map(zippedFiles, (file) => {
22693
22693
  // converts the compressed file to a string of its contents
22694
- return file.async('blob').then(function (fileData) {
22694
+ return file.async("blob").then(function (fileData) {
22695
22695
  const newFileObj = new File([fileData], file.name);
22696
22696
  return {
22697
22697
  name: file.name,
22698
22698
  originFileObj: newFileObj,
22699
- originalFileObj: newFileObj,
22699
+ originalFileObj: newFileObj
22700
22700
  };
22701
22701
  });
22702
22702
  });
@@ -22704,8 +22704,8 @@ const extractZipFiles = async (allFiles) => {
22704
22704
  return allFiles.concat(
22705
22705
  unzippedFiles.filter(
22706
22706
  ({ name, originFileObj }) =>
22707
- !name.includes('__MACOSX') &&
22708
- !name.includes('.DS_Store') &&
22707
+ !name.includes("__MACOSX") &&
22708
+ !name.includes(".DS_Store") &&
22709
22709
  originFileObj.size !== 0
22710
22710
  )
22711
22711
  );
@@ -22716,8 +22716,8 @@ const extractZipFiles = async (allFiles) => {
22716
22716
 
22717
22717
  const defaultCsvParserOptions = {
22718
22718
  header: true,
22719
- skipEmptyLines: 'greedy',
22720
- trimHeaders: true,
22719
+ skipEmptyLines: "greedy",
22720
+ trimHeaders: true
22721
22721
  };
22722
22722
  const setupCsvParserOptions = (parserOptions = {}) => {
22723
22723
  const {
@@ -22730,7 +22730,7 @@ const setupCsvParserOptions = (parserOptions = {}) => {
22730
22730
  if (camelCaseHeaders) {
22731
22731
  papaParseOpts.transformHeader = (header) => {
22732
22732
  let transHeader = header;
22733
- if (!lodashExports.startsWith(header.trim(), 'ext-')) {
22733
+ if (!lodashExports.startsWith(header.trim(), "ext-")) {
22734
22734
  transHeader = lodashExports.camelCase(header);
22735
22735
  }
22736
22736
 
@@ -22743,7 +22743,7 @@ const setupCsvParserOptions = (parserOptions = {}) => {
22743
22743
  } else if (lowerCaseHeaders) {
22744
22744
  papaParseOpts.transformHeader = (header) => {
22745
22745
  let transHeader = header;
22746
- if (!lodashExports.startsWith(header, 'ext-')) {
22746
+ if (!lodashExports.startsWith(header, "ext-")) {
22747
22747
  transHeader = header.toLowerCase();
22748
22748
  }
22749
22749
 
@@ -22762,7 +22762,7 @@ const normalizeCsvHeaderHelper = (h) =>
22762
22762
  lodashExports.snakeCase(h.toUpperCase()).toUpperCase();
22763
22763
 
22764
22764
  function normalizeCsvHeader(header) {
22765
- if (header.startsWith('ext-') || header.startsWith('EXT-')) {
22765
+ if (header.startsWith("ext-") || header.startsWith("EXT-")) {
22766
22766
  return header;
22767
22767
  }
22768
22768
  return normalizeCsvHeaderHelper(header);
@@ -22783,13 +22783,13 @@ const parseCsvFile = (csvFile, parserOptions = {}) => {
22783
22783
  ) {
22784
22784
  return resolve(results);
22785
22785
  } else if (results && results.errors && results.errors.length) {
22786
- return reject('Error in csv: ' + JSON.stringify(results.errors));
22786
+ return reject("Error in csv: " + JSON.stringify(results.errors));
22787
22787
  }
22788
22788
  return resolve(results);
22789
22789
  },
22790
22790
  error: (error) => {
22791
22791
  reject(error);
22792
- },
22792
+ }
22793
22793
  };
22794
22794
  papaparse_minExports.parse(csvFile.originFileObj, opts);
22795
22795
  });
@@ -22818,7 +22818,7 @@ const jsonToCsv = (jsonData, options = {}) => {
22818
22818
  const parseCsvString = (csvString, parserOptions = {}) => {
22819
22819
  const opts = {
22820
22820
  ...defaultCsvParserOptions,
22821
- ...setupCsvParserOptions(parserOptions),
22821
+ ...setupCsvParserOptions(parserOptions)
22822
22822
  };
22823
22823
  return papaparse_minExports.parse(csvString, opts);
22824
22824
  };
@@ -22838,7 +22838,7 @@ async function parseCsvOrExcelFile(
22838
22838
  else if (isTextFile(fileOrFiles)) txtFile = fileOrFiles;
22839
22839
  }
22840
22840
  if (!csvFile && !excelFile && !txtFile) {
22841
- throw new Error('No csv or excel files found');
22841
+ throw new Error("No csv or excel files found");
22842
22842
  }
22843
22843
 
22844
22844
  if (!csvFile && !excelFile) csvFile = txtFile;
@@ -22851,7 +22851,7 @@ async function parseCsvOrExcelFile(
22851
22851
  throw new Error(csvFile.error);
22852
22852
  }
22853
22853
  } else if (excelFile) {
22854
- throw new Error('Excel Parser not initialized on the window');
22854
+ throw new Error("Excel Parser not initialized on the window");
22855
22855
  }
22856
22856
  const parsedCsv = await parseCsvFile(csvFile, csvParserOptions);
22857
22857
  parsedCsv.originalFile = csvFile;
@@ -22867,9 +22867,9 @@ const validateCSVRequiredHeaders = (
22867
22867
  return !fields.includes(field);
22868
22868
  });
22869
22869
  if (missingRequiredHeaders.length) {
22870
- const name = filename ? `The file ${filename}` : 'CSV file';
22870
+ const name = filename ? `The file ${filename}` : "CSV file";
22871
22871
  return `${name} is missing required headers. (${missingRequiredHeaders.join(
22872
- ', '
22872
+ ", "
22873
22873
  )})`;
22874
22874
  }
22875
22875
  };
@@ -22884,14 +22884,14 @@ const validateCSVRow = (row, requiredHeaders, index) => {
22884
22884
  } else {
22885
22885
  return `Row ${
22886
22886
  index + 1
22887
- } is missing these required fields: ${missingRequiredFields.join(', ')}`;
22887
+ } is missing these required fields: ${missingRequiredFields.join(", ")}`;
22888
22888
  }
22889
22889
  }
22890
22890
  };
22891
22891
 
22892
22892
  const cleanCommaSeparatedCell = (cellData) =>
22893
- (cellData || '')
22894
- .split(',')
22893
+ (cellData || "")
22894
+ .split(",")
22895
22895
  .map((n) => n.trim())
22896
22896
  .filter((n) => n);
22897
22897
 
@@ -22912,7 +22912,7 @@ const cleanCsvExport = (rows) => {
22912
22912
  });
22913
22913
  rows.forEach((row) => {
22914
22914
  allHeaders.forEach((header) => {
22915
- row[header] = row[header] || '';
22915
+ row[header] = row[header] || "";
22916
22916
  });
22917
22917
  });
22918
22918
  return rows;
@@ -22922,7 +22922,7 @@ const filterFilesInZip = async (file, accepted) => {
22922
22922
  const zipExtracted = await extractZipFiles(file);
22923
22923
  const acceptedFiles = [];
22924
22924
  for (const extFile of zipExtracted) {
22925
- if (accepted.some((ext) => ext?.replace(".","") === getExt(extFile))) {
22925
+ if (accepted.some((ext) => ext?.replace(".", "") === getExt(extFile))) {
22926
22926
  acceptedFiles.push(extFile);
22927
22927
  }
22928
22928
  }
@@ -22931,14 +22931,14 @@ const filterFilesInZip = async (file, accepted) => {
22931
22931
  window.toastr.warning("Some files don't have the proper file extension.");
22932
22932
 
22933
22933
  if (!acceptedFiles.length)
22934
- window.toastr.warning('No files with the proper extension were found.');
22934
+ window.toastr.warning("No files with the proper extension were found.");
22935
22935
 
22936
22936
  return acceptedFiles;
22937
22937
  };
22938
22938
 
22939
22939
  function removeExt(filename) {
22940
- if (filename && filename.includes('.')) {
22941
- return filename.split('.').slice(0, -1).join('.');
22940
+ if (filename && filename.includes(".")) {
22941
+ return filename.split(".").slice(0, -1).join(".");
22942
22942
  } else {
22943
22943
  return filename;
22944
22944
  }
@@ -22948,16 +22948,16 @@ async function uploadAndProcessFiles(files = []) {
22948
22948
  if (!files.length) return null;
22949
22949
 
22950
22950
  const formData = new FormData();
22951
- files.forEach(({ originFileObj }) => formData.append('file', originFileObj));
22951
+ files.forEach(({ originFileObj }) => formData.append("file", originFileObj));
22952
22952
 
22953
- const response = await window.api.post('/user_uploads/', formData);
22953
+ const response = await window.api.post("/user_uploads/", formData);
22954
22954
 
22955
22955
  return response.data.map((d) => ({
22956
22956
  encoding: d.encoding,
22957
22957
  mimetype: d.mimetype,
22958
22958
  originalname: d.originalname,
22959
22959
  path: d.path,
22960
- size: d.size,
22960
+ size: d.size
22961
22961
  }));
22962
22962
  }
22963
22963
 
@@ -22965,11 +22965,11 @@ async function encodeFilesForRequest(files) {
22965
22965
  const encodedFiles = [];
22966
22966
  for (const file of files) {
22967
22967
  const encoded = await fileToBase64(file.originalFileObj);
22968
- const data = encoded.split(',');
22968
+ const data = encoded.split(",");
22969
22969
  encodedFiles.push({
22970
22970
  type: file.type,
22971
22971
  base64Data: data[1],
22972
- name: file.name,
22972
+ name: file.name
22973
22973
  });
22974
22974
  }
22975
22975
  return encodedFiles;
package/index.umd.js CHANGED
@@ -22666,19 +22666,19 @@
22666
22666
 
22667
22667
  /* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
22668
22668
 
22669
- const allowedCsvFileTypes = ['.csv', '.txt', '.xlsx'];
22669
+ const allowedCsvFileTypes = [".csv", ".txt", ".xlsx"];
22670
22670
 
22671
22671
  const isZipFile = (file) => {
22672
- if (getExt(file) === 'zip') return true;
22673
- if (getExt(file) === 'geneious') return false;
22672
+ if (getExt(file) === "zip") return true;
22673
+ if (getExt(file) === "geneious") return false;
22674
22674
  const type = file.mimetype || file.type;
22675
- return type === 'application/zip' || type === 'application/x-zip-compressed';
22675
+ return type === "application/zip" || type === "application/x-zip-compressed";
22676
22676
  };
22677
22677
 
22678
- const getExt = (file) => file?.name?.split('.').pop();
22679
- const isExcelFile = (file) => getExt(file) === 'xlsx';
22680
- const isCsvFile = (file) => getExt(file) === 'csv';
22681
- const isTextFile = (file) => ['text', 'txt'].includes(getExt(file));
22678
+ const getExt = (file) => file?.name?.split(".").pop();
22679
+ const isExcelFile = (file) => getExt(file) === "xlsx";
22680
+ const isCsvFile = (file) => getExt(file) === "csv";
22681
+ const isTextFile = (file) => ["text", "txt"].includes(getExt(file));
22682
22682
 
22683
22683
  const isCsvOrExcelFile = (file) => isCsvFile(file) || isExcelFile(file);
22684
22684
 
@@ -22697,12 +22697,12 @@
22697
22697
  );
22698
22698
  const unzippedFiles = await Promise$1.map(zippedFiles, (file) => {
22699
22699
  // converts the compressed file to a string of its contents
22700
- return file.async('blob').then(function (fileData) {
22700
+ return file.async("blob").then(function (fileData) {
22701
22701
  const newFileObj = new File([fileData], file.name);
22702
22702
  return {
22703
22703
  name: file.name,
22704
22704
  originFileObj: newFileObj,
22705
- originalFileObj: newFileObj,
22705
+ originalFileObj: newFileObj
22706
22706
  };
22707
22707
  });
22708
22708
  });
@@ -22710,8 +22710,8 @@
22710
22710
  return allFiles.concat(
22711
22711
  unzippedFiles.filter(
22712
22712
  ({ name, originFileObj }) =>
22713
- !name.includes('__MACOSX') &&
22714
- !name.includes('.DS_Store') &&
22713
+ !name.includes("__MACOSX") &&
22714
+ !name.includes(".DS_Store") &&
22715
22715
  originFileObj.size !== 0
22716
22716
  )
22717
22717
  );
@@ -22722,8 +22722,8 @@
22722
22722
 
22723
22723
  const defaultCsvParserOptions = {
22724
22724
  header: true,
22725
- skipEmptyLines: 'greedy',
22726
- trimHeaders: true,
22725
+ skipEmptyLines: "greedy",
22726
+ trimHeaders: true
22727
22727
  };
22728
22728
  const setupCsvParserOptions = (parserOptions = {}) => {
22729
22729
  const {
@@ -22736,7 +22736,7 @@
22736
22736
  if (camelCaseHeaders) {
22737
22737
  papaParseOpts.transformHeader = (header) => {
22738
22738
  let transHeader = header;
22739
- if (!lodashExports.startsWith(header.trim(), 'ext-')) {
22739
+ if (!lodashExports.startsWith(header.trim(), "ext-")) {
22740
22740
  transHeader = lodashExports.camelCase(header);
22741
22741
  }
22742
22742
 
@@ -22749,7 +22749,7 @@
22749
22749
  } else if (lowerCaseHeaders) {
22750
22750
  papaParseOpts.transformHeader = (header) => {
22751
22751
  let transHeader = header;
22752
- if (!lodashExports.startsWith(header, 'ext-')) {
22752
+ if (!lodashExports.startsWith(header, "ext-")) {
22753
22753
  transHeader = header.toLowerCase();
22754
22754
  }
22755
22755
 
@@ -22768,7 +22768,7 @@
22768
22768
  lodashExports.snakeCase(h.toUpperCase()).toUpperCase();
22769
22769
 
22770
22770
  function normalizeCsvHeader(header) {
22771
- if (header.startsWith('ext-') || header.startsWith('EXT-')) {
22771
+ if (header.startsWith("ext-") || header.startsWith("EXT-")) {
22772
22772
  return header;
22773
22773
  }
22774
22774
  return normalizeCsvHeaderHelper(header);
@@ -22789,13 +22789,13 @@
22789
22789
  ) {
22790
22790
  return resolve(results);
22791
22791
  } else if (results && results.errors && results.errors.length) {
22792
- return reject('Error in csv: ' + JSON.stringify(results.errors));
22792
+ return reject("Error in csv: " + JSON.stringify(results.errors));
22793
22793
  }
22794
22794
  return resolve(results);
22795
22795
  },
22796
22796
  error: (error) => {
22797
22797
  reject(error);
22798
- },
22798
+ }
22799
22799
  };
22800
22800
  papaparse_minExports.parse(csvFile.originFileObj, opts);
22801
22801
  });
@@ -22824,7 +22824,7 @@
22824
22824
  const parseCsvString = (csvString, parserOptions = {}) => {
22825
22825
  const opts = {
22826
22826
  ...defaultCsvParserOptions,
22827
- ...setupCsvParserOptions(parserOptions),
22827
+ ...setupCsvParserOptions(parserOptions)
22828
22828
  };
22829
22829
  return papaparse_minExports.parse(csvString, opts);
22830
22830
  };
@@ -22844,7 +22844,7 @@
22844
22844
  else if (isTextFile(fileOrFiles)) txtFile = fileOrFiles;
22845
22845
  }
22846
22846
  if (!csvFile && !excelFile && !txtFile) {
22847
- throw new Error('No csv or excel files found');
22847
+ throw new Error("No csv or excel files found");
22848
22848
  }
22849
22849
 
22850
22850
  if (!csvFile && !excelFile) csvFile = txtFile;
@@ -22857,7 +22857,7 @@
22857
22857
  throw new Error(csvFile.error);
22858
22858
  }
22859
22859
  } else if (excelFile) {
22860
- throw new Error('Excel Parser not initialized on the window');
22860
+ throw new Error("Excel Parser not initialized on the window");
22861
22861
  }
22862
22862
  const parsedCsv = await parseCsvFile(csvFile, csvParserOptions);
22863
22863
  parsedCsv.originalFile = csvFile;
@@ -22873,9 +22873,9 @@
22873
22873
  return !fields.includes(field);
22874
22874
  });
22875
22875
  if (missingRequiredHeaders.length) {
22876
- const name = filename ? `The file ${filename}` : 'CSV file';
22876
+ const name = filename ? `The file ${filename}` : "CSV file";
22877
22877
  return `${name} is missing required headers. (${missingRequiredHeaders.join(
22878
- ', '
22878
+ ", "
22879
22879
  )})`;
22880
22880
  }
22881
22881
  };
@@ -22890,14 +22890,14 @@
22890
22890
  } else {
22891
22891
  return `Row ${
22892
22892
  index + 1
22893
- } is missing these required fields: ${missingRequiredFields.join(', ')}`;
22893
+ } is missing these required fields: ${missingRequiredFields.join(", ")}`;
22894
22894
  }
22895
22895
  }
22896
22896
  };
22897
22897
 
22898
22898
  const cleanCommaSeparatedCell = (cellData) =>
22899
- (cellData || '')
22900
- .split(',')
22899
+ (cellData || "")
22900
+ .split(",")
22901
22901
  .map((n) => n.trim())
22902
22902
  .filter((n) => n);
22903
22903
 
@@ -22918,7 +22918,7 @@
22918
22918
  });
22919
22919
  rows.forEach((row) => {
22920
22920
  allHeaders.forEach((header) => {
22921
- row[header] = row[header] || '';
22921
+ row[header] = row[header] || "";
22922
22922
  });
22923
22923
  });
22924
22924
  return rows;
@@ -22928,7 +22928,7 @@
22928
22928
  const zipExtracted = await extractZipFiles(file);
22929
22929
  const acceptedFiles = [];
22930
22930
  for (const extFile of zipExtracted) {
22931
- if (accepted.some((ext) => ext?.replace(".","") === getExt(extFile))) {
22931
+ if (accepted.some((ext) => ext?.replace(".", "") === getExt(extFile))) {
22932
22932
  acceptedFiles.push(extFile);
22933
22933
  }
22934
22934
  }
@@ -22937,14 +22937,14 @@
22937
22937
  window.toastr.warning("Some files don't have the proper file extension.");
22938
22938
 
22939
22939
  if (!acceptedFiles.length)
22940
- window.toastr.warning('No files with the proper extension were found.');
22940
+ window.toastr.warning("No files with the proper extension were found.");
22941
22941
 
22942
22942
  return acceptedFiles;
22943
22943
  };
22944
22944
 
22945
22945
  function removeExt(filename) {
22946
- if (filename && filename.includes('.')) {
22947
- return filename.split('.').slice(0, -1).join('.');
22946
+ if (filename && filename.includes(".")) {
22947
+ return filename.split(".").slice(0, -1).join(".");
22948
22948
  } else {
22949
22949
  return filename;
22950
22950
  }
@@ -22954,16 +22954,16 @@
22954
22954
  if (!files.length) return null;
22955
22955
 
22956
22956
  const formData = new FormData();
22957
- files.forEach(({ originFileObj }) => formData.append('file', originFileObj));
22957
+ files.forEach(({ originFileObj }) => formData.append("file", originFileObj));
22958
22958
 
22959
- const response = await window.api.post('/user_uploads/', formData);
22959
+ const response = await window.api.post("/user_uploads/", formData);
22960
22960
 
22961
22961
  return response.data.map((d) => ({
22962
22962
  encoding: d.encoding,
22963
22963
  mimetype: d.mimetype,
22964
22964
  originalname: d.originalname,
22965
22965
  path: d.path,
22966
- size: d.size,
22966
+ size: d.size
22967
22967
  }));
22968
22968
  }
22969
22969
 
@@ -22971,11 +22971,11 @@
22971
22971
  const encodedFiles = [];
22972
22972
  for (const file of files) {
22973
22973
  const encoded = await fileToBase64(file.originalFileObj);
22974
- const data = encoded.split(',');
22974
+ const data = encoded.split(",");
22975
22975
  encodedFiles.push({
22976
22976
  type: file.type,
22977
22977
  base64Data: data[1],
22978
- name: file.name,
22978
+ name: file.name
22979
22979
  });
22980
22980
  }
22981
22981
  return encodedFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/file-utils",
3
- "version": "0.2.23",
3
+ "version": "0.2.26",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
6
  "bluebird": "^3.7.2",