@wikicasa-dev/utilities 0.1.1 → 0.1.2

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.
Files changed (51) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/utilities.cjs +4 -4
  3. package/dist/utilities.iife.js +2 -2
  4. package/dist/utilities.mjs +57 -51
  5. package/dist/utils/DateUtils.d.ts +1 -0
  6. package/package.json +2 -5
  7. package/src/custom/constants.ts +3 -0
  8. package/src/custom/icons.ts +63 -0
  9. package/src/custom/leaflet_map.ts +946 -0
  10. package/src/index.ts +173 -0
  11. package/src/services/agencyAPI.ts +105 -0
  12. package/src/services/geographyAPI.ts +129 -0
  13. package/src/services/insightsAPI.ts +20 -0
  14. package/src/services/mailAPI.ts +89 -0
  15. package/src/services/placesAPI.ts +72 -0
  16. package/src/services/portfolioCustomerAPI.ts +16 -0
  17. package/src/services/publicUserAPI.ts +216 -0
  18. package/src/services/realEstateAPI.ts +133 -0
  19. package/src/services/requestAPI.ts +40 -0
  20. package/src/services/servicesUtils.ts +27 -0
  21. package/src/services/statisticsAPI.ts +84 -0
  22. package/src/services/valuationAPI.ts +45 -0
  23. package/src/services/wikicasaPro.ts +25 -0
  24. package/src/utils/AppRedirectUtils.ts +26 -0
  25. package/src/utils/ArrayUtils.ts +2 -0
  26. package/src/utils/ColorUtils.ts +11 -0
  27. package/src/utils/CookieUtils.ts +43 -0
  28. package/src/utils/CurrencyUtils.ts +18 -0
  29. package/src/utils/DOMUtils.ts +28 -0
  30. package/src/utils/DateUtils.ts +9 -0
  31. package/src/utils/DeviceDetectionUtils.ts +17 -0
  32. package/src/utils/EmailUtils.ts +45 -0
  33. package/src/utils/FavoriteUtils.ts +19 -0
  34. package/src/utils/FunctionUtils.ts +29 -0
  35. package/src/utils/GAEvents.ts +414 -0
  36. package/src/utils/GAutocompleteUtils.ts +70 -0
  37. package/src/utils/GenericUtils.ts +37 -0
  38. package/src/utils/LazyLoadingBg.ts +18 -0
  39. package/src/utils/MapUtils.ts +118 -0
  40. package/src/utils/NumberUtils.ts +90 -0
  41. package/src/utils/ObjectUtils.ts +34 -0
  42. package/src/utils/ObserverUtils.ts +32 -0
  43. package/src/utils/PermissionUtils.ts +41 -0
  44. package/src/utils/RESB_UrlBuilder.ts +99 -0
  45. package/src/utils/RequestUtils.ts +20 -0
  46. package/src/utils/StringUtils.ts +67 -0
  47. package/src/utils/URLBuilderUtils.ts +21 -0
  48. package/src/utils/URLPagesFactory.ts +20 -0
  49. package/src/vite-env.d.ts +1 -0
  50. package/tsconfig.json +38 -0
  51. package/vite.config.ts +42 -0
@@ -0,0 +1,216 @@
1
+ import type {
2
+ PublicUser,
3
+ PublicUserMenuInfo,
4
+ SaveSearchBean,
5
+ } from "@wikicasa-dev/types";
6
+
7
+ import { getDefaultSaveSearchBean } from "@wikicasa-dev/types";
8
+ import axios, { AxiosError } from "axios";
9
+ import { handleAxiosError } from "./servicesUtils";
10
+
11
+ //@ts-ignore
12
+ const baseURL: string = window["_baseURLIt"];
13
+ const baseController = `${baseURL}/rest/publicUser`;
14
+
15
+ export const getMenuInfo = async (): Promise<PublicUserMenuInfo> => {
16
+ try {
17
+ const res = await axios.get(`${baseController}/getMenuInfo`);
18
+ return res.data as PublicUserMenuInfo;
19
+ } catch (error) {
20
+ handleAxiosError(error as AxiosError);
21
+ throw null;
22
+ }
23
+ };
24
+
25
+ export const getPublicUser = async (): Promise<PublicUser> => {
26
+ try {
27
+ const res = await axios.get(`${baseController}/getUser`);
28
+ return res.data as PublicUser;
29
+ } catch (err) {
30
+ handleAxiosError(err as AxiosError);
31
+ throw null;
32
+ }
33
+ };
34
+
35
+ export const getMarketingConsent = async (email: string): Promise<boolean> => {
36
+ try {
37
+ const res = await axios.get(
38
+ `${baseController}/getMarketingConsent?email=${email}`
39
+ );
40
+ return res.data as boolean;
41
+ } catch (error) {
42
+ handleAxiosError(error as AxiosError);
43
+ return false;
44
+ }
45
+ };
46
+
47
+ export const deleteAllSaveSearch = async (): Promise<number> => {
48
+ try {
49
+ const res = await axios.post(`${baseController}/deleteAllUserSaveSearch`);
50
+ return res.data as number;
51
+ } catch (err) {
52
+ handleAxiosError(err as AxiosError);
53
+ throw null;
54
+ }
55
+ };
56
+
57
+ export const deleteSaveSearch = async (id: number): Promise<string> => {
58
+ try {
59
+ const res = await axios.post(
60
+ `${baseController}/deleteUserSaveSearchParam/${id}`
61
+ );
62
+ return res.data as string;
63
+ } catch (error) {
64
+ handleAxiosError(error as AxiosError);
65
+ throw null;
66
+ }
67
+ };
68
+
69
+ export const getFavourites = async (): Promise<number[]> => {
70
+ try {
71
+ const res = await axios.get(`${baseController}/getFavouriteIdList`);
72
+ return res.data as number[];
73
+ } catch (error) {
74
+ handleAxiosError(error as AxiosError);
75
+ return [];
76
+ }
77
+ };
78
+
79
+ export const addUserFavorite = async (id: number): Promise<boolean> => {
80
+ try {
81
+ const res = await axios.post(`${baseController}/addUserFavourite/${id}`);
82
+ return res.data as boolean;
83
+ } catch (error) {
84
+ handleAxiosError(error as AxiosError);
85
+ return false;
86
+ }
87
+ };
88
+
89
+ export const deleteUserFavorite = async (id: number): Promise<boolean> => {
90
+ try {
91
+ const res = await axios.post(`${baseController}/deleteUserFavourite/${id}`);
92
+ return res.data as boolean;
93
+ } catch (error) {
94
+ handleAxiosError(error as AxiosError);
95
+ return false;
96
+ }
97
+ };
98
+
99
+ export const updateNote = async (
100
+ id: number,
101
+ note: string | null
102
+ ): Promise<boolean> => {
103
+ if (note === " " || note === " ") return false;
104
+
105
+ try {
106
+ const res = await axios.post(`${baseController}/updateFavouriteNote`, {
107
+ realEstateId: id,
108
+ note: note,
109
+ });
110
+ return res.data as boolean;
111
+ } catch (error) {
112
+ handleAxiosError(error as AxiosError);
113
+ return false;
114
+ }
115
+ };
116
+
117
+ export const removeFavourites = async (): Promise<boolean> => {
118
+ try {
119
+ const res = await axios.post(`${baseController}/deleteAllUserFavourite`);
120
+ return res.data as boolean;
121
+ } catch (error) {
122
+ handleAxiosError(error as AxiosError);
123
+ return false;
124
+ }
125
+ };
126
+
127
+ export const saveUserFirebaseToken = async (
128
+ firebaseToken: string
129
+ ): Promise<boolean> => {
130
+ try {
131
+ if (!firebaseToken) return false;
132
+
133
+ await axios.post(
134
+ `${baseController}/refreshUserFirebaseToken?token=${firebaseToken}`
135
+ );
136
+ return true;
137
+ } catch (err) {
138
+ return false;
139
+ }
140
+ };
141
+
142
+ export const deleteUserFirebaseToken = async (
143
+ firebaseToken: string
144
+ ): Promise<boolean> => {
145
+ try {
146
+ await axios.delete(
147
+ `${baseController}/deleteUserFirebaseToken?token=${firebaseToken}`
148
+ );
149
+ return true;
150
+ } catch (error) {
151
+ return false;
152
+ }
153
+ };
154
+
155
+ export const updateMarketingConsent = async (data: {
156
+ email: string;
157
+ marketingConsent: boolean;
158
+ }): Promise<boolean> => {
159
+ const { email, marketingConsent } = data;
160
+ try {
161
+ await axios.post(
162
+ `${baseController}/updateMarketingConsent?email=${email}&marketingConsent=${marketingConsent}`,
163
+ data
164
+ );
165
+ return true;
166
+ } catch (error) {
167
+ handleAxiosError(error as AxiosError);
168
+ return false;
169
+ }
170
+ /* return $.ajax({
171
+ type: "POST",
172
+ contentType: "application/json",
173
+ data: JSON.stringify(data),
174
+ url: `/rest/publicUser/updateMarketingConsent?email=${email}&marketingConsent=${marketingConsent}`,
175
+ });*/
176
+ };
177
+
178
+ export const getPublicUserSaveSearchList = async (
179
+ offset = 0,
180
+ limit = 10
181
+ ): Promise<Array<any>> => {
182
+ try {
183
+ const res = await axios.get(
184
+ `${baseController}/getPublicUserSavedSearchBeanList/${offset}/${limit}`
185
+ );
186
+ return res.data as Array<SaveSearchBean>;
187
+ } catch (error) {
188
+ handleAxiosError(error as AxiosError);
189
+ return [];
190
+ }
191
+ };
192
+ export const updatePublicUserSavedSearchBean = async (
193
+ savedSearchBean: SaveSearchBean
194
+ ): Promise<SaveSearchBean> => {
195
+ try {
196
+ const res = await axios.post(
197
+ `${baseController}/updatePublicUserSavedSearchBean/`,
198
+ savedSearchBean
199
+ );
200
+ return res.data as SaveSearchBean;
201
+ } catch (error) {
202
+ handleAxiosError(error as AxiosError);
203
+ return getDefaultSaveSearchBean();
204
+ }
205
+ };
206
+ export const getSavedSearchesCount = async (): Promise<number> => {
207
+ try {
208
+ const res = await axios.get(
209
+ `${baseController}/getPublicUserSaveSearchCount`
210
+ );
211
+ return res.data as number;
212
+ } catch (error) {
213
+ handleAxiosError(error as AxiosError);
214
+ return 0;
215
+ }
216
+ };
@@ -0,0 +1,133 @@
1
+ import axios, { AxiosError, AxiosResponse } from "axios";
2
+ import { handleAxiosError } from "./servicesUtils";
3
+ import type {
4
+ RealEstateSearchBean,
5
+ MapMarker,
6
+ RealEstateMiniItem,
7
+ Nullable,
8
+ } from "@wikicasa-dev/types";
9
+ import { deepCopy } from "@utils/ObjectUtils";
10
+
11
+ declare global {
12
+ interface Window {
13
+ _serializedSearchBean?: Nullable<any>;
14
+ _locale: string;
15
+ }
16
+ }
17
+
18
+ //@ts-ignore
19
+ const baseUrl: string = window["_baseURLIt"];
20
+ const baseController = `${baseUrl}/rest/realEstate`;
21
+
22
+ export const getRealEstateNotes = async (
23
+ realEstateId: number
24
+ ): Promise<string> => {
25
+ try {
26
+ const res = await axios.post(
27
+ `${baseUrl}/rest/publicUser/getRealEstateNotes/${realEstateId}`
28
+ );
29
+ return res.data;
30
+ } catch (error) {
31
+ handleAxiosError(error as AxiosError);
32
+ return "";
33
+ }
34
+ };
35
+
36
+ export const saveSearch = async (
37
+ email: string,
38
+ title: string,
39
+ hourly: boolean,
40
+ resb: RealEstateSearchBean,
41
+ pushNotifications = false
42
+ ): Promise<AxiosResponse> => {
43
+ if (!email || !resb) throw `Email or resb are not valid, ${email}, ${resb}`;
44
+
45
+ //TODO: solo per testing dato che bisogna chiedere il consenso all'utente
46
+ return await axios.post(
47
+ `${baseController}/saveSearch?email=${email}&title=${title}&hourly=${hourly}&pushNotifications=${pushNotifications}`,
48
+ resb
49
+ );
50
+ // return await axios.post(`${baseController}/saveSearch?email=${email}&title=${title}&hourly=${hourly}`, resb);
51
+ };
52
+
53
+ export const saveSearchFromRequest = async (
54
+ email: string,
55
+ searchBean: RealEstateSearchBean,
56
+ pushNotifications = false
57
+ ): Promise<boolean> => {
58
+ try {
59
+ const title = "Ricerca salvata";
60
+ //TODO: solo per testing dato che bisogna chiedere il consenso all'utente
61
+ const res = await axios.post(
62
+ `${baseController}/saveSearch?email=${email}&title=${title}&pushNotifications=${pushNotifications}`,
63
+ searchBean
64
+ );
65
+ // const res = await axios.post(`/rest/realEstate/saveSearch?email=${email}`, searchBean);
66
+ return res.data as boolean;
67
+ } catch (error) {
68
+ handleAxiosError(error as AxiosError);
69
+ throw error;
70
+ }
71
+ };
72
+
73
+ export const getRealEstateCounter = async (
74
+ resb: RealEstateSearchBean
75
+ ): Promise<number | null> => {
76
+ const tempSB = deepCopy(resb);
77
+ /* Use polygon for DB only if it already set */
78
+ if (tempSB!.polygonForDB) {
79
+ tempSB!.polygonFromMap = tempSB!.polygonForDB || "";
80
+ }
81
+
82
+ /* SOREX: BRUTAL FIX COUNTER NUOVE COSTRUZIONI */
83
+ if (tempSB?.listingTypologyIdList?.includes(15)) {
84
+ tempSB.conditionType = 5;
85
+ }
86
+
87
+ const res = await axios.post("/rest/realEstate/countRealEstateES", tempSB);
88
+ return (await res.data) as number | null;
89
+ };
90
+
91
+ export const getRealEstatesData = async (
92
+ ids: Array<number>
93
+ ): Promise<Array<RealEstateMiniItem> | null> => {
94
+ try {
95
+ const res = await axios.post(
96
+ `${baseUrl}/rest/realEstate/getRealEstateListForInfoWindow/${window["_locale"]}`,
97
+ ids
98
+ );
99
+ return res.data;
100
+ } catch (e) {
101
+ handleAxiosError(e as AxiosError);
102
+ return null;
103
+ }
104
+ };
105
+
106
+ export const getMapMarkers = async (): Promise<
107
+ Array<MapMarker> | undefined
108
+ > => {
109
+ if (!window["_serializedSearchBean"]) return [];
110
+
111
+ const searchBean = deepCopy(JSON.parse(window["_serializedSearchBean"]));
112
+
113
+ delete searchBean["latitude"];
114
+ delete searchBean["longitude"];
115
+
116
+ try {
117
+ const res = await axios.post(
118
+ `${baseUrl}/rest/realEstate/getMapMarkers`,
119
+ searchBean,
120
+ {
121
+ headers: {
122
+ "Content-Type": "application/json",
123
+ Accept: "application/json",
124
+ },
125
+ }
126
+ );
127
+
128
+ return res.data as MapMarker[];
129
+ } catch (err) {
130
+ handleAxiosError(err as AxiosError);
131
+ throw [];
132
+ }
133
+ };
@@ -0,0 +1,40 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import type { Contacts } from "@wikicasa-dev/types";
3
+ import { baseURL, handleAxiosError } from "./servicesUtils";
4
+
5
+ const baseController = `${baseURL}/rest/request`;
6
+
7
+ export const sendSuggestion = async (suggestion: {
8
+ argument: string;
9
+ email: string;
10
+ message: string;
11
+ privacy: boolean;
12
+ url: string;
13
+ }): Promise<boolean> => {
14
+ const res = await axios.post(`${baseController}/sendSuggestion`, suggestion);
15
+ return res.data as boolean;
16
+ };
17
+
18
+ export const addGenericRequest = async (data: Contacts): Promise<boolean> => {
19
+ try {
20
+ const res = await axios.post("/rest/request/addRequestGeneric", data);
21
+ return res.data;
22
+ } catch (error) {
23
+ handleAxiosError(error as AxiosError);
24
+ throw error;
25
+ }
26
+ };
27
+
28
+ export const sendWidgetRequest = async (suggestion: {
29
+ name: string;
30
+ company: string;
31
+ email: string;
32
+ phone: string;
33
+ privacy: boolean;
34
+ }): Promise<boolean> => {
35
+ const res = await axios.post(
36
+ `${baseController}/sendWidgetRequest`,
37
+ suggestion
38
+ );
39
+ return res.data as boolean;
40
+ };
@@ -0,0 +1,27 @@
1
+ import { AxiosError } from "axios";
2
+
3
+ declare global {
4
+ interface Window {
5
+ _baseURLIt: string;
6
+ }
7
+ }
8
+
9
+ export const baseURL: string = window["_baseURLIt"];
10
+
11
+ export const handleAxiosError = (error: AxiosError): void => {
12
+ const cause = `errorMessage: ${error.message} \n`;
13
+ //ErrorCode !== 200 with server response
14
+ if (error.response) {
15
+ console.error(
16
+ `${cause} errorCode: ${error.response.status} \\n ${error.request.data}`
17
+ );
18
+ }
19
+ //ErrorCode !== 200 WITHOUT server response
20
+ else if (error.request) {
21
+ console.error(`${cause} \n ${error.request}`);
22
+ }
23
+ //Error in request setup
24
+ else {
25
+ console.error(cause);
26
+ }
27
+ };
@@ -0,0 +1,84 @@
1
+ import type { Place, GraphData } from "@wikicasa-dev/types";
2
+ import axios, { AxiosError } from "axios";
3
+ import { handleAxiosError } from "./servicesUtils";
4
+
5
+ const baseStatisticControllerUrl = "/rest/statistics";
6
+
7
+ export const updateViewListing = async (
8
+ data: Array<{ agencyId: number; realEstateId: number }>
9
+ ): Promise<boolean> => {
10
+ try {
11
+ await axios.post(`${baseStatisticControllerUrl}/updateViewListing/W`, data);
12
+ return true;
13
+ } catch (error) {
14
+ handleAxiosError(error as AxiosError);
15
+ return false;
16
+ }
17
+ };
18
+
19
+ export const updateRealEstateSearch = async (
20
+ realEstateSearchBean: any
21
+ ): Promise<boolean> => {
22
+ try {
23
+ axios.post(
24
+ `${baseStatisticControllerUrl}/updateRealEstateSearch`,
25
+ realEstateSearchBean
26
+ );
27
+ return true;
28
+ } catch (error) {
29
+ handleAxiosError(error as AxiosError);
30
+ return false;
31
+ }
32
+ };
33
+
34
+ export const updatePhoneView = async (
35
+ agencyId: number,
36
+ id: number
37
+ ): Promise<boolean> => {
38
+ try {
39
+ const res = await axios.post(
40
+ id
41
+ ? `${baseStatisticControllerUrl}/updatePhoneView/${agencyId}/${id}/W`
42
+ : `/rest/statistics/updatePhoneView/${agencyId}/W`
43
+ );
44
+ return res.data;
45
+ } catch (error) {
46
+ handleAxiosError(error as AxiosError);
47
+ throw error;
48
+ }
49
+ };
50
+ export const getPlaceTrendData = async (place: Place): Promise<any> => {
51
+ try {
52
+ const promiseSale = await axios.post(
53
+ `${baseStatisticControllerUrl}/getPlaceTrendData?sale=${true}`,
54
+ place
55
+ );
56
+ const promiseRent = await axios.post(
57
+ `${baseStatisticControllerUrl}/getPlaceTrendData?sale=${false}`,
58
+ place
59
+ );
60
+ return Promise.all([promiseSale, promiseRent]);
61
+ } catch (error) {
62
+ handleAxiosError(error as AxiosError);
63
+ throw error;
64
+ }
65
+ };
66
+
67
+ export const getSaleGraphData = async (
68
+ place: Place,
69
+ filters: any = {
70
+ contract: "sale",
71
+ macroTypologyId: 1,
72
+ }
73
+ ): Promise<GraphData[]> => {
74
+ try {
75
+ const res = await axios.post(
76
+ `${baseStatisticControllerUrl}/getAveragePriceGraphData/${filters.contract}/${filters.macroTypologyId}`,
77
+ place
78
+ );
79
+ return res.data;
80
+ } catch (error) {
81
+ handleAxiosError(error as AxiosError);
82
+ throw error;
83
+ }
84
+ };
@@ -0,0 +1,45 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import type { PublicValuation, Nullable } from "@wikicasa-dev/types";
3
+ import { handleAxiosError, baseURL } from "@services/servicesUtils";
4
+ import { appendQueryString } from "@utils/URLBuilderUtils";
5
+
6
+ const baseController = `/rest/wikicasaPro`;
7
+
8
+ export interface ValuationResult
9
+ extends Record<string, number | boolean | undefined> {
10
+ valid: boolean;
11
+ upper: number;
12
+ mean: number;
13
+ lower: number;
14
+ estimated: number;
15
+ count: number;
16
+ maxDistance?: number;
17
+ }
18
+
19
+ // eslint-disable-next-line max-len
20
+ export const evaluateRealEstateWidget = async (
21
+ publicValuation: PublicValuation,
22
+ token: Nullable<string>,
23
+ conditionTypeId = undefined as number | undefined,
24
+ floor = undefined as number | undefined
25
+ ): Promise<PublicValuation> => {
26
+ if (!token) throw new Error("The token can't be null");
27
+
28
+ try {
29
+ let params: Record<string, any> = { token: token };
30
+
31
+ if (conditionTypeId) params = { ...params, conditionTypeId };
32
+ if (floor != undefined) params = { ...params, floor };
33
+
34
+ const url = appendQueryString(
35
+ new URL(`${baseURL}${baseController}/evaluateRealEstateWidget`),
36
+ params
37
+ );
38
+ const res = await axios.post(url.toString(), publicValuation);
39
+ res.data.valid = !!res.data.valid;
40
+ return res.data as PublicValuation;
41
+ } catch (error) {
42
+ handleAxiosError(error as AxiosError);
43
+ throw error;
44
+ }
45
+ };
@@ -0,0 +1,25 @@
1
+ import axios, { AxiosError } from "axios";
2
+ import { handleAxiosError } from "./servicesUtils";
3
+ import type { FEEDBACK } from "@wikicasa-dev/types/dist/index";
4
+
5
+ const baseStatisticControllerUrl = "/rest/wikicasaPro";
6
+
7
+ export const userValuationWithPhotoFeedback = async (
8
+ email: string,
9
+ token: string,
10
+ feedback: FEEDBACK,
11
+ userFeedbackValue: number = 0
12
+ ): Promise<boolean> => {
13
+ try {
14
+ // eslint-disable-next-line max-len
15
+ const res = await axios.post(
16
+ `${baseStatisticControllerUrl}/userValuationWithPhotoFeedback/?email=${email}&token=${token}&feedback=${feedback}${
17
+ userFeedbackValue > 0 ? "&userFeedbackValue=" + userFeedbackValue : ""
18
+ }`
19
+ );
20
+ return res.data;
21
+ } catch (error) {
22
+ handleAxiosError(error as AxiosError);
23
+ throw error;
24
+ }
25
+ };
@@ -0,0 +1,26 @@
1
+ export const redirectToApp = (
2
+ eventLocation: "Banner" | "MenuUserModal" = "Banner"
3
+ ): void => {
4
+ if (window.navigator.userAgent.includes("iPhone")) {
5
+ //firefox on ios can't open the app
6
+ if (!window.navigator.userAgent.match(/firefox|fxios/i))
7
+ window.location.replace("wikicasa://");
8
+
9
+ setTimeout(() => {
10
+ window.location.replace(
11
+ "https://apps.apple.com/it/app/wikicasa/id1626038379"
12
+ );
13
+ }, 500);
14
+ } else if (window.navigator.userAgent.includes("Android")) {
15
+ const url =
16
+ "intent://wikicasa.it/#Intent;scheme=https;package=it.wikicasa.wikicasa_app;end";
17
+ window.location.replace(url);
18
+ }
19
+ //@ts-ignore
20
+ window.dataLayer.push({
21
+ //GA4
22
+ event_name: "open_store",
23
+ event_location: eventLocation,
24
+ OS: window.navigator?.userAgent,
25
+ });
26
+ };
@@ -0,0 +1,2 @@
1
+ export const isArrNullOrEmpty = (arrToCheck?: any[]): boolean =>
2
+ !arrToCheck?.length;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @return {string}
3
+ */
4
+ export function rgba(hex: string, opacity: number): string {
5
+ hex = hex.replace("#", "");
6
+ const r = parseInt(hex.substring(0, 2), 16);
7
+ const g = parseInt(hex.substring(2, 4), 16);
8
+ const b = parseInt(hex.substring(4, 6), 16);
9
+
10
+ return `rgba(${r}, ${g}, ${b}, ${opacity})`;
11
+ }
@@ -0,0 +1,43 @@
1
+ import * as Cookie from "js-cookie";
2
+
3
+ export function encodeCookie<T>(
4
+ name: string,
5
+ obj: T,
6
+ days: number = 30,
7
+ encodeObj = true
8
+ ): void {
9
+ const d = new Date();
10
+ d.setTime(d.getTime() + 24 * 60 * 60 * 1000 * days);
11
+
12
+ const stringObj = typeof obj !== "string" ? JSON.stringify(obj) : obj;
13
+ const cookieValue = encodeObj
14
+ ? btoa(encodeURIComponent(stringObj))
15
+ : stringObj;
16
+ document.cookie =
17
+ name + "=" + cookieValue + ";path=/;expires=" + d.toUTCString();
18
+ }
19
+
20
+ export function getCookie(name: string): string | null {
21
+ try {
22
+ const v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
23
+ return v ? v[2] : null;
24
+ } catch (e) {
25
+ console.error(e);
26
+ return null;
27
+ }
28
+ }
29
+
30
+ export function decodeCookie(name: string): any {
31
+ try {
32
+ const v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
33
+ return v ? JSON.parse(decodeURIComponent(atob(v[2]))) : null;
34
+ } catch (e) {
35
+ console.error(e);
36
+ removeCookie(name);
37
+ return null;
38
+ }
39
+ }
40
+
41
+ export function removeCookie(name: string): void {
42
+ Cookie.remove(name);
43
+ }
@@ -0,0 +1,18 @@
1
+ import { shallowCopyObjectTo } from "@utils/ObjectUtils";
2
+
3
+ export const formatCurrency = (
4
+ numberToFormat: number | undefined,
5
+ options?: Intl.NumberFormatOptions,
6
+ locale = "it-IT"
7
+ ): string => {
8
+ if (numberToFormat === undefined) return `0`;
9
+
10
+ const _options: Partial<Intl.NumberFormatOptions> = {
11
+ style: "currency",
12
+ currency: "EUR",
13
+ maximumFractionDigits: 0,
14
+ };
15
+ shallowCopyObjectTo(options, _options);
16
+
17
+ return new Intl.NumberFormat(locale, _options).format(numberToFormat);
18
+ };