@cosmotech/core 1.7.1 → 1.9.0
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/CHANGELOG.md +21 -0
- package/dist/index.cjs.js +66 -15
- package/dist/index.esm.js +66 -15
- package/package.json +2 -11
- package/dist/bundle.min.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## **1.9.0** <sub><sup>2022-07-22 (aedf63f...3ee8718)</sup></sub>
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- implement scenarioIsValid function ([06d23d8](https://github.com/Cosmo-Tech/webapp-component-core/commit/06d23d8))
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- fix error during parsing of CSV strings when columns list is undefined ([a72b5b5](https://github.com/Cosmo-Tech/webapp-component-core/commit/a72b5b5))
|
|
10
|
+
|
|
11
|
+
## **1.8.0** <sub><sup>2022-05-09 (5d61a0e...5317d94)</sup></sub>
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- support empty fields in table component ([5d61a0e](https://github.com/Cosmo-Tech/webapp-component-core/commit/5d61a0e))
|
|
16
|
+
|
|
17
|
+
## **1.7.2** <sub><sup>2022-04-29</sup></sub>
|
|
18
|
+
|
|
19
|
+
- update dependencies
|
|
20
|
+
- remove unnecessary dependencies @babel/cli, @babel/preset-react and typescript
|
|
21
|
+
|
|
1
22
|
## **1.7.1** <sub><sup>2022-04-04</sup></sub>
|
|
2
23
|
|
|
3
24
|
- update dependencies
|
package/dist/index.cjs.js
CHANGED
|
@@ -20042,7 +20042,7 @@ var _castCellValueToStr = cellValue => {
|
|
|
20042
20042
|
};
|
|
20043
20043
|
|
|
20044
20044
|
var read = /*#__PURE__*/function () {
|
|
20045
|
-
var _ref = _asyncToGenerator(function* (fileBlob, forceStr) {
|
|
20045
|
+
var _ref = _asyncToGenerator(function* (fileBlob, forceStr, emptyCols) {
|
|
20046
20046
|
var data;
|
|
20047
20047
|
|
|
20048
20048
|
try {
|
|
@@ -20050,7 +20050,10 @@ var read = /*#__PURE__*/function () {
|
|
|
20050
20050
|
var workbook = readSync(buffer);
|
|
20051
20051
|
var worksheetName = workbook.SheetNames[0];
|
|
20052
20052
|
var worksheet = workbook.Sheets[worksheetName];
|
|
20053
|
-
data = utils.sheet_to_json(worksheet, {
|
|
20053
|
+
data = utils.sheet_to_json(worksheet, emptyCols ? {
|
|
20054
|
+
header: 1,
|
|
20055
|
+
defval: ''
|
|
20056
|
+
} : {
|
|
20054
20057
|
header: 1
|
|
20055
20058
|
});
|
|
20056
20059
|
} catch (err) {
|
|
@@ -20066,7 +20069,7 @@ var read = /*#__PURE__*/function () {
|
|
|
20066
20069
|
return data;
|
|
20067
20070
|
});
|
|
20068
20071
|
|
|
20069
|
-
return function read(_x, _x2) {
|
|
20072
|
+
return function read(_x, _x2, _x3) {
|
|
20070
20073
|
return _ref.apply(this, arguments);
|
|
20071
20074
|
};
|
|
20072
20075
|
}();
|
|
@@ -31952,7 +31955,13 @@ var isString = data => {
|
|
|
31952
31955
|
return typeof data === 'string';
|
|
31953
31956
|
};
|
|
31954
31957
|
|
|
31955
|
-
var isValid = (dataStr, type, options)
|
|
31958
|
+
var isValid = function isValid(dataStr, type, options) {
|
|
31959
|
+
var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
31960
|
+
|
|
31961
|
+
if (canBeEmpty && dataStr === '') {
|
|
31962
|
+
return true;
|
|
31963
|
+
}
|
|
31964
|
+
|
|
31956
31965
|
switch (type) {
|
|
31957
31966
|
case 'bool':
|
|
31958
31967
|
return isBool(dataStr);
|
|
@@ -32013,9 +32022,9 @@ class Error$1 {
|
|
|
32013
32022
|
}
|
|
32014
32023
|
|
|
32015
32024
|
var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row) => {
|
|
32016
|
-
var errorSummary = "Missing
|
|
32025
|
+
var errorSummary = "Missing field".concat(missingColsCount > 1 ? 's' : '');
|
|
32017
32026
|
var errorLoc = "Line ".concat(rowIndex);
|
|
32018
|
-
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, "
|
|
32027
|
+
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, " fields expected, ") + "but only ".concat(colsCount, " field").concat(colsCount > 1 ? 's' : '', " found\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
|
|
32019
32028
|
return new Error$1(errorSummary, errorLoc, errorContext);
|
|
32020
32029
|
};
|
|
32021
32030
|
|
|
@@ -32039,7 +32048,7 @@ var DEFAULT_CSV_EXPORT_OPTIONS = {
|
|
|
32039
32048
|
};
|
|
32040
32049
|
|
|
32041
32050
|
var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
|
|
32042
|
-
var colsCount = row.length;
|
|
32051
|
+
var colsCount = Object.values(row).filter(el => el !== undefined).length;
|
|
32043
32052
|
var expectedColsCount = expectedCols.length;
|
|
32044
32053
|
var expectedColsName = expectedCols.map(col => col.field).join();
|
|
32045
32054
|
var missingColsCount = expectedColsCount - colsCount;
|
|
@@ -32085,7 +32094,7 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32085
32094
|
var _loop = function _loop(rowIndex) {
|
|
32086
32095
|
var row = rows[rowIndex];
|
|
32087
32096
|
|
|
32088
|
-
if (row.length < knownColsCount) {
|
|
32097
|
+
if (row.length < knownColsCount || row.includes(undefined)) {
|
|
32089
32098
|
errors.push(_forgeColumnsCountError(rows[rowIndex], rowIndex, colsData));
|
|
32090
32099
|
}
|
|
32091
32100
|
|
|
@@ -32093,8 +32102,8 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32093
32102
|
if (colIndex < knownColsCount) {
|
|
32094
32103
|
var colType = colsData[colIndex].type;
|
|
32095
32104
|
|
|
32096
|
-
if (colType) {
|
|
32097
|
-
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c;
|
|
32105
|
+
if (colType && rowCell !== undefined) {
|
|
32106
|
+
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c, _colsData$colIndex$ce, _colsData$colIndex$ce2;
|
|
32098
32107
|
|
|
32099
32108
|
var enumValues = ((_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) || ((_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 ? void 0 : (_colsData$colIndex2$c = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2$c === void 0 ? void 0 : _colsData$colIndex2$c.enumValues);
|
|
32100
32109
|
|
|
@@ -32102,7 +32111,9 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32102
32111
|
enumValues: enumValues
|
|
32103
32112
|
});
|
|
32104
32113
|
|
|
32105
|
-
|
|
32114
|
+
var acceptsEmptyFields = (_colsData$colIndex$ce = (_colsData$colIndex$ce2 = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce2 === void 0 ? void 0 : _colsData$colIndex$ce2.acceptsEmptyFields) !== null && _colsData$colIndex$ce !== void 0 ? _colsData$colIndex$ce : false;
|
|
32115
|
+
|
|
32116
|
+
if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
|
|
32106
32117
|
errors.push(_forgeTypeError(rowCell, rowIndex, colType, colOptions, colsData, colIndex));
|
|
32107
32118
|
}
|
|
32108
32119
|
}
|
|
@@ -32125,8 +32136,6 @@ var _reformatBoolValue = csvCellValue => {
|
|
|
32125
32136
|
} else if (['1', 'true', 'yes'].includes(csvCellValue)) {
|
|
32126
32137
|
return 'true';
|
|
32127
32138
|
}
|
|
32128
|
-
|
|
32129
|
-
return null;
|
|
32130
32139
|
};
|
|
32131
32140
|
|
|
32132
32141
|
var _reformatValue = (csvCellValue, colTypes) => {
|
|
@@ -32141,6 +32150,22 @@ var _buildCols = header => header.map(col => ({
|
|
|
32141
32150
|
field: col
|
|
32142
32151
|
}));
|
|
32143
32152
|
|
|
32153
|
+
var _calculateEmptyCols = cols => {
|
|
32154
|
+
if (cols === undefined) {
|
|
32155
|
+
return [];
|
|
32156
|
+
}
|
|
32157
|
+
|
|
32158
|
+
return cols.map((_, index) => index).filter(colIndex => {
|
|
32159
|
+
var _cols$colIndex$cellEd;
|
|
32160
|
+
|
|
32161
|
+
return (_cols$colIndex$cellEd = cols[colIndex].cellEditorParams) === null || _cols$colIndex$cellEd === void 0 ? void 0 : _cols$colIndex$cellEd.acceptsEmptyFields;
|
|
32162
|
+
});
|
|
32163
|
+
};
|
|
32164
|
+
|
|
32165
|
+
var _processTableToTransformNonAcceptableEmptyCols = (lines, emptyCols) => {
|
|
32166
|
+
return lines.map(line => line.map((cell, index) => cell === '' && !emptyCols.includes(index) ? undefined : cell));
|
|
32167
|
+
};
|
|
32168
|
+
|
|
32144
32169
|
var _buildRows = (rows, hasHeader, cols) => {
|
|
32145
32170
|
var formattedData = [];
|
|
32146
32171
|
var startIndex = hasHeader ? 1 : 0;
|
|
@@ -32180,8 +32205,10 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
32180
32205
|
var rows = [];
|
|
32181
32206
|
var csvLines;
|
|
32182
32207
|
|
|
32208
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32209
|
+
|
|
32183
32210
|
try {
|
|
32184
|
-
csvLines = CSVUtils.read(dataStr);
|
|
32211
|
+
csvLines = _processTableToTransformNonAcceptableEmptyCols(CSVUtils.read(dataStr), emptyCols);
|
|
32185
32212
|
} catch (err) {
|
|
32186
32213
|
return {
|
|
32187
32214
|
error: [err]
|
|
@@ -32270,8 +32297,11 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
32270
32297
|
var rows = [];
|
|
32271
32298
|
var xlsxLines;
|
|
32272
32299
|
|
|
32300
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32301
|
+
|
|
32273
32302
|
try {
|
|
32274
|
-
xlsxLines = yield XLSXUtils.read(fileBlob, true);
|
|
32303
|
+
xlsxLines = yield XLSXUtils.read(fileBlob, true, emptyCols.length > 0);
|
|
32304
|
+
if (emptyCols.length > 0) xlsxLines = _processTableToTransformNonAcceptableEmptyCols(xlsxLines, emptyCols);
|
|
32275
32305
|
} catch (err) {
|
|
32276
32306
|
return {
|
|
32277
32307
|
error: [new Error$1((err === null || err === void 0 ? void 0 : err.message) || err, fileBlob.name, (err === null || err === void 0 ? void 0 : err.stack) || null)]
|
|
@@ -32689,6 +32719,10 @@ var DatasetUtils = {
|
|
|
32689
32719
|
|
|
32690
32720
|
// Copyright (c) Cosmo Tech.
|
|
32691
32721
|
// Licensed under the MIT license.
|
|
32722
|
+
var NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;
|
|
32723
|
+
|
|
32724
|
+
// Copyright (c) Cosmo Tech.
|
|
32725
|
+
|
|
32692
32726
|
var scenarioExistsInList = (scenarioName, scenarioList) => {
|
|
32693
32727
|
scenarioName = scenarioName.trim();
|
|
32694
32728
|
return scenarioList.find(scenario => scenario.name.trim() === scenarioName) !== undefined;
|
|
@@ -32708,6 +32742,22 @@ var scenarioExistsInTree = (scenarioName, scenarioTree) => {
|
|
|
32708
32742
|
return treeSearch(scenarioTree);
|
|
32709
32743
|
};
|
|
32710
32744
|
|
|
32745
|
+
var scenarioNameIsValid = (scenarioName, scenarioList) => {
|
|
32746
|
+
scenarioName = scenarioName.trimEnd();
|
|
32747
|
+
|
|
32748
|
+
if (scenarioName.length === 0) {
|
|
32749
|
+
return 'emptyScenarioName';
|
|
32750
|
+
} else {
|
|
32751
|
+
if (scenarioName.match(NAME_VALIDATOR) === null) {
|
|
32752
|
+
return 'forbiddenCharsInScenarioName';
|
|
32753
|
+
} else if (scenarioExistsInList(scenarioName, scenarioList)) {
|
|
32754
|
+
return 'existingScenarioName';
|
|
32755
|
+
}
|
|
32756
|
+
}
|
|
32757
|
+
|
|
32758
|
+
return null;
|
|
32759
|
+
};
|
|
32760
|
+
|
|
32711
32761
|
var getScenarioTree = (scenarioList, compareFn) => {
|
|
32712
32762
|
var scenarioTree = []; // Sort scenario list based on optional user-defined function
|
|
32713
32763
|
|
|
@@ -32751,6 +32801,7 @@ function countScenariosInTree(treeData) {
|
|
|
32751
32801
|
var ScenarioUtils = {
|
|
32752
32802
|
scenarioExistsInList,
|
|
32753
32803
|
scenarioExistsInTree,
|
|
32804
|
+
scenarioNameIsValid,
|
|
32754
32805
|
getScenarioTree,
|
|
32755
32806
|
countScenariosInTree
|
|
32756
32807
|
};
|
package/dist/index.esm.js
CHANGED
|
@@ -20034,7 +20034,7 @@ var _castCellValueToStr = cellValue => {
|
|
|
20034
20034
|
};
|
|
20035
20035
|
|
|
20036
20036
|
var read = /*#__PURE__*/function () {
|
|
20037
|
-
var _ref = _asyncToGenerator(function* (fileBlob, forceStr) {
|
|
20037
|
+
var _ref = _asyncToGenerator(function* (fileBlob, forceStr, emptyCols) {
|
|
20038
20038
|
var data;
|
|
20039
20039
|
|
|
20040
20040
|
try {
|
|
@@ -20042,7 +20042,10 @@ var read = /*#__PURE__*/function () {
|
|
|
20042
20042
|
var workbook = readSync(buffer);
|
|
20043
20043
|
var worksheetName = workbook.SheetNames[0];
|
|
20044
20044
|
var worksheet = workbook.Sheets[worksheetName];
|
|
20045
|
-
data = utils.sheet_to_json(worksheet, {
|
|
20045
|
+
data = utils.sheet_to_json(worksheet, emptyCols ? {
|
|
20046
|
+
header: 1,
|
|
20047
|
+
defval: ''
|
|
20048
|
+
} : {
|
|
20046
20049
|
header: 1
|
|
20047
20050
|
});
|
|
20048
20051
|
} catch (err) {
|
|
@@ -20058,7 +20061,7 @@ var read = /*#__PURE__*/function () {
|
|
|
20058
20061
|
return data;
|
|
20059
20062
|
});
|
|
20060
20063
|
|
|
20061
|
-
return function read(_x, _x2) {
|
|
20064
|
+
return function read(_x, _x2, _x3) {
|
|
20062
20065
|
return _ref.apply(this, arguments);
|
|
20063
20066
|
};
|
|
20064
20067
|
}();
|
|
@@ -31944,7 +31947,13 @@ var isString = data => {
|
|
|
31944
31947
|
return typeof data === 'string';
|
|
31945
31948
|
};
|
|
31946
31949
|
|
|
31947
|
-
var isValid = (dataStr, type, options)
|
|
31950
|
+
var isValid = function isValid(dataStr, type, options) {
|
|
31951
|
+
var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
31952
|
+
|
|
31953
|
+
if (canBeEmpty && dataStr === '') {
|
|
31954
|
+
return true;
|
|
31955
|
+
}
|
|
31956
|
+
|
|
31948
31957
|
switch (type) {
|
|
31949
31958
|
case 'bool':
|
|
31950
31959
|
return isBool(dataStr);
|
|
@@ -32005,9 +32014,9 @@ class Error$1 {
|
|
|
32005
32014
|
}
|
|
32006
32015
|
|
|
32007
32016
|
var _buildColumnsCountError = (missingColsCount, rowIndex, expectedColsCount, colsCount, expectedColsName, row) => {
|
|
32008
|
-
var errorSummary = "Missing
|
|
32017
|
+
var errorSummary = "Missing field".concat(missingColsCount > 1 ? 's' : '');
|
|
32009
32018
|
var errorLoc = "Line ".concat(rowIndex);
|
|
32010
|
-
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, "
|
|
32019
|
+
var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : ").concat(expectedColsCount, " fields expected, ") + "but only ".concat(colsCount, " field").concat(colsCount > 1 ? 's' : '', " found\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
|
|
32011
32020
|
return new Error$1(errorSummary, errorLoc, errorContext);
|
|
32012
32021
|
};
|
|
32013
32022
|
|
|
@@ -32031,7 +32040,7 @@ var DEFAULT_CSV_EXPORT_OPTIONS = {
|
|
|
32031
32040
|
};
|
|
32032
32041
|
|
|
32033
32042
|
var _forgeColumnsCountError = (row, rowIndex, expectedCols) => {
|
|
32034
|
-
var colsCount = row.length;
|
|
32043
|
+
var colsCount = Object.values(row).filter(el => el !== undefined).length;
|
|
32035
32044
|
var expectedColsCount = expectedCols.length;
|
|
32036
32045
|
var expectedColsName = expectedCols.map(col => col.field).join();
|
|
32037
32046
|
var missingColsCount = expectedColsCount - colsCount;
|
|
@@ -32077,7 +32086,7 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32077
32086
|
var _loop = function _loop(rowIndex) {
|
|
32078
32087
|
var row = rows[rowIndex];
|
|
32079
32088
|
|
|
32080
|
-
if (row.length < knownColsCount) {
|
|
32089
|
+
if (row.length < knownColsCount || row.includes(undefined)) {
|
|
32081
32090
|
errors.push(_forgeColumnsCountError(rows[rowIndex], rowIndex, colsData));
|
|
32082
32091
|
}
|
|
32083
32092
|
|
|
@@ -32085,8 +32094,8 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32085
32094
|
if (colIndex < knownColsCount) {
|
|
32086
32095
|
var colType = colsData[colIndex].type;
|
|
32087
32096
|
|
|
32088
|
-
if (colType) {
|
|
32089
|
-
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c;
|
|
32097
|
+
if (colType && rowCell !== undefined) {
|
|
32098
|
+
var _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex2$c, _colsData$colIndex$ce, _colsData$colIndex$ce2;
|
|
32090
32099
|
|
|
32091
32100
|
var enumValues = ((_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) || ((_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 ? void 0 : (_colsData$colIndex2$c = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2$c === void 0 ? void 0 : _colsData$colIndex2$c.enumValues);
|
|
32092
32101
|
|
|
@@ -32094,7 +32103,9 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
|
|
|
32094
32103
|
enumValues: enumValues
|
|
32095
32104
|
});
|
|
32096
32105
|
|
|
32097
|
-
|
|
32106
|
+
var acceptsEmptyFields = (_colsData$colIndex$ce = (_colsData$colIndex$ce2 = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce2 === void 0 ? void 0 : _colsData$colIndex$ce2.acceptsEmptyFields) !== null && _colsData$colIndex$ce !== void 0 ? _colsData$colIndex$ce : false;
|
|
32107
|
+
|
|
32108
|
+
if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
|
|
32098
32109
|
errors.push(_forgeTypeError(rowCell, rowIndex, colType, colOptions, colsData, colIndex));
|
|
32099
32110
|
}
|
|
32100
32111
|
}
|
|
@@ -32117,8 +32128,6 @@ var _reformatBoolValue = csvCellValue => {
|
|
|
32117
32128
|
} else if (['1', 'true', 'yes'].includes(csvCellValue)) {
|
|
32118
32129
|
return 'true';
|
|
32119
32130
|
}
|
|
32120
|
-
|
|
32121
|
-
return null;
|
|
32122
32131
|
};
|
|
32123
32132
|
|
|
32124
32133
|
var _reformatValue = (csvCellValue, colTypes) => {
|
|
@@ -32133,6 +32142,22 @@ var _buildCols = header => header.map(col => ({
|
|
|
32133
32142
|
field: col
|
|
32134
32143
|
}));
|
|
32135
32144
|
|
|
32145
|
+
var _calculateEmptyCols = cols => {
|
|
32146
|
+
if (cols === undefined) {
|
|
32147
|
+
return [];
|
|
32148
|
+
}
|
|
32149
|
+
|
|
32150
|
+
return cols.map((_, index) => index).filter(colIndex => {
|
|
32151
|
+
var _cols$colIndex$cellEd;
|
|
32152
|
+
|
|
32153
|
+
return (_cols$colIndex$cellEd = cols[colIndex].cellEditorParams) === null || _cols$colIndex$cellEd === void 0 ? void 0 : _cols$colIndex$cellEd.acceptsEmptyFields;
|
|
32154
|
+
});
|
|
32155
|
+
};
|
|
32156
|
+
|
|
32157
|
+
var _processTableToTransformNonAcceptableEmptyCols = (lines, emptyCols) => {
|
|
32158
|
+
return lines.map(line => line.map((cell, index) => cell === '' && !emptyCols.includes(index) ? undefined : cell));
|
|
32159
|
+
};
|
|
32160
|
+
|
|
32136
32161
|
var _buildRows = (rows, hasHeader, cols) => {
|
|
32137
32162
|
var formattedData = [];
|
|
32138
32163
|
var startIndex = hasHeader ? 1 : 0;
|
|
@@ -32172,8 +32197,10 @@ var fromCSV = function fromCSV(dataStr) {
|
|
|
32172
32197
|
var rows = [];
|
|
32173
32198
|
var csvLines;
|
|
32174
32199
|
|
|
32200
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32201
|
+
|
|
32175
32202
|
try {
|
|
32176
|
-
csvLines = CSVUtils.read(dataStr);
|
|
32203
|
+
csvLines = _processTableToTransformNonAcceptableEmptyCols(CSVUtils.read(dataStr), emptyCols);
|
|
32177
32204
|
} catch (err) {
|
|
32178
32205
|
return {
|
|
32179
32206
|
error: [err]
|
|
@@ -32262,8 +32289,11 @@ var fromXLSX = /*#__PURE__*/function () {
|
|
|
32262
32289
|
var rows = [];
|
|
32263
32290
|
var xlsxLines;
|
|
32264
32291
|
|
|
32292
|
+
var emptyCols = _calculateEmptyCols(cols);
|
|
32293
|
+
|
|
32265
32294
|
try {
|
|
32266
|
-
xlsxLines = yield XLSXUtils.read(fileBlob, true);
|
|
32295
|
+
xlsxLines = yield XLSXUtils.read(fileBlob, true, emptyCols.length > 0);
|
|
32296
|
+
if (emptyCols.length > 0) xlsxLines = _processTableToTransformNonAcceptableEmptyCols(xlsxLines, emptyCols);
|
|
32267
32297
|
} catch (err) {
|
|
32268
32298
|
return {
|
|
32269
32299
|
error: [new Error$1((err === null || err === void 0 ? void 0 : err.message) || err, fileBlob.name, (err === null || err === void 0 ? void 0 : err.stack) || null)]
|
|
@@ -32681,6 +32711,10 @@ var DatasetUtils = {
|
|
|
32681
32711
|
|
|
32682
32712
|
// Copyright (c) Cosmo Tech.
|
|
32683
32713
|
// Licensed under the MIT license.
|
|
32714
|
+
var NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;
|
|
32715
|
+
|
|
32716
|
+
// Copyright (c) Cosmo Tech.
|
|
32717
|
+
|
|
32684
32718
|
var scenarioExistsInList = (scenarioName, scenarioList) => {
|
|
32685
32719
|
scenarioName = scenarioName.trim();
|
|
32686
32720
|
return scenarioList.find(scenario => scenario.name.trim() === scenarioName) !== undefined;
|
|
@@ -32700,6 +32734,22 @@ var scenarioExistsInTree = (scenarioName, scenarioTree) => {
|
|
|
32700
32734
|
return treeSearch(scenarioTree);
|
|
32701
32735
|
};
|
|
32702
32736
|
|
|
32737
|
+
var scenarioNameIsValid = (scenarioName, scenarioList) => {
|
|
32738
|
+
scenarioName = scenarioName.trimEnd();
|
|
32739
|
+
|
|
32740
|
+
if (scenarioName.length === 0) {
|
|
32741
|
+
return 'emptyScenarioName';
|
|
32742
|
+
} else {
|
|
32743
|
+
if (scenarioName.match(NAME_VALIDATOR) === null) {
|
|
32744
|
+
return 'forbiddenCharsInScenarioName';
|
|
32745
|
+
} else if (scenarioExistsInList(scenarioName, scenarioList)) {
|
|
32746
|
+
return 'existingScenarioName';
|
|
32747
|
+
}
|
|
32748
|
+
}
|
|
32749
|
+
|
|
32750
|
+
return null;
|
|
32751
|
+
};
|
|
32752
|
+
|
|
32703
32753
|
var getScenarioTree = (scenarioList, compareFn) => {
|
|
32704
32754
|
var scenarioTree = []; // Sort scenario list based on optional user-defined function
|
|
32705
32755
|
|
|
@@ -32743,6 +32793,7 @@ function countScenariosInTree(treeData) {
|
|
|
32743
32793
|
var ScenarioUtils = {
|
|
32744
32794
|
scenarioExistsInList,
|
|
32745
32795
|
scenarioExistsInTree,
|
|
32796
|
+
scenarioNameIsValid,
|
|
32746
32797
|
getScenarioTree,
|
|
32747
32798
|
countScenariosInTree
|
|
32748
32799
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmotech/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -11,12 +11,6 @@
|
|
|
11
11
|
"test": "jest --watchAll=false",
|
|
12
12
|
"prettier": "npx prettier -w"
|
|
13
13
|
},
|
|
14
|
-
"eslintConfig": {
|
|
15
|
-
"extends": [
|
|
16
|
-
"react-app",
|
|
17
|
-
"react-app/jest"
|
|
18
|
-
]
|
|
19
|
-
},
|
|
20
14
|
"repository": {
|
|
21
15
|
"type": "git",
|
|
22
16
|
"url": "git+https://github.com/Cosmo-Tech/webapp-component-core.git"
|
|
@@ -31,10 +25,8 @@
|
|
|
31
25
|
"fs": false
|
|
32
26
|
},
|
|
33
27
|
"devDependencies": {
|
|
34
|
-
"@babel/cli": "^7.14.3",
|
|
35
28
|
"@babel/core": "^7.14.3",
|
|
36
29
|
"@babel/preset-env": "^7.14.2",
|
|
37
|
-
"@babel/preset-react": "^7.12.10",
|
|
38
30
|
"@rollup/plugin-babel": "^5.2.2",
|
|
39
31
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
40
32
|
"@rollup/plugin-image": "^2.0.5",
|
|
@@ -53,8 +45,7 @@
|
|
|
53
45
|
"rollup": "^2.49.0",
|
|
54
46
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
55
47
|
"rollup-plugin-postcss": "^4.0.0",
|
|
56
|
-
"rollup-plugin-visualizer": "^5.5.0"
|
|
57
|
-
"typescript": "^4.4.4"
|
|
48
|
+
"rollup-plugin-visualizer": "^5.5.0"
|
|
58
49
|
},
|
|
59
50
|
"dependencies": {
|
|
60
51
|
"csv-string": "^4.0.1",
|