siam-ui-utils 1.0.12 → 1.0.14
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/index.d.ts +12 -1
- package/package.json +1 -2
- package/dist_browser/CustomBootstrap.js +0 -23
- package/dist_browser/CustomBootstrap.jsx +0 -11
- package/dist_browser/CustomSelectInput.js +0 -23
- package/dist_browser/CustomSelectInput.jsx +0 -22
- package/dist_browser/IntlMessages.js +0 -20
- package/dist_browser/IntlMessages.jsx +0 -8
- package/dist_browser/constants/defaultValues.js +0 -9
- package/dist_browser/iconos/anular-ayuda-icon.js +0 -27
- package/dist_browser/iconos/anular-ayuda-icon.jsx +0 -41
- package/dist_browser/iconos/asesoria-burbuja-button.js +0 -11
- package/dist_browser/iconos/asesoria-burbuja-button.jsx +0 -41
- package/dist_browser/iconos/asesoria-burbuja-icon.js +0 -11
- package/dist_browser/iconos/asesoria-burbuja-icon.jsx +0 -41
- package/dist_browser/iconos/atencion-presencial-icon.js +0 -12
- package/dist_browser/iconos/atencion-presencial-icon.jsx +0 -52
- package/dist_browser/iconos/atencion-telefonica-icon.js +0 -12
- package/dist_browser/iconos/atencion-telefonica-icon.jsx +0 -28
- package/dist_browser/iconos/atencion-turno-telefonico-icon.js +0 -12
- package/dist_browser/iconos/atencion-turno-telefonico-icon.jsx +0 -31
- package/dist_browser/iconos/atencion-virtual-icon.js +0 -12
- package/dist_browser/iconos/atencion-virtual-icon.jsx +0 -26
- package/dist_browser/iconos/biblioteca-burbuja-button.js +0 -13
- package/dist_browser/iconos/biblioteca-burbuja-button.jsx +0 -26
- package/dist_browser/iconos/biblioteca-burbuja-icon.js +0 -11
- package/dist_browser/iconos/biblioteca-burbuja-icon.jsx +0 -28
- package/dist_browser/iconos/cancelar-turno-icon.js +0 -11
- package/dist_browser/iconos/cancelar-turno-icon.jsx +0 -21
- package/dist_browser/iconos/codigo-verificacion-icon.js +0 -12
- package/dist_browser/iconos/codigo-verificacion-icon.jsx +0 -25
- package/dist_browser/iconos/constants-svg.js +0 -21
- package/dist_browser/iconos/curso-autogestionado-color-icon.js +0 -12
- package/dist_browser/iconos/curso-autogestionado-color-icon.jsx +0 -117
- package/dist_browser/iconos/curso-autogestionado-icon.js +0 -12
- package/dist_browser/iconos/curso-autogestionado-icon.jsx +0 -34
- package/dist_browser/iconos/curso-burbuja-button.js +0 -15
- package/dist_browser/iconos/curso-burbuja-button.jsx +0 -20
- package/dist_browser/iconos/curso-burbuja-icon.js +0 -11
- package/dist_browser/iconos/curso-burbuja-icon.jsx +0 -34
- package/dist_browser/iconos/curso-presencial-color-icon.js +0 -12
- package/dist_browser/iconos/curso-presencial-color-icon.jsx +0 -135
- package/dist_browser/iconos/curso-presencial-icon.js +0 -12
- package/dist_browser/iconos/curso-presencial-icon.jsx +0 -48
- package/dist_browser/iconos/curso-virtual-color-icon.js +0 -12
- package/dist_browser/iconos/curso-virtual-color-icon.jsx +0 -57
- package/dist_browser/iconos/curso-virtual-icon.js +0 -12
- package/dist_browser/iconos/curso-virtual-icon.jsx +0 -26
- package/dist_browser/iconos/delegaciones-icon.js +0 -11
- package/dist_browser/iconos/delegaciones-icon.jsx +0 -44
- package/dist_browser/iconos/forgot-dni-icon.js +0 -12
- package/dist_browser/iconos/forgot-dni-icon.jsx +0 -22
- package/dist_browser/iconos/forgot-password-icon.js +0 -12
- package/dist_browser/iconos/forgot-password-icon.jsx +0 -23
- package/dist_browser/iconos/icon-button-svg.js +0 -28
- package/dist_browser/iconos/icon-button-svg.jsx +0 -29
- package/dist_browser/iconos/index.js +0 -57
- package/dist_browser/iconos/lapiz-act-contacto-perf-button.js +0 -14
- package/dist_browser/iconos/lapiz-act-contacto-perf-button.jsx +0 -24
- package/dist_browser/iconos/styled-icon.js +0 -24
- package/dist_browser/iconos/styled-icon.jsx +0 -12
- package/dist_browser/iconos/user/styled-icon.js +0 -25
- package/dist_browser/iconos/user/styled-icon.jsx +0 -13
- package/dist_browser/iconos/verificar-sin-verificar-icon.js +0 -14
- package/dist_browser/iconos/verificar-sin-verificar-icon.jsx +0 -18
- package/dist_browser/iconos/verificar-verificado-icon.js +0 -11
- package/dist_browser/iconos/verificar-verificado-icon.jsx +0 -15
- package/dist_browser/iconos/whatsapp-icon-button.js +0 -13
- package/dist_browser/iconos/whatsapp-icon-button.jsx +0 -23
- package/dist_browser/index.js +0 -20
- package/dist_browser/src/CustomBootstrap.tsx +0 -10
- package/dist_browser/src/CustomSelectInput.tsx +0 -12
- package/dist_browser/src/iconos/anular-ayuda-icon.tsx +0 -72
- package/dist_browser/src/iconos/asesoria-burbuja-button.tsx +0 -102
- package/dist_browser/src/iconos/asesoria-burbuja-icon.tsx +0 -102
- package/dist_browser/src/iconos/atencion-presencial-icon.tsx +0 -77
- package/dist_browser/src/iconos/atencion-telefonica-icon.tsx +0 -42
- package/dist_browser/src/iconos/atencion-turno-telefonico-icon.tsx +0 -51
- package/dist_browser/src/iconos/atencion-virtual-icon.tsx +0 -35
- package/dist_browser/src/iconos/biblioteca-burbuja-button.tsx +0 -57
- package/dist_browser/src/iconos/biblioteca-burbuja-icon.tsx +0 -65
- package/dist_browser/src/iconos/cancelar-turno-icon.tsx +0 -27
- package/dist_browser/src/iconos/codigo-verificacion-icon.tsx +0 -53
- package/dist_browser/src/iconos/constants-svg.ts +0 -659
- package/dist_browser/src/iconos/curso-autogestionado-color-icon.tsx +0 -202
- package/dist_browser/src/iconos/curso-autogestionado-icon.tsx +0 -48
- package/dist_browser/src/iconos/curso-burbuja-button.tsx +0 -40
- package/dist_browser/src/iconos/curso-burbuja-icon.tsx +0 -96
- package/dist_browser/src/iconos/curso-presencial-color-icon.tsx +0 -255
- package/dist_browser/src/iconos/curso-presencial-icon.tsx +0 -70
- package/dist_browser/src/iconos/curso-virtual-color-icon.tsx +0 -108
- package/dist_browser/src/iconos/curso-virtual-icon.tsx +0 -38
- package/dist_browser/src/iconos/delegaciones-icon.tsx +0 -65
- package/dist_browser/src/iconos/forgot-dni-icon.tsx +0 -41
- package/dist_browser/src/iconos/forgot-password-icon.tsx +0 -45
- package/dist_browser/src/iconos/icon-button-svg.tsx +0 -52
- package/dist_browser/src/iconos/index.ts +0 -42
- package/dist_browser/src/iconos/lapiz-act-contacto-perf-button.tsx +0 -43
- package/dist_browser/src/iconos/styled-icon.tsx +0 -25
- package/dist_browser/src/iconos/user/styled-icon.tsx +0 -24
- package/dist_browser/src/iconos/verificar-sin-verificar-icon.tsx +0 -37
- package/dist_browser/src/iconos/verificar-verificado-icon.tsx +0 -29
- package/dist_browser/src/iconos/whatsapp-icon-button.tsx +0 -40
- package/dist_browser/src/index.ts +0 -10
- package/dist_browser/src/utils-arrays-reducers.ts +0 -142
- package/dist_browser/src/utils-currency.ts +0 -39
- package/dist_browser/src/utils-number.ts +0 -39
- package/dist_browser/src/utils-temp.ts +0 -52
- package/src/index.ts +0 -10
- package/src/utils-arrays-reducers.ts +0 -142
- package/src/utils-currency.ts +0 -39
- package/src/utils-number.ts +0 -39
- package/src/utils-temp.ts +0 -52
- package/test/utils-dates.test.ts +0 -139
- package/test/utils-percent.test.ts +0 -50
- package/test/utils.test.ts +0 -40
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { withTheme } from 'styled-components';
|
|
3
|
-
import { Icon } from './styled-icon';
|
|
4
|
-
|
|
5
|
-
const WhatsappIconButton = (props: any) => {
|
|
6
|
-
const { phone = '', width = '', height = '', sublabel = '' } = props || {};
|
|
7
|
-
return (
|
|
8
|
-
<Icon
|
|
9
|
-
width={width}
|
|
10
|
-
height={height}
|
|
11
|
-
display={sublabel !== '' ? 'block' : 'none'}
|
|
12
|
-
onClick={() =>
|
|
13
|
-
window.open(
|
|
14
|
-
`https://api.whatsapp.com/send/?phone=${phone}&text=&app_absent=0`,
|
|
15
|
-
'_blank'
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
>
|
|
19
|
-
<svg
|
|
20
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
21
|
-
version="1.1"
|
|
22
|
-
viewBox="0 0 23.687 23.688"
|
|
23
|
-
>
|
|
24
|
-
<path
|
|
25
|
-
fill="#99CC33"
|
|
26
|
-
d="M12.906,3.301c-5.344,0-9.687,4.348-9.687,9.69c0,1.778,0.482,3.509,1.406,5.022l-1.387,4.159
|
|
27
|
-
C3.19,22.311,3.227,22.46,3.33,22.566c0.076,0.073,0.175,0.112,0.275,0.112c0.045,0,0.082-0.003,0.126-0.019l4.154-1.385
|
|
28
|
-
c1.516,0.918,3.246,1.403,5.021,1.403c5.343,0,9.688-4.346,9.688-9.688S18.249,3.301,12.906,3.301z M19.107,16.912
|
|
29
|
-
c0,0.338-0.14,0.671-0.379,0.91l-1.009,0.996c-0.24,0.241-0.565,0.373-0.899,0.373h-0.05c-5.414-0.233-9.833-4.65-10.065-10.061
|
|
30
|
-
C6.691,8.778,6.828,8.428,7.078,8.176l0.995-1.008c0.241-0.238,0.574-0.38,0.915-0.38h0.373c0.531,0,1.015,0.333,1.201,0.834
|
|
31
|
-
l0.883,2.345c0.171,0.457,0.066,0.98-0.271,1.337l-0.364,0.383c-0.168,0.176-0.185,0.444-0.05,0.641
|
|
32
|
-
c0.448,0.65,1.411,1.88,2.814,2.824c0.192,0.129,0.457,0.105,0.628-0.058l0.395-0.372c0.353-0.336,0.876-0.44,1.333-0.271
|
|
33
|
-
l2.345,0.884c0.498,0.188,0.833,0.669,0.833,1.201V16.912z"
|
|
34
|
-
/>
|
|
35
|
-
</svg>
|
|
36
|
-
</Icon>
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
WhatsappIconButton.defaultProps = { theme: {} };
|
|
40
|
-
export default withTheme(WhatsappIconButton);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./auth-header";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export * from "./utils-arrays-reducers";
|
|
4
|
-
export * from "./utils-boolean";
|
|
5
|
-
export * from "./utils-currency";
|
|
6
|
-
export * from "./utils-dates";
|
|
7
|
-
export * from "./utils-error";
|
|
8
|
-
export * from "./utils-number";
|
|
9
|
-
export * from "./utils-percent";
|
|
10
|
-
export * from "./utils-temp";
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { fieldToDate } from './utils-dates.js';
|
|
2
|
-
import { fieldTypes} from './commons/defaultValues.js';
|
|
3
|
-
|
|
4
|
-
export const addSelectedFieldToList = (list: any[], selected = false) =>
|
|
5
|
-
list.map((item: any) => {
|
|
6
|
-
return { ...item, selected };
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export const updateSelectedItemInList = (list: any[], keyField: string | number, idItem: any) =>
|
|
10
|
-
list.map((item: { [x: string]: any; selected: any; }) => {
|
|
11
|
-
return item[keyField] === idItem
|
|
12
|
-
? { ...item, selected: !item.selected }
|
|
13
|
-
: { ...item };
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const updateAllSelectedItemInList = (list: any[], newValue: any) =>
|
|
17
|
-
list.map((item: any) => {
|
|
18
|
-
return { ...item, selected: newValue };
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const toogleAllSelectedItemInList = (list: any[]) =>
|
|
22
|
-
list.map((item: { selected: any; }) => {
|
|
23
|
-
return { ...item, selected: !item.selected };
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const countItemsSelectedInList = (list: any[]) => {
|
|
27
|
-
return (list.filter((i: { selected: any; }) => i.selected) || []).length;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const castField = (field: string, type: any) => {
|
|
31
|
-
const { date, string, number } = fieldTypes;
|
|
32
|
-
switch (type) {
|
|
33
|
-
case number:
|
|
34
|
-
return Number(field);
|
|
35
|
-
case date:
|
|
36
|
-
return fieldToDate(field);
|
|
37
|
-
case string:
|
|
38
|
-
return field;
|
|
39
|
-
default:
|
|
40
|
-
return field;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const sortList = (list: { id: any; name: any; tag: any; count: any; }[], ...properties: { value: string; field: string; type: string; }[]) => {
|
|
45
|
-
let tmpList = list;
|
|
46
|
-
properties.forEach((p) => {
|
|
47
|
-
const { field, type } = p;
|
|
48
|
-
tmpList = tmpList.sort((a: { [x: string]: any; }, b: { [x: string]: any; }) =>
|
|
49
|
-
castField(a[field], type) < castField(b[field], type) ? -1 : 1
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
return tmpList;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const miGroupBy = (objectArray: any[], ...properties: any[]) => {
|
|
56
|
-
return [
|
|
57
|
-
...Object.values(
|
|
58
|
-
objectArray.reduce((accumulator: { [x: string]: any[]; }, object: { [x: string]: any; }) => {
|
|
59
|
-
const key = JSON.stringify(properties.map((x) => object[x] || null));
|
|
60
|
-
|
|
61
|
-
if (!accumulator[key]) {
|
|
62
|
-
accumulator[key] = [];
|
|
63
|
-
}
|
|
64
|
-
accumulator[key].push(object);
|
|
65
|
-
return accumulator;
|
|
66
|
-
}, {})
|
|
67
|
-
),
|
|
68
|
-
];
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const getFilterItems = (dataArray: any, ...properties: (string | number)[]) => {
|
|
72
|
-
const dataGroupBy = miGroupBy(dataArray, ...properties);
|
|
73
|
-
const sumGroupBy = dataGroupBy.map((group) => ({
|
|
74
|
-
id: (group as any)[0][properties[0]],
|
|
75
|
-
name: (group as any)[0][properties[1]],
|
|
76
|
-
tag: (group as any)[0][properties[2]],
|
|
77
|
-
count: (group as any).length,
|
|
78
|
-
}));
|
|
79
|
-
return sortList(sumGroupBy, { value: 'name', field: 'name', type: 'string' });
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const filterListByItem = (list: any[], itemName: string | number, filterValue: any) => {
|
|
83
|
-
return list.filter((item: { [x: string]: any; }) => item[itemName] === filterValue);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const applyFilterToList = (list: any, filtersToApply: any) => {
|
|
87
|
-
let listFiltered = list;
|
|
88
|
-
for (const itemToFilter of filtersToApply) {
|
|
89
|
-
const { fieldName, fieldValue } = itemToFilter;
|
|
90
|
-
if (fieldValue) {
|
|
91
|
-
listFiltered = filterListByItem(listFiltered, fieldName, fieldValue);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return listFiltered;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const sumField = (data: any[], field: string | number) => {
|
|
98
|
-
return data.reduce(
|
|
99
|
-
(prevValue: number, currentValue: { [x: string]: any; }) =>
|
|
100
|
-
prevValue + parseFloat(currentValue[field] || 0),
|
|
101
|
-
0
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const removeDuplicates = (data: any[], field: string | number) => {
|
|
106
|
-
const hash = {};
|
|
107
|
-
return data.filter((o: { [x: string]: string | number; }) => {
|
|
108
|
-
return (hash as any)[o[field]] ? false : ((hash as any)[o[field]] = true);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const convertArrayToString = (dataArray: any[], separator = '|') => {
|
|
113
|
-
const cadena = dataArray.join(separator);
|
|
114
|
-
return cadena;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const convertStringToArray = (string: string, separator = '|') => {
|
|
118
|
-
return string ? string.replace(/\s+/g, '').split(separator) : [];
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const convertFieldObjStringToArray = (data: any[], field: string | number, separator: string | undefined) => {
|
|
122
|
-
const dataArray = data
|
|
123
|
-
? data.map((item: { [x: string]: any; }) => {
|
|
124
|
-
return {
|
|
125
|
-
...item,
|
|
126
|
-
[field]: item[field]
|
|
127
|
-
? convertStringToArray(item[field], separator)
|
|
128
|
-
: [],
|
|
129
|
-
};
|
|
130
|
-
})
|
|
131
|
-
: [];
|
|
132
|
-
return dataArray;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const updateItemField = (data: any[], id: string | number, idValue: any, fieldName: any, fieldValue: any) => {
|
|
136
|
-
const dataUpdate = data.map((item: { [x: string]: any; }) => {
|
|
137
|
-
return item[id] === idValue
|
|
138
|
-
? { ...item, [fieldName]: fieldValue }
|
|
139
|
-
: { ...item };
|
|
140
|
-
});
|
|
141
|
-
return dataUpdate;
|
|
142
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { numberLocalConf } from "./commons/defaultValues";
|
|
2
|
-
|
|
3
|
-
const { locales, style, currency } = numberLocalConf;
|
|
4
|
-
|
|
5
|
-
const formatter = new Intl.NumberFormat(locales, {
|
|
6
|
-
style,
|
|
7
|
-
currency,
|
|
8
|
-
} as any);
|
|
9
|
-
|
|
10
|
-
export const fieldToCurrency = (field: number): string => {
|
|
11
|
-
// ingresa string '99999.99' devuelve string $99.999,99
|
|
12
|
-
return formatter.format(field);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const fieldToNumber = (field: string): number => {
|
|
16
|
-
// ingresa string '99999.99' devuelve flotante '99999.99'
|
|
17
|
-
return parseFloat(field);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const currencyToNumber = (
|
|
21
|
-
currencyValue: string,
|
|
22
|
-
returnZero?: boolean
|
|
23
|
-
): number => {
|
|
24
|
-
// ingresa $99.999,99 devuelve flotante '99999.99'
|
|
25
|
-
if (returnZero && !currencyValue) {
|
|
26
|
-
return 0;
|
|
27
|
-
}
|
|
28
|
-
let stringValue = currencyValue.toString().replace("$", "");
|
|
29
|
-
stringValue = stringValue.replace(/[.]/g, "");
|
|
30
|
-
stringValue = stringValue.replace(",", ".");
|
|
31
|
-
return parseFloat(stringValue);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Esta funcion debe devolver un STRING !!!! revisar compatibilidad...
|
|
35
|
-
export const currencyToPersistence = (currencyValue: string): string => {
|
|
36
|
-
// ingresa $99.999,99 devuelve string '99999.99'
|
|
37
|
-
const stringValue = currencyToNumber(currencyValue);
|
|
38
|
-
return stringValue.toString();
|
|
39
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { numberLocalConf } from "./commons/defaultValues";
|
|
2
|
-
|
|
3
|
-
const { locales, minimumFractionDigits, maximumFractionDigits, currency } =
|
|
4
|
-
numberLocalConf;
|
|
5
|
-
|
|
6
|
-
export const numberToDisplay = (
|
|
7
|
-
number: number,
|
|
8
|
-
fractionDigits: number = 0
|
|
9
|
-
): string => {
|
|
10
|
-
return number.toLocaleString(locales, {
|
|
11
|
-
minimumFractionDigits: fractionDigits,
|
|
12
|
-
maximumFractionDigits: fractionDigits,
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const numberToDisplayCurrency = (number: number): string => {
|
|
17
|
-
if (number === null || number === undefined) {
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
const res = number.toLocaleString(locales, {
|
|
21
|
-
minimumFractionDigits,
|
|
22
|
-
maximumFractionDigits,
|
|
23
|
-
style: "currency",
|
|
24
|
-
currency,
|
|
25
|
-
});
|
|
26
|
-
return res;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const numberToPersistence = (number: string): string | null => {
|
|
30
|
-
return number === "" ? null : number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const numberToStringifyPersistence = (number: number): string => {
|
|
34
|
-
return String(number);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const comprobanteToPersistence = (comprobanteStr: string): string => {
|
|
38
|
-
return comprobanteStr.replace(/[-]/g, "");
|
|
39
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defaultDirection } from './commons/defaultValues.js';
|
|
2
|
-
|
|
3
|
-
export const getDirection = () => {
|
|
4
|
-
let direction = defaultDirection;
|
|
5
|
-
if (localStorage.getItem('direction')) {
|
|
6
|
-
const localValue = localStorage.getItem('direction');
|
|
7
|
-
if (localValue === 'rtl' || localValue === 'ltr') {
|
|
8
|
-
direction = localValue;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
direction,
|
|
13
|
-
isRtl: direction === 'rtl',
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const setDirection = (localValue: string) => {
|
|
18
|
-
let direction = 'ltr';
|
|
19
|
-
if (localValue === 'rtl' || localValue === 'ltr') {
|
|
20
|
-
direction = localValue;
|
|
21
|
-
}
|
|
22
|
-
localStorage.setItem('direction', direction);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getStartPath = () => {
|
|
26
|
-
const isReactProxyEnabled =
|
|
27
|
-
(localStorage.getItem('reactProxy') || 'N') === 'S';
|
|
28
|
-
const startPath = isReactProxyEnabled ? '/app' : '';
|
|
29
|
-
return startPath;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const toUpper = (payload: { [x: string]: any; }) => {
|
|
33
|
-
for (const prop in payload) {
|
|
34
|
-
if (typeof payload[prop] === 'string') {
|
|
35
|
-
payload[prop] = payload[prop].toUpperCase();
|
|
36
|
-
}
|
|
37
|
-
if (typeof payload[prop] === 'object') {
|
|
38
|
-
toUpper(payload[prop]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return payload;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const checkRole = (roles = [], ...properties: any[]) => {
|
|
45
|
-
let result = false;
|
|
46
|
-
properties.forEach((serchRole) => {
|
|
47
|
-
if ((roles as any).includes(serchRole)) {
|
|
48
|
-
result = true;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return result;
|
|
52
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./auth-header";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export * from "./utils-arrays-reducers";
|
|
4
|
-
export * from "./utils-boolean";
|
|
5
|
-
export * from "./utils-currency";
|
|
6
|
-
export * from "./utils-dates";
|
|
7
|
-
export * from "./utils-error";
|
|
8
|
-
export * from "./utils-number";
|
|
9
|
-
export * from "./utils-percent";
|
|
10
|
-
export * from "./utils-temp";
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { fieldToDate } from './utils-dates.js';
|
|
2
|
-
import { fieldTypes} from './commons/defaultValues.js';
|
|
3
|
-
|
|
4
|
-
export const addSelectedFieldToList = (list: any[], selected = false) =>
|
|
5
|
-
list.map((item: any) => {
|
|
6
|
-
return { ...item, selected };
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export const updateSelectedItemInList = (list: any[], keyField: string | number, idItem: any) =>
|
|
10
|
-
list.map((item: { [x: string]: any; selected: any; }) => {
|
|
11
|
-
return item[keyField] === idItem
|
|
12
|
-
? { ...item, selected: !item.selected }
|
|
13
|
-
: { ...item };
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const updateAllSelectedItemInList = (list: any[], newValue: any) =>
|
|
17
|
-
list.map((item: any) => {
|
|
18
|
-
return { ...item, selected: newValue };
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const toogleAllSelectedItemInList = (list: any[]) =>
|
|
22
|
-
list.map((item: { selected: any; }) => {
|
|
23
|
-
return { ...item, selected: !item.selected };
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const countItemsSelectedInList = (list: any[]) => {
|
|
27
|
-
return (list.filter((i: { selected: any; }) => i.selected) || []).length;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const castField = (field: string, type: any) => {
|
|
31
|
-
const { date, string, number } = fieldTypes;
|
|
32
|
-
switch (type) {
|
|
33
|
-
case number:
|
|
34
|
-
return Number(field);
|
|
35
|
-
case date:
|
|
36
|
-
return fieldToDate(field);
|
|
37
|
-
case string:
|
|
38
|
-
return field;
|
|
39
|
-
default:
|
|
40
|
-
return field;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const sortList = (list: { id: any; name: any; tag: any; count: any; }[], ...properties: { value: string; field: string; type: string; }[]) => {
|
|
45
|
-
let tmpList = list;
|
|
46
|
-
properties.forEach((p) => {
|
|
47
|
-
const { field, type } = p;
|
|
48
|
-
tmpList = tmpList.sort((a: { [x: string]: any; }, b: { [x: string]: any; }) =>
|
|
49
|
-
castField(a[field], type) < castField(b[field], type) ? -1 : 1
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
return tmpList;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const miGroupBy = (objectArray: any[], ...properties: any[]) => {
|
|
56
|
-
return [
|
|
57
|
-
...Object.values(
|
|
58
|
-
objectArray.reduce((accumulator: { [x: string]: any[]; }, object: { [x: string]: any; }) => {
|
|
59
|
-
const key = JSON.stringify(properties.map((x) => object[x] || null));
|
|
60
|
-
|
|
61
|
-
if (!accumulator[key]) {
|
|
62
|
-
accumulator[key] = [];
|
|
63
|
-
}
|
|
64
|
-
accumulator[key].push(object);
|
|
65
|
-
return accumulator;
|
|
66
|
-
}, {})
|
|
67
|
-
),
|
|
68
|
-
];
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const getFilterItems = (dataArray: any, ...properties: (string | number)[]) => {
|
|
72
|
-
const dataGroupBy = miGroupBy(dataArray, ...properties);
|
|
73
|
-
const sumGroupBy = dataGroupBy.map((group) => ({
|
|
74
|
-
id: (group as any)[0][properties[0]],
|
|
75
|
-
name: (group as any)[0][properties[1]],
|
|
76
|
-
tag: (group as any)[0][properties[2]],
|
|
77
|
-
count: (group as any).length,
|
|
78
|
-
}));
|
|
79
|
-
return sortList(sumGroupBy, { value: 'name', field: 'name', type: 'string' });
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const filterListByItem = (list: any[], itemName: string | number, filterValue: any) => {
|
|
83
|
-
return list.filter((item: { [x: string]: any; }) => item[itemName] === filterValue);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const applyFilterToList = (list: any, filtersToApply: any) => {
|
|
87
|
-
let listFiltered = list;
|
|
88
|
-
for (const itemToFilter of filtersToApply) {
|
|
89
|
-
const { fieldName, fieldValue } = itemToFilter;
|
|
90
|
-
if (fieldValue) {
|
|
91
|
-
listFiltered = filterListByItem(listFiltered, fieldName, fieldValue);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return listFiltered;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const sumField = (data: any[], field: string | number) => {
|
|
98
|
-
return data.reduce(
|
|
99
|
-
(prevValue: number, currentValue: { [x: string]: any; }) =>
|
|
100
|
-
prevValue + parseFloat(currentValue[field] || 0),
|
|
101
|
-
0
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const removeDuplicates = (data: any[], field: string | number) => {
|
|
106
|
-
const hash = {};
|
|
107
|
-
return data.filter((o: { [x: string]: string | number; }) => {
|
|
108
|
-
return (hash as any)[o[field]] ? false : ((hash as any)[o[field]] = true);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const convertArrayToString = (dataArray: any[], separator = '|') => {
|
|
113
|
-
const cadena = dataArray.join(separator);
|
|
114
|
-
return cadena;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const convertStringToArray = (string: string, separator = '|') => {
|
|
118
|
-
return string ? string.replace(/\s+/g, '').split(separator) : [];
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const convertFieldObjStringToArray = (data: any[], field: string | number, separator: string | undefined) => {
|
|
122
|
-
const dataArray = data
|
|
123
|
-
? data.map((item: { [x: string]: any; }) => {
|
|
124
|
-
return {
|
|
125
|
-
...item,
|
|
126
|
-
[field]: item[field]
|
|
127
|
-
? convertStringToArray(item[field], separator)
|
|
128
|
-
: [],
|
|
129
|
-
};
|
|
130
|
-
})
|
|
131
|
-
: [];
|
|
132
|
-
return dataArray;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const updateItemField = (data: any[], id: string | number, idValue: any, fieldName: any, fieldValue: any) => {
|
|
136
|
-
const dataUpdate = data.map((item: { [x: string]: any; }) => {
|
|
137
|
-
return item[id] === idValue
|
|
138
|
-
? { ...item, [fieldName]: fieldValue }
|
|
139
|
-
: { ...item };
|
|
140
|
-
});
|
|
141
|
-
return dataUpdate;
|
|
142
|
-
};
|
package/src/utils-currency.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { numberLocalConf } from "./commons/defaultValues";
|
|
2
|
-
|
|
3
|
-
const { locales, style, currency } = numberLocalConf;
|
|
4
|
-
|
|
5
|
-
const formatter = new Intl.NumberFormat(locales, {
|
|
6
|
-
style,
|
|
7
|
-
currency,
|
|
8
|
-
} as any);
|
|
9
|
-
|
|
10
|
-
export const fieldToCurrency = (field: number): string => {
|
|
11
|
-
// ingresa string '99999.99' devuelve string $99.999,99
|
|
12
|
-
return formatter.format(field);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const fieldToNumber = (field: string): number => {
|
|
16
|
-
// ingresa string '99999.99' devuelve flotante '99999.99'
|
|
17
|
-
return parseFloat(field);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const currencyToNumber = (
|
|
21
|
-
currencyValue: string,
|
|
22
|
-
returnZero?: boolean
|
|
23
|
-
): number => {
|
|
24
|
-
// ingresa $99.999,99 devuelve flotante '99999.99'
|
|
25
|
-
if (returnZero && !currencyValue) {
|
|
26
|
-
return 0;
|
|
27
|
-
}
|
|
28
|
-
let stringValue = currencyValue.toString().replace("$", "");
|
|
29
|
-
stringValue = stringValue.replace(/[.]/g, "");
|
|
30
|
-
stringValue = stringValue.replace(",", ".");
|
|
31
|
-
return parseFloat(stringValue);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Esta funcion debe devolver un STRING !!!! revisar compatibilidad...
|
|
35
|
-
export const currencyToPersistence = (currencyValue: string): string => {
|
|
36
|
-
// ingresa $99.999,99 devuelve string '99999.99'
|
|
37
|
-
const stringValue = currencyToNumber(currencyValue);
|
|
38
|
-
return stringValue.toString();
|
|
39
|
-
};
|
package/src/utils-number.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { numberLocalConf } from "./commons/defaultValues";
|
|
2
|
-
|
|
3
|
-
const { locales, minimumFractionDigits, maximumFractionDigits, currency } =
|
|
4
|
-
numberLocalConf;
|
|
5
|
-
|
|
6
|
-
export const numberToDisplay = (
|
|
7
|
-
number: number,
|
|
8
|
-
fractionDigits: number = 0
|
|
9
|
-
): string => {
|
|
10
|
-
return number.toLocaleString(locales, {
|
|
11
|
-
minimumFractionDigits: fractionDigits,
|
|
12
|
-
maximumFractionDigits: fractionDigits,
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const numberToDisplayCurrency = (number: number): string => {
|
|
17
|
-
if (number === null || number === undefined) {
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
const res = number.toLocaleString(locales, {
|
|
21
|
-
minimumFractionDigits,
|
|
22
|
-
maximumFractionDigits,
|
|
23
|
-
style: "currency",
|
|
24
|
-
currency,
|
|
25
|
-
});
|
|
26
|
-
return res;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const numberToPersistence = (number: string): string | null => {
|
|
30
|
-
return number === "" ? null : number;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const numberToStringifyPersistence = (number: number): string => {
|
|
34
|
-
return String(number);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const comprobanteToPersistence = (comprobanteStr: string): string => {
|
|
38
|
-
return comprobanteStr.replace(/[-]/g, "");
|
|
39
|
-
};
|
package/src/utils-temp.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defaultDirection } from './commons/defaultValues.js';
|
|
2
|
-
|
|
3
|
-
export const getDirection = () => {
|
|
4
|
-
let direction = defaultDirection;
|
|
5
|
-
if (localStorage.getItem('direction')) {
|
|
6
|
-
const localValue = localStorage.getItem('direction');
|
|
7
|
-
if (localValue === 'rtl' || localValue === 'ltr') {
|
|
8
|
-
direction = localValue;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
direction,
|
|
13
|
-
isRtl: direction === 'rtl',
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const setDirection = (localValue: string) => {
|
|
18
|
-
let direction = 'ltr';
|
|
19
|
-
if (localValue === 'rtl' || localValue === 'ltr') {
|
|
20
|
-
direction = localValue;
|
|
21
|
-
}
|
|
22
|
-
localStorage.setItem('direction', direction);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getStartPath = () => {
|
|
26
|
-
const isReactProxyEnabled =
|
|
27
|
-
(localStorage.getItem('reactProxy') || 'N') === 'S';
|
|
28
|
-
const startPath = isReactProxyEnabled ? '/app' : '';
|
|
29
|
-
return startPath;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const toUpper = (payload: { [x: string]: any; }) => {
|
|
33
|
-
for (const prop in payload) {
|
|
34
|
-
if (typeof payload[prop] === 'string') {
|
|
35
|
-
payload[prop] = payload[prop].toUpperCase();
|
|
36
|
-
}
|
|
37
|
-
if (typeof payload[prop] === 'object') {
|
|
38
|
-
toUpper(payload[prop]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return payload;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const checkRole = (roles = [], ...properties: any[]) => {
|
|
45
|
-
let result = false;
|
|
46
|
-
properties.forEach((serchRole) => {
|
|
47
|
-
if ((roles as any).includes(serchRole)) {
|
|
48
|
-
result = true;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return result;
|
|
52
|
-
};
|