siam-ui-utils 1.0.12 → 1.0.13

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 CHANGED
@@ -1,4 +1,12 @@
1
1
  declare module "siam-ui-utils" {
2
+ //CUSTOMBOOSTRAP
3
+ export function Colxx(props);
4
+ export function Separator(props);
5
+
6
+ //CUSTOMSELECTINPUT
7
+ export function CustomSelectInput(props);
8
+
9
+ //ICONOS
2
10
  export function AnularAyudaIcon (props);
3
11
  export function AsesoriaBurbujaButton(props);
4
12
  export function AsesoriaBurbujaIcon (props);
@@ -42,8 +50,11 @@ declare module "siam-ui-utils" {
42
50
  export function IconButtonSvg(props);
43
51
  export function LapizActContactoPerfilButton(props);
44
52
  export function Icon(props);
45
- export function UserIcon(props);
46
53
  export function VerificarSinVerificarIcon(props);
47
54
  export function VerificarVerificadoIcon(props);
48
55
  export function WhatsappIconButton(props);
56
+
57
+ //ICONOS/USER
58
+ export function UserIcon(props);
59
+
49
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siam-ui-utils",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "keywords": [
5
5
  "ampf-react",
6
6
  "ampf-utils",
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
- };
@@ -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
- };
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
- };
@@ -1,139 +0,0 @@
1
- import { describe, test, assert } from "vitest";
2
- import {
3
- dateToDisplay,
4
- dateToDisplayDiaMes,
5
- dateToDisplayHoraMinuto,
6
- dateToDisplayPeriodo,
7
- dateToPersistence,
8
- diffDateDays,
9
- fieldPeriodoToDate,
10
- fieldPeriodoToDisplay,
11
- fieldToDate,
12
- fieldToDisplay,
13
- fieldToPersistence,
14
- periodToPersistence,
15
- } from "../src";
16
-
17
- let dateResult: Date | string | undefined;
18
- const STRING_FULL_DATE_TO_TEST = "01/10/2010 12:10:35";
19
- const STRING_FULL_DATE_SLASH_TO_TEST = "01-10-2010 12:10:35";
20
- const STRING_SHORT_DATE_TO_TEST = "01/10/2010";
21
-
22
- const STRING_1ST_SHORT_DATE_TO_TEST = "10/01/2010";
23
- const STRING_2ND_SHORT_DATE_TO_TEST = "10/05/2010";
24
-
25
- const STRING_INVALID_DATE_TO_TEST = "01/15/2010";
26
- const STRING_SHORT_RESULT = "10-01-2010";
27
- const STRING_FULL_RESULT =
28
- "Fri Oct 01 2010 12:10:35 GMT-0300 (hora estándar de Argentina)";
29
- const INVALD_DATE_MESSAGE = "Invalid Date";
30
-
31
- const PERIOD_TO_PERSISTENCE_RESULT = "201001";
32
- const STRING_SHORT_PERIOD_MM_YYYY = "01/2010";
33
- const STRING_SHORT_PERIOD_DD_MM = "01/10";
34
- const STRING_SHORT_RESULT_TO_PERSISTENCE = "01-10-2010";
35
- const STRING_RESULT_HH_MM = "12:10";
36
- const PERIOD_TO_DISPLAY_RESULT_MM_YYYY = "01/2010";
37
-
38
- describe("Dates test suite", () => {
39
- ////// fieldToDate ///////
40
- describe("fieldToDate=> sub-test suite", () => {
41
- test(`Recibiendo: ${STRING_FULL_DATE_TO_TEST} debe devolver un campo tipo Date: '${STRING_FULL_RESULT}'`, () => {
42
- dateResult = fieldToDate(STRING_FULL_DATE_TO_TEST);
43
- assert.equal(
44
- dateResult?.toString() === STRING_FULL_RESULT.toString(),
45
- true
46
- );
47
- });
48
-
49
- test.skip(`Recibiendo string vacío debe devolver null`, () => {
50
- dateResult = fieldToDate("");
51
- assert.equal(dateResult === null, true);
52
- });
53
-
54
- test(`Recibiendo ${STRING_INVALID_DATE_TO_TEST} debe devolver ${INVALD_DATE_MESSAGE}`, () => {
55
- dateResult = fieldToDate(STRING_INVALID_DATE_TO_TEST);
56
- assert.equal(dateResult?.toString(), INVALD_DATE_MESSAGE);
57
- });
58
- });
59
-
60
- ////// dateToPersistence ///////
61
-
62
- describe("dateToPersistence=> sub-test suite", () => {
63
- test(`Recibiendo: ${STRING_SHORT_DATE_TO_TEST} debe devolver: '${STRING_SHORT_RESULT}'`, () => {
64
- dateResult = dateToPersistence(new Date(STRING_SHORT_DATE_TO_TEST));
65
- assert.equal(dateResult === STRING_SHORT_RESULT, true);
66
- });
67
-
68
- test(`Recibiendo: ${STRING_FULL_DATE_TO_TEST} debe devolver: '${STRING_SHORT_RESULT}'`, () => {
69
- dateResult = dateToPersistence(new Date(STRING_FULL_DATE_TO_TEST));
70
- assert.equal(dateResult === STRING_SHORT_RESULT, true);
71
- });
72
- });
73
-
74
- ////// periodToPersistence ///////
75
-
76
- test(`Recibiendo: ${STRING_SHORT_DATE_TO_TEST} debe devolver: '${PERIOD_TO_PERSISTENCE_RESULT}'`, () => {
77
- dateResult = periodToPersistence(new Date(STRING_SHORT_DATE_TO_TEST));
78
- assert.equal(dateResult === PERIOD_TO_PERSISTENCE_RESULT, true);
79
- });
80
-
81
- ////// fieldToPersistence ///////
82
-
83
- test(`Recibiendo: ${STRING_SHORT_DATE_TO_TEST} debe devolver: '${STRING_SHORT_RESULT_TO_PERSISTENCE}'`, () => {
84
- dateResult = fieldToPersistence(STRING_SHORT_DATE_TO_TEST);
85
- assert.equal(dateResult === STRING_SHORT_RESULT_TO_PERSISTENCE, true);
86
- });
87
-
88
- ////// dateToDisplay ///////
89
-
90
- test(`Recibiendo: ${new Date(
91
- STRING_SHORT_RESULT
92
- )} debe devolver: '${STRING_SHORT_DATE_TO_TEST}'`, () => {
93
- dateResult = dateToDisplay(new Date(STRING_SHORT_RESULT));
94
- assert.equal(dateResult === STRING_SHORT_DATE_TO_TEST, true);
95
- });
96
-
97
- ////// fieldToDisplay ///////
98
- test(`Recibiendo: ${STRING_SHORT_DATE_TO_TEST} debe devolver: '${STRING_SHORT_RESULT_TO_PERSISTENCE}'`, () => {
99
- dateResult = fieldToDisplay(STRING_SHORT_DATE_TO_TEST, "DD-MM-YYYY");
100
- assert.equal(dateResult === STRING_SHORT_RESULT_TO_PERSISTENCE, true);
101
- });
102
-
103
- ////// dateToDisplayPeriodo ///////
104
- test(`Recibiendo: ${new Date(
105
- STRING_SHORT_DATE_TO_TEST
106
- )} debe devolver: '${STRING_SHORT_PERIOD_MM_YYYY}'`, () => {
107
- dateResult = dateToDisplayPeriodo(
108
- new Date(STRING_SHORT_RESULT_TO_PERSISTENCE)
109
- );
110
- assert.equal(dateResult === STRING_SHORT_PERIOD_MM_YYYY, true);
111
- });
112
-
113
- ////// dateToDisplayDiaMes ///////
114
- test(`Recibiendo: ${STRING_SHORT_DATE_TO_TEST} debe devolver: '${STRING_SHORT_PERIOD_DD_MM}'`, () => {
115
- dateResult = dateToDisplayDiaMes(STRING_SHORT_DATE_TO_TEST);
116
- assert.equal(dateResult === STRING_SHORT_PERIOD_DD_MM, true);
117
- });
118
-
119
- ////// dateToDisplayHoraMinuto ///////
120
- test(`Recibiendo: ${STRING_FULL_DATE_SLASH_TO_TEST} debe devolver: '${STRING_RESULT_HH_MM}'`, () => {
121
- dateResult = dateToDisplayHoraMinuto(STRING_FULL_DATE_SLASH_TO_TEST);
122
- assert.equal(dateResult === STRING_RESULT_HH_MM, true);
123
- });
124
-
125
- ////// fieldPeriodoToDisplay ///////
126
- test(`Recibiendo: ${PERIOD_TO_PERSISTENCE_RESULT} debe devolver: '${PERIOD_TO_DISPLAY_RESULT_MM_YYYY}'`, () => {
127
- dateResult = fieldPeriodoToDisplay(PERIOD_TO_PERSISTENCE_RESULT);
128
- assert.equal(dateResult === PERIOD_TO_DISPLAY_RESULT_MM_YYYY, true);
129
- });
130
-
131
- ////// diffDateDays ///////
132
- test.skip(`Recibiendo: ${STRING_1ST_SHORT_DATE_TO_TEST} y ${STRING_2ND_SHORT_DATE_TO_TEST} debe devolver: 4`, () => {
133
- const difDays = diffDateDays(
134
- STRING_1ST_SHORT_DATE_TO_TEST,
135
- STRING_2ND_SHORT_DATE_TO_TEST
136
- );
137
- assert.equal(difDays === 4, true);
138
- });
139
- });
@@ -1,50 +0,0 @@
1
- import {
2
- comprobanteToPersistence,
3
- insertSimbol,
4
- numberToDisplay,
5
- numberToDisplayCurrency,
6
- numberToPersistence,
7
- numberToStringifyPersistence,
8
- persistenceToDisplayPercent,
9
- } from "../src";
10
- import { describe, test, assert } from "vitest";
11
-
12
- let stringResult: string;
13
-
14
- const SYMBOL = "%";
15
- const POSITION = "f";
16
- const FIELD_TO_TEST = "123,456";
17
-
18
- describe("Percent test suite", () => {
19
- describe("insertSimbol=> sub-test suite", () => {
20
- test(`Recibiendo: ${FIELD_TO_TEST}, con simbolo ${SYMBOL} y position ${POSITION} debe devolver '${SYMBOL}${FIELD_TO_TEST}'`, () => {
21
- stringResult = insertSimbol(FIELD_TO_TEST, SYMBOL, POSITION);
22
- assert.equal(stringResult === `${SYMBOL}${FIELD_TO_TEST}`, true);
23
- });
24
- test(`Recibiendo: ${FIELD_TO_TEST}, con simbolo ${SYMBOL} y sin position debe devolver '${FIELD_TO_TEST}${SYMBOL}'`, () => {
25
- stringResult = insertSimbol(FIELD_TO_TEST, SYMBOL);
26
- assert.equal(stringResult === `${FIELD_TO_TEST}${SYMBOL}`, true);
27
- });
28
- });
29
-
30
- describe("persistenceToDisplayPercent=> sub-test suite", () => {
31
- test(`Recibiendo: ${FIELD_TO_TEST}, position ${POSITION} debe devolver '${SYMBOL}${parseFloat(
32
- FIELD_TO_TEST
33
- ).toFixed(2)}'`, () => {
34
- stringResult = persistenceToDisplayPercent(FIELD_TO_TEST, POSITION);
35
- assert.equal(
36
- stringResult === `${SYMBOL}${parseFloat(FIELD_TO_TEST).toFixed(2)}`,
37
- true
38
- );
39
- });
40
- test(`Recibiendo: ${FIELD_TO_TEST} y sin position debe devolver '${parseFloat(
41
- FIELD_TO_TEST
42
- ).toFixed(2)}${SYMBOL}'`, () => {
43
- stringResult = persistenceToDisplayPercent(FIELD_TO_TEST);
44
- assert.equal(
45
- stringResult === `${parseFloat(FIELD_TO_TEST).toFixed(2)}${SYMBOL}`,
46
- true
47
- );
48
- });
49
- });
50
- });
@@ -1,40 +0,0 @@
1
- import { idAyudaToKeyAyuda, isLocalhost } from "../src";
2
- import { describe, test, assert } from "vitest";
3
- import { idMutualToCodMutual } from "../src/commons/defaultValues";
4
-
5
- let mapResult: {
6
- codMutual: string;
7
- codDelegacion: string;
8
- NroSolicitud: number;
9
- } = { codMutual: "", codDelegacion: "", NroSolicitud: 0 };
10
-
11
- let _isLocalhost: boolean;
12
-
13
- const IDAYUDA_RESULT: {
14
- codMutual: string;
15
- codDelegacion: string;
16
- NroSolicitud: number;
17
- } = {
18
- codMutual: idMutualToCodMutual["01"],
19
- codDelegacion: "000001",
20
- NroSolicitud: 1,
21
- };
22
-
23
- const IDAYUDA = "01000001000000001";
24
-
25
- describe("Utils test suite", () => {
26
- test(`idAyudaToKeyAyuda=> Recibiendo: '${IDAYUDA}', debe devolver {codMutual:'${IDAYUDA_RESULT.codMutual}',NroSolicitud:${IDAYUDA_RESULT.NroSolicitud},codDelegacion:'${IDAYUDA_RESULT.codDelegacion}'}`, () => {
27
- mapResult = idAyudaToKeyAyuda(IDAYUDA);
28
- assert.equal(
29
- mapResult.codMutual === IDAYUDA_RESULT.codMutual &&
30
- mapResult.NroSolicitud === IDAYUDA_RESULT.NroSolicitud &&
31
- mapResult.codDelegacion === IDAYUDA_RESULT.codDelegacion,
32
- true
33
- );
34
- });
35
-
36
- test(`isLocalhost=> Debe devolver si es localhost o no (en el caso del test, no se tiene acceso al objeto window, por ende, debería devolver false)`, () => {
37
- _isLocalhost = isLocalhost;
38
- assert.equal(_isLocalhost, false);
39
- });
40
- });