@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
package/dist/cjs/qrvey/index.js
CHANGED
|
@@ -11,5 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./getColumnsLabel"), exports);
|
|
14
|
+
__exportStar(require("./getPropertyLabel"), exports);
|
|
14
15
|
__exportStar(require("./isDateColumn"), exports);
|
|
15
16
|
__exportStar(require("./isComplexColumn"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DATE_P_VALUES, DATE_TIME_P_VALUES } from "../date";
|
|
1
|
+
import { DATE_P_VALUES, DATE_TIME_VALUES, DATE_TIME_P_VALUES } from "../date";
|
|
2
2
|
import { DATE_VALUES } from "../date/constants/DATE_VALUES";
|
|
3
3
|
import { COLUMN } from "./COLUMN";
|
|
4
4
|
import { COLUMN_COMPLEX_VALUE } from "./COLUMN_COMPLEX_VALUE";
|
|
@@ -18,5 +18,5 @@ const C = {
|
|
|
18
18
|
[COLUMN.EXPRESSION]: COLUMN_COMPLEX_VALUE.EXPRESSION.map(setTabStructure),
|
|
19
19
|
[COLUMN.IMAGEUPLOAD]: COLUMN_COMPLEX_VALUE.IMAGEUPLOAD.map(setTabStructure),
|
|
20
20
|
};
|
|
21
|
-
C[COLUMN.DATE + '-complete'] = C[COLUMN.DATE].concat(DATE_P_VALUES).concat(DATE_TIME_P_VALUES);
|
|
21
|
+
C[COLUMN.DATE + '-complete'] = C[COLUMN.DATE].concat(DATE_TIME_VALUES).concat(DATE_P_VALUES).concat(DATE_TIME_P_VALUES);
|
|
22
22
|
export const COLUMN_PROPERTY_VALUE = C;
|
|
@@ -3,5 +3,5 @@ export const DATE_VALUES = [
|
|
|
3
3
|
{ value: "year" /* DATE_YEAR */, label: 'Year', display: true },
|
|
4
4
|
{ value: "quarter" /* DATE_QUARTER */, label: 'Quarter, Year', display: true },
|
|
5
5
|
{ value: "month" /* DATE_MONTH */, label: 'Month, Year', display: true },
|
|
6
|
-
{ value: "week" /* DATE_WEEK */, label: '
|
|
6
|
+
{ value: "week" /* DATE_WEEK */, label: 'Week, Year', display: true }
|
|
7
7
|
];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cloneDeep, isEmpty, _get } from "../../general";
|
|
2
2
|
import { getUIValues } from "../helpers";
|
|
3
3
|
import { adaptDateGroupingProperty } from "./adaptDateGroupingProperty";
|
|
4
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
4
5
|
/**
|
|
5
6
|
* Generates a Flattened UI filter structure from Filter Data structure.
|
|
6
7
|
* @param filterData The filter data object.
|
|
@@ -80,7 +81,7 @@ function FD21ToFlatUI(scopes = [], datasetsInfo = []) {
|
|
|
80
81
|
property: property,
|
|
81
82
|
uiValues: getUIValues(filter),
|
|
82
83
|
validator: filter.validator,
|
|
83
|
-
values: filter
|
|
84
|
+
values: adaptFilterValues(filter),
|
|
84
85
|
};
|
|
85
86
|
uFilters.push(uFilter);
|
|
86
87
|
});
|
|
@@ -2,6 +2,7 @@ import { adaptDateGroupingProperty } from ".";
|
|
|
2
2
|
import { cloneDeep, isEmpty, _get } from "../../general";
|
|
3
3
|
import { FILTER_STRUCTURE_VERSION } from "../constants";
|
|
4
4
|
import { getUIValues } from "../helpers";
|
|
5
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
5
6
|
/**
|
|
6
7
|
* Generates a UI filter structure from Filter Data structure.
|
|
7
8
|
* @param filterData The filter data object.
|
|
@@ -56,7 +57,7 @@ function FD21ToUI(scopes = [], section = "ANYWHERE" /* ANYWHERE */, enabled = tr
|
|
|
56
57
|
outputFormat: _get(datasetInfo, 'outputFormat'),
|
|
57
58
|
qrveyid: filter.column.qrveyid,
|
|
58
59
|
type: (columnInfo === null || columnInfo === void 0 ? void 0 : columnInfo.type) || filter.column.type,
|
|
59
|
-
}, property, uiValues: getUIValues(filter) });
|
|
60
|
+
}, property, uiValues: getUIValues(filter), values: adaptFilterValues(filter) });
|
|
60
61
|
}) });
|
|
61
62
|
}) })));
|
|
62
63
|
return ufData;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { adaptDateGroupingProperty } from ".";
|
|
2
2
|
import { cloneDeep, isEmpty } from "../../general";
|
|
3
3
|
import { getUIValues } from "../helpers";
|
|
4
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
4
5
|
/**
|
|
5
6
|
* Generates a Flattened UI filter structure from UI Filter Data structure.
|
|
6
7
|
* @param filterData The UI filter data object.
|
|
@@ -79,7 +80,7 @@ function UI21ToFlatUI(scopes = [], datasetsInfo = []) {
|
|
|
79
80
|
property,
|
|
80
81
|
uiValues: getUIValues(filter),
|
|
81
82
|
validator: filter.validator,
|
|
82
|
-
values: filter
|
|
83
|
+
values: adaptFilterValues(filter),
|
|
83
84
|
};
|
|
84
85
|
uFilters.push(uFilter);
|
|
85
86
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { adaptDateGroupingProperty } from ".";
|
|
2
2
|
import { cloneDeep, isEmpty } from "../../general";
|
|
3
3
|
import { getBackendGroupValue, getBackendProperty, getBackendValidator, getBackendValues, getUIValues } from "../helpers";
|
|
4
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
4
5
|
import { flatUIToOldLogic } from "./flatUIToOldLogic";
|
|
5
6
|
import { UIToFlatUI } from "./UIToFlatUI";
|
|
6
7
|
export function UIToOldLogic(uFilterData, flattedMethod = true) {
|
|
@@ -137,6 +138,6 @@ const getFilterDetail = (filter, scope, dataset) => {
|
|
|
137
138
|
section: filter.extras.section,
|
|
138
139
|
uiValue: getUIValues(filter, true),
|
|
139
140
|
validator: filter.validator,
|
|
140
|
-
values: filter
|
|
141
|
+
values: adaptFilterValues(filter)
|
|
141
142
|
};
|
|
142
143
|
};
|
|
@@ -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,14 @@
|
|
|
1
|
+
import { COLUMN, isEmpty } 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 function adaptFilterValues(filter) {
|
|
9
|
+
const setValue = value => (Object.assign(Object.assign({}, value), { enabled: isEmpty(value.enabled) ? true : value.enabled }));
|
|
10
|
+
if (filter.column.type === COLUMN.RANKING && isEmpty(filter.column.aggregate)) {
|
|
11
|
+
return filter.values.map(rValues => rValues.map(setValue));
|
|
12
|
+
}
|
|
13
|
+
return filter.values.map(setValue);
|
|
14
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { adaptDateGroupingProperty } from ".";
|
|
2
2
|
import { isEmpty } from "../../general";
|
|
3
3
|
import { FILTER_STRUCTURE_VERSION } from "../constants";
|
|
4
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
4
5
|
/**
|
|
5
6
|
* Generates a filter data structure from the flatttened UI filters.
|
|
6
7
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -98,6 +99,6 @@ function buildFilter(uFilter) {
|
|
|
98
99
|
operator: uFilter.operator,
|
|
99
100
|
property,
|
|
100
101
|
validator: uFilter.validator,
|
|
101
|
-
values: uFilter
|
|
102
|
+
values: adaptFilterValues(uFilter),
|
|
102
103
|
};
|
|
103
104
|
}
|
|
@@ -2,6 +2,7 @@ import { adaptDateGroupingProperty } from ".";
|
|
|
2
2
|
import { isEmpty, getLastIndexFromArray } from "../../general";
|
|
3
3
|
import { FILTER_STRUCTURE_VERSION } from "../constants";
|
|
4
4
|
import { getUIValues } from "../helpers";
|
|
5
|
+
import { adaptFilterValues } from "./adaptFilterValues";
|
|
5
6
|
/**
|
|
6
7
|
* Generates a UI filter data structure from the flatttened UI filters.
|
|
7
8
|
* @param uFilters Array of flattened filters from UI
|
|
@@ -113,6 +114,6 @@ function buildFilter(uFilter) {
|
|
|
113
114
|
property,
|
|
114
115
|
uiValues: getUIValues(uFilter),
|
|
115
116
|
validator: uFilter.validator,
|
|
116
|
-
values: uFilter
|
|
117
|
+
values: adaptFilterValues(uFilter),
|
|
117
118
|
};
|
|
118
119
|
}
|
|
@@ -22,9 +22,6 @@ export function logicToFlatUI(logics = []) {
|
|
|
22
22
|
buildFilterByExpression(expression2, scopeItem, uFilters);
|
|
23
23
|
}) : buildFilterByExpression(expression1, scopeItem, uFilters);
|
|
24
24
|
});
|
|
25
|
-
// (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
|
|
26
|
-
// buildFilterByExpression(expression, scopeItem, uFilters);
|
|
27
|
-
// });
|
|
28
25
|
});
|
|
29
26
|
}
|
|
30
27
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isComplexColumn } from "../../../qrvey/isComplexColumn";
|
|
2
|
-
import { COLUMN_COMPLEX_VALUE } from "../../../constants";
|
|
2
|
+
import { AGGREGATE_ABBREVIATION, COLUMN_COMPLEX_VALUE } from "../../../constants";
|
|
3
3
|
/**
|
|
4
4
|
* Get an string of the properties of the given filter column.
|
|
5
5
|
* @param column The filter column
|
|
@@ -10,7 +10,7 @@ export function getFilterColumnLabel(column) {
|
|
|
10
10
|
if (isComplexColumn(column) && column.property != null)
|
|
11
11
|
labels.push(COLUMN_COMPLEX_VALUE[column.property].shortLabel);
|
|
12
12
|
if (column.aggregate != null)
|
|
13
|
-
labels.push(column.aggregate);
|
|
13
|
+
labels.push(AGGREGATE_ABBREVIATION[column.aggregate]);
|
|
14
14
|
if (column.calculation != null)
|
|
15
15
|
labels.push(column.calculation);
|
|
16
16
|
return labels.length > 0 ? `(${labels.join(' - ')})` : '';
|
|
@@ -34,7 +34,7 @@ export function getFiltersByParams(filterData, params, settings) {
|
|
|
34
34
|
return Object.assign(Object.assign({}, filter), { values: filter.values.map((value) => {
|
|
35
35
|
if (Array.isArray(value) && value.length > 0) {
|
|
36
36
|
const rankingValues = value;
|
|
37
|
-
rankingValues.map(rValue => {
|
|
37
|
+
return rankingValues.map(rValue => {
|
|
38
38
|
if (!_hasProperty(params, 'enableds') || !_hasProperty(params.enableds, 'values') || params.enableds.values === rValue.enabled)
|
|
39
39
|
return rValue;
|
|
40
40
|
}).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,9 @@
|
|
|
1
|
+
import { getPropertyLabel } 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 function getFilterPropertyLabel(filter) {
|
|
8
|
+
return getPropertyLabel(filter.column, filter.property);
|
|
9
|
+
}
|
|
@@ -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';
|
|
@@ -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';
|
|
@@ -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[];
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { isEmpty } from "../mix";
|
|
2
2
|
import { cloneDeep } from "../object/cloneDeep";
|
|
3
3
|
/**
|
|
4
|
-
* Filters a nested tree array by a custom condition on the
|
|
4
|
+
* Filters a nested tree array by a custom condition on the last child node
|
|
5
|
+
* - If the given arguments are not valid, the function returns the first argument.
|
|
6
|
+
* - If the childArrKey is not matched in the object, the condition tries to resolve the filter anyway and returns an empty array.
|
|
7
|
+
* - If the condition is not fulfilled, the function returns a filtered array, probably a empty array inside of the child array
|
|
5
8
|
* @param arr nested tree array
|
|
6
9
|
* @param childArrKey property representing the children array on the nested tree
|
|
7
10
|
* @param condition function callback that determines if the filter is applied on the last child node of the nested tree
|
|
8
11
|
* @returns array filtered
|
|
9
12
|
*/
|
|
10
|
-
export function filterNestedTree(arr, childArrKey, condition) {
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
+
export function filterNestedTree(arr = [], childArrKey = '', condition = undefined) {
|
|
14
|
+
if (!isValid(arr, childArrKey, condition))
|
|
15
|
+
return arr;
|
|
13
16
|
return cloneDeep(arr).filter(obj => {
|
|
14
|
-
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length;
|
|
17
|
+
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length > 0;
|
|
15
18
|
if (hasChildArr)
|
|
16
19
|
obj[childArrKey] = filterNestedTree(obj[childArrKey], childArrKey, condition);
|
|
17
20
|
return hasChildArr || condition(obj);
|
|
18
21
|
});
|
|
19
22
|
}
|
|
23
|
+
function isValid(arr = [], childArrKey = '', condition = undefined) {
|
|
24
|
+
return (!isEmpty(arr) && Array.isArray(arr))
|
|
25
|
+
&& (!isEmpty(childArrKey) && typeof childArrKey === 'string')
|
|
26
|
+
&& (!isEmpty(condition) && typeof condition === "function");
|
|
27
|
+
}
|
|
@@ -13,5 +13,7 @@ export function isEmpty(variable, includeFalsy = false) {
|
|
|
13
13
|
|| (typeof variable == 'boolean' && includeFalsy && variable === false)
|
|
14
14
|
|| (Array.isArray(variable) && variable.length === 0)
|
|
15
15
|
|| ((getTag(variable) === '[object Map]' || getTag(variable) === '[object Set]') && variable.size === 0)
|
|
16
|
-
|| (
|
|
16
|
+
|| (variable instanceof Date && isNaN(variable.valueOf()))
|
|
17
|
+
|| (typeof variable === 'function' && Object.prototype.toString.call(variable).indexOf("Function") === 0)
|
|
18
|
+
|| ((!(variable instanceof Date) && typeof variable !== 'function') && isObject(variable) && Object.entries(variable).length === 0);
|
|
17
19
|
}
|
|
@@ -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,14 +1,31 @@
|
|
|
1
|
+
import { isEmpty, isNull } from ".";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Creates a random string
|
|
4
|
+
* - If the first given argument is different than a length number, the variable is replaced by a default number
|
|
5
|
+
* - If the optional second given argument is passed the random string is permutated.
|
|
3
6
|
* @param {Number} length size of the generated string. Default 8
|
|
4
|
-
* @
|
|
7
|
+
* @param {Array} exclude collection of strings that is going to be excluded of the random string.
|
|
8
|
+
* @return {String} Random string
|
|
5
9
|
*/
|
|
6
|
-
export function randomId(
|
|
10
|
+
export function randomId(length = 8, exclude = []) {
|
|
11
|
+
if (typeof length !== 'number')
|
|
12
|
+
length = 8;
|
|
13
|
+
if (isNull(exclude) || !Array.isArray(exclude))
|
|
14
|
+
exclude = [];
|
|
15
|
+
exclude = exclude.filter(e => typeof e === 'string');
|
|
7
16
|
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
|
|
17
|
+
const blackList = [];
|
|
8
18
|
let id = '';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
do {
|
|
20
|
+
if (!isEmpty(id) && !blackList.includes(id))
|
|
21
|
+
blackList.push(id);
|
|
22
|
+
id = '';
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
const randPos = Math.floor(Math.random() * charSet.length);
|
|
25
|
+
id += charSet[randPos];
|
|
26
|
+
}
|
|
27
|
+
} while (exclude.length > 0 && exclude.includes(id) && blackList.length < exclude.length);
|
|
28
|
+
if (exclude.length > 0 && blackList.length >= exclude.length)
|
|
29
|
+
id = '';
|
|
13
30
|
return id;
|
|
14
31
|
}
|
|
@@ -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;
|
package/dist/general/mix/size.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { isEmpty } from ".";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* For `null` or `undefined` argument the returned value will be 0.
|
|
5
|
-
* @param {Any} obj
|
|
6
|
-
* @returns {Number}
|
|
3
|
+
* Gets the length of the given array.
|
|
4
|
+
* - Useful for Object, Array and string type.
|
|
5
|
+
* - For `null` or `undefined` or else argument the returned value will be 0.
|
|
6
|
+
* @param {Any} obj Any object-type variable
|
|
7
|
+
* @returns {Number} the size of the given variable
|
|
7
8
|
*/
|
|
8
9
|
export function size(obj) {
|
|
9
|
-
|
|
10
|
+
if (isEmpty(obj))
|
|
11
|
+
return 0;
|
|
12
|
+
return Object.keys(obj).length;
|
|
10
13
|
}
|
|
@@ -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,17 +1,48 @@
|
|
|
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
|
*
|
|
7
14
|
* @example
|
|
8
15
|
* getAttribute(obj, 'snake_case') //it search for: obj.snake_case || obj.snakeCase || obj.SnakeCase || obj.snakecase || obj.SNAKECASE
|
|
9
16
|
*/
|
|
17
|
+
import { isObject } from ".";
|
|
18
|
+
import { isEmpty } from "..";
|
|
10
19
|
export function getAttribute(obj, key) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
if (!isValid(obj, key))
|
|
22
|
+
return;
|
|
23
|
+
const snake = getSnakeCase(key);
|
|
24
|
+
const camel = getCamelCase(snake);
|
|
25
|
+
const pascal = getPascalCase(camel);
|
|
26
|
+
const lower = getLowerCase(pascal);
|
|
27
|
+
const upper = getUpperCase(lower);
|
|
28
|
+
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];
|
|
29
|
+
}
|
|
30
|
+
function getSnakeCase(key) {
|
|
31
|
+
return key.replace(/[A-Z]/g, (a, i) => i == 0 ? a.toLowerCase() : '_' + a.toLowerCase());
|
|
32
|
+
}
|
|
33
|
+
function getCamelCase(key) {
|
|
34
|
+
return key.replace(/(.)/, (_, a) => a.toLowerCase()).replace(/_(.)/g, (_, a) => a.toUpperCase());
|
|
35
|
+
}
|
|
36
|
+
function getPascalCase(key) {
|
|
37
|
+
return key.replace(/(.)/, (_, a) => a.toUpperCase());
|
|
38
|
+
}
|
|
39
|
+
function getLowerCase(key) {
|
|
40
|
+
return key.replace(/_/g, '').toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
function getUpperCase(key) {
|
|
43
|
+
return key.toUpperCase();
|
|
44
|
+
}
|
|
45
|
+
function isValid(obj, key) {
|
|
46
|
+
return (!isEmpty(obj) && isObject(obj))
|
|
47
|
+
&& (!isEmpty(key) && typeof key === 'string');
|
|
17
48
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isObject } from ".";
|
|
2
|
+
import { isEmpty } from "..";
|
|
1
3
|
/**
|
|
2
4
|
* Use the hasOwnProperty in order to verify if the given property exists in the object.
|
|
3
5
|
*
|
|
@@ -15,5 +17,11 @@
|
|
|
15
17
|
* _hasProperty(ob1, prop2) // false
|
|
16
18
|
*/
|
|
17
19
|
export function _hasProperty(obj = {}, property = '') {
|
|
20
|
+
if (!isValid(obj, property))
|
|
21
|
+
return false;
|
|
18
22
|
return Object.prototype.hasOwnProperty.call(obj, property);
|
|
19
23
|
}
|
|
24
|
+
function isValid(obj, property) {
|
|
25
|
+
return !isEmpty(obj) && (isObject(obj) || Array.isArray(obj))
|
|
26
|
+
&& !isEmpty(property) && (typeof property === 'string' || typeof property === 'number');
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created a new reference of the given argument
|
|
3
|
+
* @param entity The variable to be copied
|
|
4
|
+
* @param cache
|
|
5
|
+
* @returns A new reference of the given argument
|
|
6
|
+
*/
|
|
7
|
+
export function objectCopy(entity, cache = new WeakMap()) {
|
|
8
|
+
if (!isClonable(entity))
|
|
9
|
+
return entity;
|
|
10
|
+
if (cache.has(entity))
|
|
11
|
+
return cache.get(entity);
|
|
12
|
+
const c = new entity.constructor;
|
|
13
|
+
if (c.name === 'Date')
|
|
14
|
+
return new Date(entity);
|
|
15
|
+
if (entity instanceof Map) {
|
|
16
|
+
entity.forEach((value, key) => c.set(objectCopy(key), objectCopy(value)));
|
|
17
|
+
}
|
|
18
|
+
if (entity instanceof Set) {
|
|
19
|
+
entity.forEach((value) => c.add(objectCopy(value)));
|
|
20
|
+
}
|
|
21
|
+
cache.set(entity, c);
|
|
22
|
+
return Object.assign(c, ...Object.keys(entity).map((prop) => ({ [prop]: objectCopy(entity[prop], cache) })));
|
|
23
|
+
}
|
|
24
|
+
function isClonable(entity) {
|
|
25
|
+
const referenceTypes = ['Array', 'Object', 'Map', 'Set', 'Date'];
|
|
26
|
+
const entityName = entity && entity.constructor.name;
|
|
27
|
+
return referenceTypes.includes(entityName);
|
|
28
|
+
}
|
|
@@ -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,8 +1,11 @@
|
|
|
1
|
+
import { isEmpty } from "..";
|
|
1
2
|
/**
|
|
2
|
-
* Upper case
|
|
3
|
+
* Upper case the first letter of a given text
|
|
3
4
|
* @param {String} text
|
|
4
|
-
* @returns {String}
|
|
5
|
+
* @returns {String} a capitalized text
|
|
5
6
|
*/
|
|
6
|
-
export function capitalize(text) {
|
|
7
|
+
export function capitalize(text = '') {
|
|
8
|
+
if (isEmpty(text) || typeof text !== 'string')
|
|
9
|
+
return text;
|
|
7
10
|
return text.toLowerCase().replace(/^\w/, c => c.toUpperCase());
|
|
8
11
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDateColumn } from ".";
|
|
2
|
+
import { COLUMN_PROPERTY_VALUE, isEmpty } from "..";
|
|
3
|
+
export function getPropertyLabel(column, property) {
|
|
4
|
+
var _a;
|
|
5
|
+
let propertyLabel;
|
|
6
|
+
const propertyValues = COLUMN_PROPERTY_VALUE[isDateColumn(column) ? 'DATE-complete' : column.type];
|
|
7
|
+
if (!isEmpty(propertyValues))
|
|
8
|
+
propertyLabel = (_a = propertyValues.find(pValue => pValue.value === property)) === null || _a === void 0 ? void 0 : _a.label;
|
|
9
|
+
return propertyLabel;
|
|
10
|
+
}
|
package/dist/qrvey/index.d.ts
CHANGED