@qrvey/utils 1.1.2 → 1.1.6
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/README.md +196 -143
- package/dist/cjs/constants/COLUMN_PROPERTY_VALUE.js +1 -1
- package/dist/cjs/date/constants/DATE_VALUES.js +1 -1
- package/dist/cjs/filters/adapters/FDToFlatUI.js +2 -1
- package/dist/cjs/filters/adapters/FDToUI.js +2 -1
- package/dist/cjs/filters/adapters/UIToFlatUI.js +2 -1
- package/dist/cjs/filters/adapters/UIToOldLogic.js +2 -1
- package/dist/cjs/filters/adapters/adaptFilterValues.d.ts +8 -0
- package/dist/cjs/filters/adapters/adaptFilterValues.js +18 -0
- package/dist/cjs/filters/adapters/flatUIToFD.js +2 -1
- package/dist/cjs/filters/adapters/flatUIToUI.js +2 -1
- package/dist/cjs/filters/adapters/logicToFlatUI.js +0 -3
- package/dist/cjs/filters/helpers/common/getFilterColumnLabel.js +1 -1
- package/dist/cjs/filters/helpers/common/getFiltersByParams.js +1 -1
- package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
- package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.js +13 -0
- package/dist/cjs/filters/helpers/ui/index.d.ts +1 -0
- package/dist/cjs/filters/helpers/ui/index.js +1 -0
- package/dist/cjs/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
- package/dist/cjs/general/array/filterNestedTree.d.ts +5 -2
- package/dist/cjs/general/array/filterNestedTree.js +13 -5
- package/dist/cjs/general/mix/isEmpty.js +3 -1
- package/dist/cjs/general/mix/isNull.js +1 -1
- package/dist/cjs/general/mix/randomId.d.ts +6 -3
- package/dist/cjs/general/mix/randomId.js +24 -7
- package/dist/cjs/general/mix/size.d.ts +5 -5
- package/dist/cjs/general/mix/size.js +9 -6
- package/dist/cjs/general/object/get.d.ts +1 -1
- package/dist/cjs/general/object/getAttribute.d.ts +9 -2
- package/dist/cjs/general/object/getAttribute.js +39 -8
- package/dist/cjs/general/object/hasProperty.d.ts +1 -1
- package/dist/cjs/general/object/hasProperty.js +10 -2
- package/dist/cjs/general/object/index.d.ts +1 -0
- package/dist/cjs/general/object/index.js +1 -0
- package/dist/cjs/general/object/isObject.js +1 -1
- package/dist/cjs/general/object/objectCopy.d.ts +7 -0
- package/dist/cjs/general/object/objectCopy.js +32 -0
- package/dist/cjs/general/string/capitalize.d.ts +3 -3
- package/dist/cjs/general/string/capitalize.js +6 -3
- package/dist/cjs/qrvey/getPropertyLabel.d.ts +2 -0
- package/dist/cjs/qrvey/getPropertyLabel.js +14 -0
- package/dist/cjs/qrvey/index.d.ts +1 -0
- package/dist/cjs/qrvey/index.js +1 -0
- package/dist/constants/COLUMN_PROPERTY_VALUE.js +2 -2
- package/dist/date/constants/DATE_VALUES.js +1 -1
- package/dist/filters/adapters/FDToFlatUI.js +2 -1
- package/dist/filters/adapters/FDToUI.js +2 -1
- package/dist/filters/adapters/UIToFlatUI.js +2 -1
- package/dist/filters/adapters/UIToOldLogic.js +2 -1
- package/dist/filters/adapters/adaptFilterValues.d.ts +8 -0
- package/dist/filters/adapters/adaptFilterValues.js +14 -0
- package/dist/filters/adapters/flatUIToFD.js +2 -1
- package/dist/filters/adapters/flatUIToUI.js +2 -1
- package/dist/filters/adapters/logicToFlatUI.js +0 -3
- package/dist/filters/helpers/common/getFilterColumnLabel.js +2 -2
- package/dist/filters/helpers/common/getFiltersByParams.js +1 -1
- package/dist/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
- package/dist/filters/helpers/ui/getFilterPropertyLabel.js +9 -0
- package/dist/filters/helpers/ui/index.d.ts +1 -0
- package/dist/filters/helpers/ui/index.js +1 -0
- package/dist/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
- package/dist/general/array/filterNestedTree.d.ts +5 -2
- package/dist/general/array/filterNestedTree.js +13 -5
- package/dist/general/mix/isEmpty.js +3 -1
- package/dist/general/mix/isNull.js +1 -1
- package/dist/general/mix/randomId.d.ts +6 -3
- package/dist/general/mix/randomId.js +24 -7
- package/dist/general/mix/size.d.ts +5 -5
- package/dist/general/mix/size.js +9 -6
- package/dist/general/object/get.d.ts +1 -1
- package/dist/general/object/getAttribute.d.ts +9 -2
- package/dist/general/object/getAttribute.js +39 -8
- package/dist/general/object/hasProperty.d.ts +1 -1
- package/dist/general/object/hasProperty.js +8 -0
- package/dist/general/object/index.d.ts +1 -0
- package/dist/general/object/index.js +1 -0
- package/dist/general/object/isObject.js +1 -1
- package/dist/general/object/objectCopy.d.ts +7 -0
- package/dist/general/object/objectCopy.js +28 -0
- package/dist/general/string/capitalize.d.ts +3 -3
- package/dist/general/string/capitalize.js +6 -3
- package/dist/qrvey/getPropertyLabel.d.ts +2 -0
- package/dist/qrvey/getPropertyLabel.js +10 -0
- package/dist/qrvey/index.d.ts +1 -0
- package/dist/qrvey/index.js +1 -0
- package/package.json +1 -1
- package/src/constants/COLUMN_PROPERTY_VALUE.ts +2 -2
- package/src/date/constants/DATE_VALUES.ts +1 -1
- package/src/filters/adapters/FDToFlatUI.ts +2 -1
- package/src/filters/adapters/FDToUI.ts +2 -0
- package/src/filters/adapters/UIToFlatUI.ts +2 -1
- package/src/filters/adapters/UIToOldLogic.ts +2 -1
- package/src/filters/adapters/adaptFilterValues.ts +17 -0
- package/src/filters/adapters/flatUIToFD.ts +2 -1
- package/src/filters/adapters/flatUIToUI.ts +2 -1
- package/src/filters/adapters/logicToFlatUI.ts +0 -3
- package/src/filters/helpers/backend/getAggFiltersBySummaryIndex.ts +1 -1
- package/src/filters/helpers/common/getFilterColumnLabel.ts +2 -2
- package/src/filters/helpers/common/getFiltersByParams.ts +1 -1
- package/src/filters/helpers/ui/getFilterPropertyLabel.ts +11 -0
- package/src/filters/helpers/ui/index.ts +1 -0
- package/src/filters/interfaces/common/IFSValueRelativeDate.ts +1 -1
- package/src/general/array/filterNestedTree.ts +13 -4
- package/src/general/mix/getTag.ts +1 -1
- package/src/general/mix/isEmpty.ts +3 -1
- package/src/general/mix/isNull.ts +1 -1
- package/src/general/mix/randomId.ts +24 -7
- package/src/general/mix/size.ts +10 -6
- package/src/general/object/get.ts +1 -1
- package/src/general/object/getAttribute.ts +47 -9
- package/src/general/object/hasProperty.ts +10 -1
- package/src/general/object/index.ts +1 -0
- package/src/general/object/isObject.ts +1 -1
- package/src/general/object/objectCopy.ts +35 -0
- package/src/general/string/capitalize.ts +7 -3
- package/src/qrvey/getPropertyLabel.ts +9 -0
- package/src/qrvey/index.ts +1 -0
- package/test/general/array/filterNestedTree.test.js +115 -0
- package/test/general/mix/getTag.test.js +101 -0
- package/test/general/mix/isEmpty.test.js +24 -24
- package/test/general/mix/isNull.test.js +72 -0
- package/test/general/mix/randomId.test.js +134 -0
- package/test/general/mix/size.test.js +87 -0
- package/test/general/object/cloneDeep.test.js +8 -16
- package/test/general/object/getAttribute.test.js +316 -0
- package/test/general/object/hasProperty.test.js +103 -0
- package/test/general/object/objectCopy.test.js +105 -0
- package/test/general/string/capitalize.test.js +87 -0
|
@@ -6,5 +6,5 @@ exports.DATE_VALUES = [
|
|
|
6
6
|
{ value: "year" /* DATE_YEAR */, label: 'Year', display: true },
|
|
7
7
|
{ value: "quarter" /* DATE_QUARTER */, label: 'Quarter, Year', display: true },
|
|
8
8
|
{ value: "month" /* DATE_MONTH */, label: 'Month, Year', display: true },
|
|
9
|
-
{ value: "week" /* DATE_WEEK */, label: '
|
|
9
|
+
{ value: "week" /* DATE_WEEK */, label: 'Week, Year', display: true }
|
|
10
10
|
];
|
|
@@ -4,6 +4,7 @@ exports.FDToFlatUI = void 0;
|
|
|
4
4
|
const general_1 = require("../../general");
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
const adaptDateGroupingProperty_1 = require("./adaptDateGroupingProperty");
|
|
7
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
7
8
|
/**
|
|
8
9
|
* Generates a Flattened UI filter structure from Filter Data structure.
|
|
9
10
|
* @param filterData The filter data object.
|
|
@@ -84,7 +85,7 @@ function FD21ToFlatUI(scopes = [], datasetsInfo = []) {
|
|
|
84
85
|
property: property,
|
|
85
86
|
uiValues: helpers_1.getUIValues(filter),
|
|
86
87
|
validator: filter.validator,
|
|
87
|
-
values: filter
|
|
88
|
+
values: adaptFilterValues_1.adaptFilterValues(filter),
|
|
88
89
|
};
|
|
89
90
|
uFilters.push(uFilter);
|
|
90
91
|
});
|
|
@@ -5,6 +5,7 @@ const _1 = require(".");
|
|
|
5
5
|
const general_1 = require("../../general");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const helpers_1 = require("../helpers");
|
|
8
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
8
9
|
/**
|
|
9
10
|
* Generates a UI filter structure from Filter Data structure.
|
|
10
11
|
* @param filterData The filter data object.
|
|
@@ -60,7 +61,7 @@ function FD21ToUI(scopes = [], section = "ANYWHERE" /* ANYWHERE */, enabled = tr
|
|
|
60
61
|
outputFormat: general_1._get(datasetInfo, 'outputFormat'),
|
|
61
62
|
qrveyid: filter.column.qrveyid,
|
|
62
63
|
type: (columnInfo === null || columnInfo === void 0 ? void 0 : columnInfo.type) || filter.column.type,
|
|
63
|
-
}, property, uiValues: helpers_1.getUIValues(filter) });
|
|
64
|
+
}, property, uiValues: helpers_1.getUIValues(filter), values: adaptFilterValues_1.adaptFilterValues(filter) });
|
|
64
65
|
}) });
|
|
65
66
|
}) })));
|
|
66
67
|
return ufData;
|
|
@@ -4,6 +4,7 @@ exports.UIToFlatUI = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const general_1 = require("../../general");
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
7
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
7
8
|
/**
|
|
8
9
|
* Generates a Flattened UI filter structure from UI Filter Data structure.
|
|
9
10
|
* @param filterData The UI filter data object.
|
|
@@ -83,7 +84,7 @@ function UI21ToFlatUI(scopes = [], datasetsInfo = []) {
|
|
|
83
84
|
property,
|
|
84
85
|
uiValues: helpers_1.getUIValues(filter),
|
|
85
86
|
validator: filter.validator,
|
|
86
|
-
values: filter
|
|
87
|
+
values: adaptFilterValues_1.adaptFilterValues(filter),
|
|
87
88
|
};
|
|
88
89
|
uFilters.push(uFilter);
|
|
89
90
|
});
|
|
@@ -4,6 +4,7 @@ exports.UIToOldLogic = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const general_1 = require("../../general");
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
7
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
7
8
|
const flatUIToOldLogic_1 = require("./flatUIToOldLogic");
|
|
8
9
|
const UIToFlatUI_1 = require("./UIToFlatUI");
|
|
9
10
|
function UIToOldLogic(uFilterData, flattedMethod = true) {
|
|
@@ -141,6 +142,6 @@ const getFilterDetail = (filter, scope, dataset) => {
|
|
|
141
142
|
section: filter.extras.section,
|
|
142
143
|
uiValue: helpers_1.getUIValues(filter, true),
|
|
143
144
|
validator: filter.validator,
|
|
144
|
-
values: filter
|
|
145
|
+
values: adaptFilterValues_1.adaptFilterValues(filter)
|
|
145
146
|
};
|
|
146
147
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IFSFilter, IFValue } from "..";
|
|
2
|
+
/**
|
|
3
|
+
* [TODO: For 2022, eliminate this adapter]
|
|
4
|
+
* Gets an adapted filter value array. Validates the enabled property and sets
|
|
5
|
+
* @param filter The filter
|
|
6
|
+
* @returns A new value array with the filled properties.
|
|
7
|
+
*/
|
|
8
|
+
export declare function adaptFilterValues(filter: IFSFilter): IFValue[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adaptFilterValues = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
/**
|
|
6
|
+
* [TODO: For 2022, eliminate this adapter]
|
|
7
|
+
* Gets an adapted filter value array. Validates the enabled property and sets
|
|
8
|
+
* @param filter The filter
|
|
9
|
+
* @returns A new value array with the filled properties.
|
|
10
|
+
*/
|
|
11
|
+
function adaptFilterValues(filter) {
|
|
12
|
+
const setValue = value => (Object.assign(Object.assign({}, value), { enabled: __1.isEmpty(value.enabled) ? true : value.enabled }));
|
|
13
|
+
if (filter.column.type === __1.COLUMN.RANKING && __1.isEmpty(filter.column.aggregate)) {
|
|
14
|
+
return filter.values.map(rValues => rValues.map(setValue));
|
|
15
|
+
}
|
|
16
|
+
return filter.values.map(setValue);
|
|
17
|
+
}
|
|
18
|
+
exports.adaptFilterValues = adaptFilterValues;
|
|
@@ -4,6 +4,7 @@ exports.flatUIToFD = void 0;
|
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const general_1 = require("../../general");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
7
8
|
/**
|
|
8
9
|
* Generates a filter data structure from the flatttened UI filters.
|
|
9
10
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -102,6 +103,6 @@ function buildFilter(uFilter) {
|
|
|
102
103
|
operator: uFilter.operator,
|
|
103
104
|
property,
|
|
104
105
|
validator: uFilter.validator,
|
|
105
|
-
values: uFilter
|
|
106
|
+
values: adaptFilterValues_1.adaptFilterValues(uFilter),
|
|
106
107
|
};
|
|
107
108
|
}
|
|
@@ -5,6 +5,7 @@ const _1 = require(".");
|
|
|
5
5
|
const general_1 = require("../../general");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const helpers_1 = require("../helpers");
|
|
8
|
+
const adaptFilterValues_1 = require("./adaptFilterValues");
|
|
8
9
|
/**
|
|
9
10
|
* Generates a UI filter data structure from the flatttened UI filters.
|
|
10
11
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -117,6 +118,6 @@ function buildFilter(uFilter) {
|
|
|
117
118
|
property,
|
|
118
119
|
uiValues: helpers_1.getUIValues(uFilter),
|
|
119
120
|
validator: uFilter.validator,
|
|
120
|
-
values: uFilter
|
|
121
|
+
values: adaptFilterValues_1.adaptFilterValues(uFilter),
|
|
121
122
|
};
|
|
122
123
|
}
|
|
@@ -25,9 +25,6 @@ function logicToFlatUI(logics = []) {
|
|
|
25
25
|
buildFilterByExpression(expression2, scopeItem, uFilters);
|
|
26
26
|
}) : buildFilterByExpression(expression1, scopeItem, uFilters);
|
|
27
27
|
});
|
|
28
|
-
// (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
|
|
29
|
-
// buildFilterByExpression(expression, scopeItem, uFilters);
|
|
30
|
-
// });
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
});
|
|
@@ -13,7 +13,7 @@ function getFilterColumnLabel(column) {
|
|
|
13
13
|
if (isComplexColumn_1.isComplexColumn(column) && column.property != null)
|
|
14
14
|
labels.push(constants_1.COLUMN_COMPLEX_VALUE[column.property].shortLabel);
|
|
15
15
|
if (column.aggregate != null)
|
|
16
|
-
labels.push(column.aggregate);
|
|
16
|
+
labels.push(constants_1.AGGREGATE_ABBREVIATION[column.aggregate]);
|
|
17
17
|
if (column.calculation != null)
|
|
18
18
|
labels.push(column.calculation);
|
|
19
19
|
return labels.length > 0 ? `(${labels.join(' - ')})` : '';
|
|
@@ -37,7 +37,7 @@ function getFiltersByParams(filterData, params, settings) {
|
|
|
37
37
|
return Object.assign(Object.assign({}, filter), { values: filter.values.map((value) => {
|
|
38
38
|
if (Array.isArray(value) && value.length > 0) {
|
|
39
39
|
const rankingValues = value;
|
|
40
|
-
rankingValues.map(rValue => {
|
|
40
|
+
return rankingValues.map(rValue => {
|
|
41
41
|
if (!general_1._hasProperty(params, 'enableds') || !general_1._hasProperty(params.enableds, 'values') || params.enableds.values === rValue.enabled)
|
|
42
42
|
return rValue;
|
|
43
43
|
}).filter(Boolean);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IFSFilter, IFUFilter } from "../..";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the label of the filter property
|
|
4
|
+
* @param filter The UI Filter
|
|
5
|
+
* @returns a string of the filter property label
|
|
6
|
+
*/
|
|
7
|
+
export declare function getFilterPropertyLabel(filter: IFUFilter | IFSFilter): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilterPropertyLabel = void 0;
|
|
4
|
+
const __1 = require("../../..");
|
|
5
|
+
/**
|
|
6
|
+
* Gets the label of the filter property
|
|
7
|
+
* @param filter The UI Filter
|
|
8
|
+
* @returns a string of the filter property label
|
|
9
|
+
*/
|
|
10
|
+
function getFilterPropertyLabel(filter) {
|
|
11
|
+
return __1.getPropertyLabel(filter.column, filter.property);
|
|
12
|
+
}
|
|
13
|
+
exports.getFilterPropertyLabel = getFilterPropertyLabel;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './excludeUIFiltersByAggregate';
|
|
2
2
|
export * from './excludeUIFlatFiltersByScopes';
|
|
3
|
+
export * from './getFilterPropertyLabel';
|
|
3
4
|
export * from './getOutputFormatByColumn';
|
|
4
5
|
export * from './getUIFlatFilterByParams';
|
|
5
6
|
export * from './getUIFlatFiltersByParams';
|
|
@@ -12,6 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./excludeUIFiltersByAggregate"), exports);
|
|
14
14
|
__exportStar(require("./excludeUIFlatFiltersByScopes"), exports);
|
|
15
|
+
__exportStar(require("./getFilterPropertyLabel"), exports);
|
|
15
16
|
__exportStar(require("./getOutputFormatByColumn"), exports);
|
|
16
17
|
__exportStar(require("./getUIFlatFilterByParams"), exports);
|
|
17
18
|
__exportStar(require("./getUIFlatFiltersByParams"), exports);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Filters a nested tree array by a custom condition on the
|
|
2
|
+
* Filters a nested tree array by a custom condition on the last child node
|
|
3
|
+
* - If the given arguments are not valid, the function returns the first argument.
|
|
4
|
+
* - If the childArrKey is not matched in the object, the condition tries to resolve the filter anyway and returns an empty array.
|
|
5
|
+
* - If the condition is not fulfilled, the function returns a filtered array, probably a empty array inside of the child array
|
|
3
6
|
* @param arr nested tree array
|
|
4
7
|
* @param childArrKey property representing the children array on the nested tree
|
|
5
8
|
* @param condition function callback that determines if the filter is applied on the last child node of the nested tree
|
|
6
9
|
* @returns array filtered
|
|
7
10
|
*/
|
|
8
|
-
export declare function filterNestedTree(arr
|
|
11
|
+
export declare function filterNestedTree<T = any>(arr?: T[], childArrKey?: string, condition?: any): T[];
|
|
@@ -4,20 +4,28 @@ exports.filterNestedTree = void 0;
|
|
|
4
4
|
const mix_1 = require("../mix");
|
|
5
5
|
const cloneDeep_1 = require("../object/cloneDeep");
|
|
6
6
|
/**
|
|
7
|
-
* Filters a nested tree array by a custom condition on the
|
|
7
|
+
* Filters a nested tree array by a custom condition on the last child node
|
|
8
|
+
* - If the given arguments are not valid, the function returns the first argument.
|
|
9
|
+
* - If the childArrKey is not matched in the object, the condition tries to resolve the filter anyway and returns an empty array.
|
|
10
|
+
* - If the condition is not fulfilled, the function returns a filtered array, probably a empty array inside of the child array
|
|
8
11
|
* @param arr nested tree array
|
|
9
12
|
* @param childArrKey property representing the children array on the nested tree
|
|
10
13
|
* @param condition function callback that determines if the filter is applied on the last child node of the nested tree
|
|
11
14
|
* @returns array filtered
|
|
12
15
|
*/
|
|
13
|
-
function filterNestedTree(arr, childArrKey, condition) {
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
16
|
+
function filterNestedTree(arr = [], childArrKey = '', condition = undefined) {
|
|
17
|
+
if (!isValid(arr, childArrKey, condition))
|
|
18
|
+
return arr;
|
|
16
19
|
return cloneDeep_1.cloneDeep(arr).filter(obj => {
|
|
17
|
-
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length;
|
|
20
|
+
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length > 0;
|
|
18
21
|
if (hasChildArr)
|
|
19
22
|
obj[childArrKey] = filterNestedTree(obj[childArrKey], childArrKey, condition);
|
|
20
23
|
return hasChildArr || condition(obj);
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
exports.filterNestedTree = filterNestedTree;
|
|
27
|
+
function isValid(arr = [], childArrKey = '', condition = undefined) {
|
|
28
|
+
return (!mix_1.isEmpty(arr) && Array.isArray(arr))
|
|
29
|
+
&& (!mix_1.isEmpty(childArrKey) && typeof childArrKey === 'string')
|
|
30
|
+
&& (!mix_1.isEmpty(condition) && typeof condition === "function");
|
|
31
|
+
}
|
|
@@ -16,6 +16,8 @@ function isEmpty(variable, includeFalsy = false) {
|
|
|
16
16
|
|| (typeof variable == 'boolean' && includeFalsy && variable === false)
|
|
17
17
|
|| (Array.isArray(variable) && variable.length === 0)
|
|
18
18
|
|| ((_1.getTag(variable) === '[object Map]' || _1.getTag(variable) === '[object Set]') && variable.size === 0)
|
|
19
|
-
|| (
|
|
19
|
+
|| (variable instanceof Date && isNaN(variable.valueOf()))
|
|
20
|
+
|| (typeof variable === 'function' && Object.prototype.toString.call(variable).indexOf("Function") === 0)
|
|
21
|
+
|| ((!(variable instanceof Date) && typeof variable !== 'function') && __1.isObject(variable) && Object.entries(variable).length === 0);
|
|
20
22
|
}
|
|
21
23
|
exports.isEmpty = isEmpty;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Creates a random string
|
|
3
|
+
* - If the first given argument is different than a length number, the variable is replaced by a default number
|
|
4
|
+
* - If the optional second given argument is passed the random string is permutated.
|
|
3
5
|
* @param {Number} length size of the generated string. Default 8
|
|
4
|
-
* @
|
|
6
|
+
* @param {Array} exclude collection of strings that is going to be excluded of the random string.
|
|
7
|
+
* @return {String} Random string
|
|
5
8
|
*/
|
|
6
|
-
export declare function randomId(
|
|
9
|
+
export declare function randomId(length?: number, exclude?: string[]): string;
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randomId = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
+
* Creates a random string
|
|
7
|
+
* - If the first given argument is different than a length number, the variable is replaced by a default number
|
|
8
|
+
* - If the optional second given argument is passed the random string is permutated.
|
|
6
9
|
* @param {Number} length size of the generated string. Default 8
|
|
7
|
-
* @
|
|
10
|
+
* @param {Array} exclude collection of strings that is going to be excluded of the random string.
|
|
11
|
+
* @return {String} Random string
|
|
8
12
|
*/
|
|
9
|
-
function randomId(
|
|
13
|
+
function randomId(length = 8, exclude = []) {
|
|
14
|
+
if (typeof length !== 'number')
|
|
15
|
+
length = 8;
|
|
16
|
+
if (_1.isNull(exclude) || !Array.isArray(exclude))
|
|
17
|
+
exclude = [];
|
|
18
|
+
exclude = exclude.filter(e => typeof e === 'string');
|
|
10
19
|
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
|
|
20
|
+
const blackList = [];
|
|
11
21
|
let id = '';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
do {
|
|
23
|
+
if (!_1.isEmpty(id) && !blackList.includes(id))
|
|
24
|
+
blackList.push(id);
|
|
25
|
+
id = '';
|
|
26
|
+
for (let i = 0; i < length; i++) {
|
|
27
|
+
const randPos = Math.floor(Math.random() * charSet.length);
|
|
28
|
+
id += charSet[randPos];
|
|
29
|
+
}
|
|
30
|
+
} while (exclude.length > 0 && exclude.includes(id) && blackList.length < exclude.length);
|
|
31
|
+
if (exclude.length > 0 && blackList.length >= exclude.length)
|
|
32
|
+
id = '';
|
|
16
33
|
return id;
|
|
17
34
|
}
|
|
18
35
|
exports.randomId = randomId;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* For `null` or `undefined` argument the returned value will be 0.
|
|
5
|
-
* @param {Any} obj
|
|
6
|
-
* @returns {Number}
|
|
2
|
+
* Gets the length of the given array.
|
|
3
|
+
* - Useful for Object, Array and string type.
|
|
4
|
+
* - For `null` or `undefined` or else argument the returned value will be 0.
|
|
5
|
+
* @param {Any} obj Any object-type variable
|
|
6
|
+
* @returns {Number} the size of the given variable
|
|
7
7
|
*/
|
|
8
8
|
export declare function size(obj: any): number;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.size = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* For `null` or `undefined` argument the returned value will be 0.
|
|
8
|
-
* @param {Any} obj
|
|
9
|
-
* @returns {Number}
|
|
6
|
+
* Gets the length of the given array.
|
|
7
|
+
* - Useful for Object, Array and string type.
|
|
8
|
+
* - For `null` or `undefined` or else argument the returned value will be 0.
|
|
9
|
+
* @param {Any} obj Any object-type variable
|
|
10
|
+
* @returns {Number} the size of the given variable
|
|
10
11
|
*/
|
|
11
12
|
function size(obj) {
|
|
12
|
-
|
|
13
|
+
if (_1.isEmpty(obj))
|
|
14
|
+
return 0;
|
|
15
|
+
return Object.keys(obj).length;
|
|
13
16
|
}
|
|
14
17
|
exports.size = size;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* _get({ item1: { item11: 'Hello Again' }, item2: {} }, ['item1', 'item11'])
|
|
27
27
|
* @returns the resolved value.
|
|
28
28
|
*/
|
|
29
|
-
export declare function _get(baseObject:
|
|
29
|
+
export declare function _get<T = any>(baseObject: T, path: string | string[], defaultValue?: any): any;
|
|
30
30
|
/**
|
|
31
31
|
*
|
|
32
32
|
* /**
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Searchs for properties in different case styles such as: lower, upper, camel and pascal
|
|
3
|
+
* - To optimize the searching, it is required a key in a snake_case style
|
|
4
|
+
* - List of cases that do not match
|
|
5
|
+
* -- From lower to snake case
|
|
6
|
+
* -- From upper to snake case
|
|
7
|
+
* -- From lower to camel case
|
|
8
|
+
* -- From upper to camel case
|
|
9
|
+
* -- From lower to pascal case
|
|
10
|
+
* -- From upper to pascal case
|
|
4
11
|
* @param {object} obj object to look for
|
|
5
12
|
* @param {string} key String attribute in snake_case style
|
|
6
13
|
*
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Searchs for properties in different case styles such as: lower, upper, camel and pascal
|
|
4
|
+
* - To optimize the searching, it is required a key in a snake_case style
|
|
5
|
+
* - List of cases that do not match
|
|
6
|
+
* -- From lower to snake case
|
|
7
|
+
* -- From upper to snake case
|
|
8
|
+
* -- From lower to camel case
|
|
9
|
+
* -- From upper to camel case
|
|
10
|
+
* -- From lower to pascal case
|
|
11
|
+
* -- From upper to pascal case
|
|
5
12
|
* @param {object} obj object to look for
|
|
6
13
|
* @param {string} key String attribute in snake_case style
|
|
7
14
|
*
|
|
@@ -10,12 +17,36 @@
|
|
|
10
17
|
*/
|
|
11
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
19
|
exports.getAttribute = void 0;
|
|
20
|
+
const _1 = require(".");
|
|
21
|
+
const __1 = require("..");
|
|
13
22
|
function getAttribute(obj, key) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
24
|
+
if (!isValid(obj, key))
|
|
25
|
+
return;
|
|
26
|
+
const snake = getSnakeCase(key);
|
|
27
|
+
const camel = getCamelCase(snake);
|
|
28
|
+
const pascal = getPascalCase(camel);
|
|
29
|
+
const lower = getLowerCase(pascal);
|
|
30
|
+
const upper = getUpperCase(lower);
|
|
31
|
+
return (_e = (_d = (_c = (_b = (_a = obj[key]) !== null && _a !== void 0 ? _a : obj[snake]) !== null && _b !== void 0 ? _b : obj[camel]) !== null && _c !== void 0 ? _c : obj[pascal]) !== null && _d !== void 0 ? _d : obj[lower]) !== null && _e !== void 0 ? _e : obj[upper];
|
|
20
32
|
}
|
|
21
33
|
exports.getAttribute = getAttribute;
|
|
34
|
+
function getSnakeCase(key) {
|
|
35
|
+
return key.replace(/[A-Z]/g, (a, i) => i == 0 ? a.toLowerCase() : '_' + a.toLowerCase());
|
|
36
|
+
}
|
|
37
|
+
function getCamelCase(key) {
|
|
38
|
+
return key.replace(/(.)/, (_, a) => a.toLowerCase()).replace(/_(.)/g, (_, a) => a.toUpperCase());
|
|
39
|
+
}
|
|
40
|
+
function getPascalCase(key) {
|
|
41
|
+
return key.replace(/(.)/, (_, a) => a.toUpperCase());
|
|
42
|
+
}
|
|
43
|
+
function getLowerCase(key) {
|
|
44
|
+
return key.replace(/_/g, '').toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
function getUpperCase(key) {
|
|
47
|
+
return key.toUpperCase();
|
|
48
|
+
}
|
|
49
|
+
function isValid(obj, key) {
|
|
50
|
+
return (!__1.isEmpty(obj) && _1.isObject(obj))
|
|
51
|
+
&& (!__1.isEmpty(key) && typeof key === 'string');
|
|
52
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._hasProperty = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const __1 = require("..");
|
|
2
6
|
/**
|
|
3
7
|
* Use the hasOwnProperty in order to verify if the given property exists in the object.
|
|
4
8
|
*
|
|
@@ -15,9 +19,13 @@
|
|
|
15
19
|
* const obj2 = { prop1: 'hello world' }
|
|
16
20
|
* _hasProperty(ob1, prop2) // false
|
|
17
21
|
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports._hasProperty = void 0;
|
|
20
22
|
function _hasProperty(obj = {}, property = '') {
|
|
23
|
+
if (!isValid(obj, property))
|
|
24
|
+
return false;
|
|
21
25
|
return Object.prototype.hasOwnProperty.call(obj, property);
|
|
22
26
|
}
|
|
23
27
|
exports._hasProperty = _hasProperty;
|
|
28
|
+
function isValid(obj, property) {
|
|
29
|
+
return !__1.isEmpty(obj) && (_1.isObject(obj) || Array.isArray(obj))
|
|
30
|
+
&& !__1.isEmpty(property) && (typeof property === 'string' || typeof property === 'number');
|
|
31
|
+
}
|
|
@@ -15,6 +15,7 @@ __exportStar(require("./get"), exports);
|
|
|
15
15
|
__exportStar(require("./getAttribute"), exports);
|
|
16
16
|
__exportStar(require("./hasProperty"), exports);
|
|
17
17
|
__exportStar(require("./isObject"), exports);
|
|
18
|
+
__exportStar(require("./objectCopy"), exports);
|
|
18
19
|
__exportStar(require("./omit"), exports);
|
|
19
20
|
__exportStar(require("./pick"), exports);
|
|
20
21
|
__exportStar(require("./mapValues"), exports);
|
|
@@ -8,6 +8,6 @@ const __1 = require("..");
|
|
|
8
8
|
* @returns True: It is an object; False: It is not.
|
|
9
9
|
*/
|
|
10
10
|
function isObject(obj) {
|
|
11
|
-
return __1.getTag(obj) === '[object Object]';
|
|
11
|
+
return obj === Object(obj) || __1.getTag(obj) === '[object Object]';
|
|
12
12
|
}
|
|
13
13
|
exports.isObject = isObject;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectCopy = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Created a new reference of the given argument
|
|
6
|
+
* @param entity The variable to be copied
|
|
7
|
+
* @param cache
|
|
8
|
+
* @returns A new reference of the given argument
|
|
9
|
+
*/
|
|
10
|
+
function objectCopy(entity, cache = new WeakMap()) {
|
|
11
|
+
if (!isClonable(entity))
|
|
12
|
+
return entity;
|
|
13
|
+
if (cache.has(entity))
|
|
14
|
+
return cache.get(entity);
|
|
15
|
+
const c = new entity.constructor;
|
|
16
|
+
if (c.name === 'Date')
|
|
17
|
+
return new Date(entity);
|
|
18
|
+
if (entity instanceof Map) {
|
|
19
|
+
entity.forEach((value, key) => c.set(objectCopy(key), objectCopy(value)));
|
|
20
|
+
}
|
|
21
|
+
if (entity instanceof Set) {
|
|
22
|
+
entity.forEach((value) => c.add(objectCopy(value)));
|
|
23
|
+
}
|
|
24
|
+
cache.set(entity, c);
|
|
25
|
+
return Object.assign(c, ...Object.keys(entity).map((prop) => ({ [prop]: objectCopy(entity[prop], cache) })));
|
|
26
|
+
}
|
|
27
|
+
exports.objectCopy = objectCopy;
|
|
28
|
+
function isClonable(entity) {
|
|
29
|
+
const referenceTypes = ['Array', 'Object', 'Map', 'Set', 'Date'];
|
|
30
|
+
const entityName = entity && entity.constructor.name;
|
|
31
|
+
return referenceTypes.includes(entityName);
|
|
32
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Upper case
|
|
2
|
+
* Upper case the first letter of a given text
|
|
3
3
|
* @param {String} text
|
|
4
|
-
* @returns {String}
|
|
4
|
+
* @returns {String} a capitalized text
|
|
5
5
|
*/
|
|
6
|
-
export declare function capitalize(text
|
|
6
|
+
export declare function capitalize(text?: string): string;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.capitalize = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
4
5
|
/**
|
|
5
|
-
* Upper case
|
|
6
|
+
* Upper case the first letter of a given text
|
|
6
7
|
* @param {String} text
|
|
7
|
-
* @returns {String}
|
|
8
|
+
* @returns {String} a capitalized text
|
|
8
9
|
*/
|
|
9
|
-
function capitalize(text) {
|
|
10
|
+
function capitalize(text = '') {
|
|
11
|
+
if (__1.isEmpty(text) || typeof text !== 'string')
|
|
12
|
+
return text;
|
|
10
13
|
return text.toLowerCase().replace(/^\w/, c => c.toUpperCase());
|
|
11
14
|
}
|
|
12
15
|
exports.capitalize = capitalize;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropertyLabel = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
function getPropertyLabel(column, property) {
|
|
7
|
+
var _a;
|
|
8
|
+
let propertyLabel;
|
|
9
|
+
const propertyValues = __1.COLUMN_PROPERTY_VALUE[_1.isDateColumn(column) ? 'DATE-complete' : column.type];
|
|
10
|
+
if (!__1.isEmpty(propertyValues))
|
|
11
|
+
propertyLabel = (_a = propertyValues.find(pValue => pValue.value === property)) === null || _a === void 0 ? void 0 : _a.label;
|
|
12
|
+
return propertyLabel;
|
|
13
|
+
}
|
|
14
|
+
exports.getPropertyLabel = getPropertyLabel;
|