@cosmotech/core 1.5.0-dev → 1.5.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.
package/dist/index.cjs.js CHANGED
@@ -646,7 +646,11 @@ __export(CSV);
646
646
  // Copyright (c) Cosmo Tech.
647
647
 
648
648
  var read = function read(dataStr) {
649
- return dist.parse(dataStr);
649
+ return dist.parse(dataStr).map(function (row) {
650
+ return row.map(function (cell) {
651
+ return cell.trim();
652
+ });
653
+ });
650
654
  };
651
655
 
652
656
  var write = function write(dataArray) {
@@ -7991,7 +7995,7 @@ function buildLocalizeFn(args) {
7991
7995
  valuesArray = args.values[_width] || args.values[_defaultWidth];
7992
7996
  }
7993
7997
 
7994
- var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challange you to try to remove it!
7998
+ var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
7995
7999
 
7996
8000
  return valuesArray[index];
7997
8001
  };
@@ -8558,7 +8562,7 @@ function startOfUTCWeek(dirtyDate, dirtyOptions) {
8558
8562
 
8559
8563
  function getUTCWeekYear(dirtyDate, dirtyOptions) {
8560
8564
  requiredArgs(1, arguments);
8561
- var date = toDate(dirtyDate, dirtyOptions);
8565
+ var date = toDate(dirtyDate);
8562
8566
  var year = date.getUTCFullYear();
8563
8567
  var options = dirtyOptions || {};
8564
8568
  var locale = options.locale;
@@ -9444,7 +9448,7 @@ var formatters = {
9444
9448
  }
9445
9449
  };
9446
9450
 
9447
- function formatTimezoneShort(offset, dirtyDelimiter) {
9451
+ function formatTimezoneShort(offset, delimiter) {
9448
9452
  var sign = offset > 0 ? '-' : '+';
9449
9453
  var absOffset = Math.abs(offset);
9450
9454
  var hours = Math.floor(absOffset / 60);
@@ -9454,7 +9458,6 @@ function formatTimezoneShort(offset, dirtyDelimiter) {
9454
9458
  return sign + String(hours);
9455
9459
  }
9456
9460
 
9457
- var delimiter = dirtyDelimiter || '';
9458
9461
  return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
9459
9462
  }
9460
9463
 
@@ -9529,7 +9532,7 @@ function timeLongFormatter(pattern, formatLong) {
9529
9532
  }
9530
9533
 
9531
9534
  function dateTimeLongFormatter(pattern, formatLong) {
9532
- var matchResult = pattern.match(/(P+)(p+)?/);
9535
+ var matchResult = pattern.match(/(P+)(p+)?/) || [];
9533
9536
  var datePattern = matchResult[1];
9534
9537
  var timePattern = matchResult[2];
9535
9538
 
@@ -12712,6 +12715,26 @@ var _validateFormat = function _validateFormat(rows, hasHeader, cols, options) {
12712
12715
  return errors;
12713
12716
  };
12714
12717
 
12718
+ var _reformatBoolValue = function _reformatBoolValue(csvCellValue) {
12719
+ csvCellValue = csvCellValue.toLowerCase();
12720
+
12721
+ if (['0', 'false', 'no'].includes(csvCellValue)) {
12722
+ return 'false';
12723
+ } else if (['1', 'true', 'yes'].includes(csvCellValue)) {
12724
+ return 'true';
12725
+ }
12726
+
12727
+ return null;
12728
+ };
12729
+
12730
+ var _reformatValue = function _reformatValue(csvCellValue, colTypes) {
12731
+ if (colTypes && colTypes.includes('bool')) {
12732
+ return _reformatBoolValue(csvCellValue);
12733
+ }
12734
+
12735
+ return csvCellValue;
12736
+ };
12737
+
12715
12738
  var _buildCols = function _buildCols(header) {
12716
12739
  return header.map(function (col) {
12717
12740
  return {
@@ -12728,7 +12751,8 @@ var _buildRows = function _buildRows(rows, hasHeader, cols) {
12728
12751
  var row = {};
12729
12752
 
12730
12753
  for (var colIndex = 0; colIndex < cols.length; colIndex++) {
12731
- row[cols[colIndex].field] = rows[rowIndex][colIndex];
12754
+ var csvCellValue = rows[rowIndex][colIndex];
12755
+ row[cols[colIndex].field] = _reformatValue(csvCellValue, cols[colIndex].type);
12732
12756
  }
12733
12757
 
12734
12758
  formattedData.push(row);
package/dist/index.esm.js CHANGED
@@ -638,7 +638,11 @@ __export(CSV);
638
638
  // Copyright (c) Cosmo Tech.
639
639
 
640
640
  var read = function read(dataStr) {
641
- return dist.parse(dataStr);
641
+ return dist.parse(dataStr).map(function (row) {
642
+ return row.map(function (cell) {
643
+ return cell.trim();
644
+ });
645
+ });
642
646
  };
643
647
 
644
648
  var write = function write(dataArray) {
@@ -7983,7 +7987,7 @@ function buildLocalizeFn(args) {
7983
7987
  valuesArray = args.values[_width] || args.values[_defaultWidth];
7984
7988
  }
7985
7989
 
7986
- var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challange you to try to remove it!
7990
+ var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex; // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
7987
7991
 
7988
7992
  return valuesArray[index];
7989
7993
  };
@@ -8550,7 +8554,7 @@ function startOfUTCWeek(dirtyDate, dirtyOptions) {
8550
8554
 
8551
8555
  function getUTCWeekYear(dirtyDate, dirtyOptions) {
8552
8556
  requiredArgs(1, arguments);
8553
- var date = toDate(dirtyDate, dirtyOptions);
8557
+ var date = toDate(dirtyDate);
8554
8558
  var year = date.getUTCFullYear();
8555
8559
  var options = dirtyOptions || {};
8556
8560
  var locale = options.locale;
@@ -9436,7 +9440,7 @@ var formatters = {
9436
9440
  }
9437
9441
  };
9438
9442
 
9439
- function formatTimezoneShort(offset, dirtyDelimiter) {
9443
+ function formatTimezoneShort(offset, delimiter) {
9440
9444
  var sign = offset > 0 ? '-' : '+';
9441
9445
  var absOffset = Math.abs(offset);
9442
9446
  var hours = Math.floor(absOffset / 60);
@@ -9446,7 +9450,6 @@ function formatTimezoneShort(offset, dirtyDelimiter) {
9446
9450
  return sign + String(hours);
9447
9451
  }
9448
9452
 
9449
- var delimiter = dirtyDelimiter || '';
9450
9453
  return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
9451
9454
  }
9452
9455
 
@@ -9521,7 +9524,7 @@ function timeLongFormatter(pattern, formatLong) {
9521
9524
  }
9522
9525
 
9523
9526
  function dateTimeLongFormatter(pattern, formatLong) {
9524
- var matchResult = pattern.match(/(P+)(p+)?/);
9527
+ var matchResult = pattern.match(/(P+)(p+)?/) || [];
9525
9528
  var datePattern = matchResult[1];
9526
9529
  var timePattern = matchResult[2];
9527
9530
 
@@ -12704,6 +12707,26 @@ var _validateFormat = function _validateFormat(rows, hasHeader, cols, options) {
12704
12707
  return errors;
12705
12708
  };
12706
12709
 
12710
+ var _reformatBoolValue = function _reformatBoolValue(csvCellValue) {
12711
+ csvCellValue = csvCellValue.toLowerCase();
12712
+
12713
+ if (['0', 'false', 'no'].includes(csvCellValue)) {
12714
+ return 'false';
12715
+ } else if (['1', 'true', 'yes'].includes(csvCellValue)) {
12716
+ return 'true';
12717
+ }
12718
+
12719
+ return null;
12720
+ };
12721
+
12722
+ var _reformatValue = function _reformatValue(csvCellValue, colTypes) {
12723
+ if (colTypes && colTypes.includes('bool')) {
12724
+ return _reformatBoolValue(csvCellValue);
12725
+ }
12726
+
12727
+ return csvCellValue;
12728
+ };
12729
+
12707
12730
  var _buildCols = function _buildCols(header) {
12708
12731
  return header.map(function (col) {
12709
12732
  return {
@@ -12720,7 +12743,8 @@ var _buildRows = function _buildRows(rows, hasHeader, cols) {
12720
12743
  var row = {};
12721
12744
 
12722
12745
  for (var colIndex = 0; colIndex < cols.length; colIndex++) {
12723
- row[cols[colIndex].field] = rows[rowIndex][colIndex];
12746
+ var csvCellValue = rows[rowIndex][colIndex];
12747
+ row[cols[colIndex].field] = _reformatValue(csvCellValue, cols[colIndex].type);
12724
12748
  }
12725
12749
 
12726
12750
  formattedData.push(row);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cosmotech/core",
3
3
  "private": false,
4
- "version": "1.5.0-dev",
4
+ "version": "1.5.1",
5
5
  "description": "",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.esm.js",