@cuemath/web-utils 1.0.8-deepak.0 → 1.0.8
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/dist/cjs/constants/country/index.js.map +1 -0
- package/dist/cjs/constants/country/iso-country-code.js.map +1 -0
- package/dist/cjs/constants/date-time/index.js.map +1 -0
- package/dist/cjs/constants/date-time/international-timezones.js.map +1 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/cookie/index.js.map +1 -0
- package/dist/{date-time-helper → cjs/date-time-helper}/index.js +1 -1
- package/dist/cjs/date-time-helper/index.js.map +1 -0
- package/dist/cjs/e-cna/index.js.map +1 -0
- package/dist/{growth-source → cjs/growth-source}/index.js +4 -2
- package/dist/cjs/growth-source/index.js.map +1 -0
- package/dist/{growth-source → cjs/growth-source}/types.d.ts +1 -1
- package/dist/{growth-source → cjs/growth-source}/types.js.map +1 -1
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/local-storage/index.js.map +1 -0
- package/dist/cjs/object/index.js.map +1 -0
- package/dist/esm/constants/country/index.js +2 -0
- package/dist/esm/constants/country/index.js.map +1 -0
- package/dist/esm/constants/country/iso-country-code.d.ts +248 -0
- package/dist/esm/constants/country/iso-country-code.js +249 -0
- package/dist/esm/constants/country/iso-country-code.js.map +1 -0
- package/dist/esm/constants/date-time/index.d.ts +18 -0
- package/dist/esm/constants/date-time/index.js +40 -0
- package/dist/esm/constants/date-time/index.js.map +1 -0
- package/dist/esm/constants/date-time/international-timezones.d.ts +7 -0
- package/dist/esm/constants/date-time/international-timezones.js +148 -0
- package/dist/esm/constants/date-time/international-timezones.js.map +1 -0
- package/dist/esm/constants/index.js +3 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/cookie/index.d.ts +4 -0
- package/dist/esm/cookie/index.js +38 -0
- package/dist/esm/cookie/index.js.map +1 -0
- package/dist/esm/date-time-helper/index.d.ts +30 -0
- package/dist/esm/date-time-helper/index.js +87 -0
- package/dist/esm/date-time-helper/index.js.map +1 -0
- package/dist/esm/e-cna/index.d.ts +4 -0
- package/dist/esm/e-cna/index.js +18 -0
- package/dist/esm/e-cna/index.js.map +1 -0
- package/dist/esm/growth-source/index.d.ts +6 -0
- package/dist/esm/growth-source/index.js +180 -0
- package/dist/esm/growth-source/index.js.map +1 -0
- package/dist/esm/growth-source/types.d.ts +41 -0
- package/dist/esm/growth-source/types.js +2 -0
- package/dist/esm/growth-source/types.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/local-storage/index.d.ts +13 -0
- package/dist/esm/local-storage/index.js +162 -0
- package/dist/esm/local-storage/index.js.map +1 -0
- package/dist/esm/object/index.d.ts +2 -0
- package/dist/esm/object/index.js +19 -0
- package/dist/esm/object/index.js.map +1 -0
- package/package.json +11 -4
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -9
- package/.husky/pre-commit +0 -5
- package/.huskyrc +0 -5
- package/.lintstagedrc.yml +0 -1
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -1
- package/.vscode/settings.json +0 -1
- package/dist/constants/country/index.js.map +0 -1
- package/dist/constants/country/iso-country-code.js.map +0 -1
- package/dist/constants/date-time/index.js.map +0 -1
- package/dist/constants/date-time/international-timezones.js.map +0 -1
- package/dist/constants/index.js.map +0 -1
- package/dist/cookie/index.js.map +0 -1
- package/dist/date-time-helper/index.js.map +0 -1
- package/dist/e-cna/index.js.map +0 -1
- package/dist/growth-source/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/local-storage/index.js.map +0 -1
- package/dist/object/index.js.map +0 -1
- package/src/constants/country/iso-country-code.ts +0 -248
- package/src/constants/date-time/index.ts +0 -45
- package/src/constants/date-time/international-timezones.ts +0 -157
- package/src/cookie/index.ts +0 -59
- package/src/date-time-helper/index.ts +0 -139
- package/src/e-cna/index.ts +0 -23
- package/src/growth-source/index.ts +0 -233
- package/src/growth-source/types.ts +0 -50
- package/src/local-storage/index.ts +0 -196
- package/src/object/index.ts +0 -21
- package/tsconfig.json +0 -8
- /package/dist/{constants → cjs/constants}/country/index.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/country/index.js +0 -0
- /package/dist/{constants → cjs/constants}/country/iso-country-code.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/country/iso-country-code.js +0 -0
- /package/dist/{constants → cjs/constants}/date-time/index.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/date-time/index.js +0 -0
- /package/dist/{constants → cjs/constants}/date-time/international-timezones.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/date-time/international-timezones.js +0 -0
- /package/dist/{constants → cjs/constants}/index.d.ts +0 -0
- /package/dist/{constants → cjs/constants}/index.js +0 -0
- /package/dist/{cookie → cjs/cookie}/index.d.ts +0 -0
- /package/dist/{cookie → cjs/cookie}/index.js +0 -0
- /package/dist/{date-time-helper → cjs/date-time-helper}/index.d.ts +0 -0
- /package/dist/{e-cna → cjs/e-cna}/index.d.ts +0 -0
- /package/dist/{e-cna → cjs/e-cna}/index.js +0 -0
- /package/dist/{growth-source → cjs/growth-source}/index.d.ts +0 -0
- /package/dist/{growth-source → cjs/growth-source}/types.js +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{local-storage → cjs/local-storage}/index.d.ts +0 -0
- /package/dist/{local-storage → cjs/local-storage}/index.js +0 -0
- /package/dist/{object → cjs/object}/index.d.ts +0 -0
- /package/dist/{object → cjs/object}/index.js +0 -0
- /package/{src/constants/country/index.ts → dist/esm/constants/country/index.d.ts} +0 -0
- /package/{src/constants/index.ts → dist/esm/constants/index.d.ts} +0 -0
- /package/{src/index.ts → dist/esm/index.d.ts} +0 -0
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SourceDetails,
|
|
3
|
-
SourceDetailsCookie,
|
|
4
|
-
Platform,
|
|
5
|
-
SignupFlow,
|
|
6
|
-
UTMParams,
|
|
7
|
-
Experiments,
|
|
8
|
-
RevenueChannel,
|
|
9
|
-
UTMParamsKeys,
|
|
10
|
-
} from './types';
|
|
11
|
-
|
|
12
|
-
import { createCookie, getCookie, removeCookie } from '../cookie';
|
|
13
|
-
|
|
14
|
-
const SOURCE_DETAILS_COOKIE = 'source_details';
|
|
15
|
-
const UTM_PARAMS: UTMParamsKeys[] = [
|
|
16
|
-
'utm_source',
|
|
17
|
-
'utm_medium',
|
|
18
|
-
'utm_campaign',
|
|
19
|
-
'utm_term',
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
export const readSourceCookie = (): SourceDetailsCookie => {
|
|
23
|
-
const sourceDetails = getCookie(SOURCE_DETAILS_COOKIE);
|
|
24
|
-
|
|
25
|
-
return sourceDetails ? JSON.parse(decodeURIComponent(sourceDetails)) : undefined;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const writeSourceCookie = (sourceDetails: SourceDetailsCookie): void => {
|
|
29
|
-
createCookie(SOURCE_DETAILS_COOKIE, JSON.stringify(sourceDetails), 365);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const isSourcePresent = (): boolean => {
|
|
33
|
-
return !!getCookie(SOURCE_DETAILS_COOKIE);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const updateSourceCookie = (sourceDetail: Partial<SourceDetailsCookie>): void => {
|
|
37
|
-
if (!isSourcePresent) return;
|
|
38
|
-
|
|
39
|
-
const sourceDetails: SourceDetailsCookie = readSourceCookie();
|
|
40
|
-
const updatedDetails: SourceDetailsCookie = {
|
|
41
|
-
...sourceDetails,
|
|
42
|
-
...sourceDetail,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
writeSourceCookie(updatedDetails);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const getRevenueChannel = (platform: Platform, utmSource?: string): RevenueChannel => {
|
|
49
|
-
let revenueChannel: RevenueChannel = 'unknown';
|
|
50
|
-
|
|
51
|
-
// set defaults for WEBSITE and ASTRO
|
|
52
|
-
if (platform === 'website') {
|
|
53
|
-
revenueChannel = 'organic';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (utmSource) {
|
|
57
|
-
switch (true) {
|
|
58
|
-
case /^affiliate-/.test(utmSource):
|
|
59
|
-
revenueChannel = 'affiliate';
|
|
60
|
-
break;
|
|
61
|
-
case /^offline-/.test(utmSource):
|
|
62
|
-
revenueChannel = 'offline';
|
|
63
|
-
break;
|
|
64
|
-
case /^referral-/.test(utmSource):
|
|
65
|
-
revenueChannel = 'referral';
|
|
66
|
-
break;
|
|
67
|
-
case /^performance-/.test(utmSource):
|
|
68
|
-
revenueChannel = 'performance';
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return revenueChannel;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
if Platform = website, then decide based on experiment key
|
|
78
|
-
if Platform = Astro, decide logic once BAU is started
|
|
79
|
-
if Platform = APP, decide logic
|
|
80
|
-
if Platform = chatbot, decide based on chatbot experiment key
|
|
81
|
-
*/
|
|
82
|
-
const getFlow = (platform: Platform, experiments?: Experiments): SignupFlow => {
|
|
83
|
-
let flow: SignupFlow = 'regular';
|
|
84
|
-
|
|
85
|
-
if (platform === 'website') {
|
|
86
|
-
if (experiments) {
|
|
87
|
-
const ecnaExp = Object.keys(experiments).find(
|
|
88
|
-
experiment => experiment.indexOf('ecna') !== -1,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
flow = ecnaExp && experiments[ecnaExp] === 'b' ? 'e-cna' : 'regular';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return flow;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const getUTMParams = (): Partial<UTMParams> => {
|
|
99
|
-
if (typeof window === undefined) return {};
|
|
100
|
-
|
|
101
|
-
const search = new URLSearchParams(window.location.search);
|
|
102
|
-
const utmParams = UTM_PARAMS.reduce((acc: UTMParams, param) => {
|
|
103
|
-
const utmParam = search.get(param) as string;
|
|
104
|
-
|
|
105
|
-
if (utmParam) {
|
|
106
|
-
acc[param] = utmParam;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return acc;
|
|
110
|
-
}, {});
|
|
111
|
-
|
|
112
|
-
return utmParams;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const getFirstPage = (): string => {
|
|
116
|
-
if (typeof window === undefined) return '';
|
|
117
|
-
|
|
118
|
-
return window.location.pathname;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/* TODO: Align Marketing Team on UTM source convention
|
|
122
|
-
affiliate-<channel>
|
|
123
|
-
performance-<channel>
|
|
124
|
-
organic-<channel>
|
|
125
|
-
offline-<channel>
|
|
126
|
-
*/
|
|
127
|
-
const getChannel = (utmSource?: string): string => {
|
|
128
|
-
// TODO: UTM source patter for FB, GOOGLE...
|
|
129
|
-
if (!utmSource) return '';
|
|
130
|
-
|
|
131
|
-
let channel = '';
|
|
132
|
-
|
|
133
|
-
if (utmSource) {
|
|
134
|
-
switch (true) {
|
|
135
|
-
case /^affiliate-/.test(utmSource):
|
|
136
|
-
case /^offline-/.test(utmSource):
|
|
137
|
-
case /^referral-/.test(utmSource):
|
|
138
|
-
case /^performance-/.test(utmSource):
|
|
139
|
-
channel = utmSource.split('-')[1];
|
|
140
|
-
break;
|
|
141
|
-
default:
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return channel;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/*
|
|
150
|
-
Set Static Source Details of user on Visit of Platform
|
|
151
|
-
*/
|
|
152
|
-
export const initSourceDetails = async ({
|
|
153
|
-
platform,
|
|
154
|
-
experiments, // only for website.
|
|
155
|
-
flow,
|
|
156
|
-
affiliateChannel,
|
|
157
|
-
offlineChannel,
|
|
158
|
-
organicChannel,
|
|
159
|
-
performanceChannel,
|
|
160
|
-
revenueChannel,
|
|
161
|
-
guestId = '',
|
|
162
|
-
}: SourceDetails): Promise<void> => {
|
|
163
|
-
const utmParams: Partial<UTMParams> = getUTMParams();
|
|
164
|
-
const { utm_source: utmSource } = utmParams;
|
|
165
|
-
const leadChannel = getChannel(utmSource);
|
|
166
|
-
|
|
167
|
-
/*
|
|
168
|
-
source cookie was added in cross subdomain for few days initially,
|
|
169
|
-
which was later changed to subdomain specific. Now to sending older cookie to backend, removing older cookie
|
|
170
|
-
*/
|
|
171
|
-
removeCookie(SOURCE_DETAILS_COOKIE, true);
|
|
172
|
-
|
|
173
|
-
revenueChannel = revenueChannel || getRevenueChannel(platform, utmSource);
|
|
174
|
-
|
|
175
|
-
if (utmSource) {
|
|
176
|
-
affiliateChannel =
|
|
177
|
-
revenueChannel === 'affiliate' ? affiliateChannel || leadChannel : undefined;
|
|
178
|
-
offlineChannel =
|
|
179
|
-
revenueChannel === 'offline' ? offlineChannel || leadChannel : undefined;
|
|
180
|
-
organicChannel =
|
|
181
|
-
revenueChannel === 'organic' ? organicChannel || leadChannel : undefined;
|
|
182
|
-
performanceChannel =
|
|
183
|
-
revenueChannel === 'performance' ? performanceChannel || leadChannel : undefined;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (!isSourcePresent()) {
|
|
187
|
-
const sourceDetails: SourceDetailsCookie = {
|
|
188
|
-
platform_channel: platform,
|
|
189
|
-
experiment_dict: experiments,
|
|
190
|
-
utm_params: utmParams,
|
|
191
|
-
flow: flow || getFlow(platform, experiments),
|
|
192
|
-
affiliate_channel: affiliateChannel,
|
|
193
|
-
offline_channel: offlineChannel,
|
|
194
|
-
organic_channel: organicChannel,
|
|
195
|
-
performance_channel: performanceChannel,
|
|
196
|
-
revenue_channel: revenueChannel,
|
|
197
|
-
first_page: getFirstPage(),
|
|
198
|
-
guest_id: guestId,
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
writeSourceCookie(sourceDetails);
|
|
202
|
-
} else {
|
|
203
|
-
let updatedSource: Partial<SourceDetailsCookie> = {
|
|
204
|
-
experiment_dict: experiments,
|
|
205
|
-
flow: flow || getFlow(platform, experiments),
|
|
206
|
-
guest_id: guestId,
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
if (utmSource) {
|
|
210
|
-
updatedSource = {
|
|
211
|
-
...updatedSource,
|
|
212
|
-
utm_params: utmParams,
|
|
213
|
-
affiliate_channel: affiliateChannel,
|
|
214
|
-
offline_channel: offlineChannel,
|
|
215
|
-
organic_channel: organicChannel,
|
|
216
|
-
performance_channel: performanceChannel,
|
|
217
|
-
revenue_channel: revenueChannel,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
updateSourceCookie(updatedSource);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// Last Page which user visited signup before
|
|
226
|
-
export const setLastPage = async (pagePath: string): Promise<void> => {
|
|
227
|
-
updateSourceCookie({ last_page: pagePath });
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// set Entry point where user clicked to Signup
|
|
231
|
-
export const setFlowEntryPoint = async (flowEntry: string): Promise<void> => {
|
|
232
|
-
updateSourceCookie({ flow_entry: flowEntry });
|
|
233
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export type Platform = 'website' | 'app' | 'astro' | 'leap-teacher' | 'leap-admin';
|
|
2
|
-
export type RevenueChannel =
|
|
3
|
-
| 'organic'
|
|
4
|
-
| 'performance'
|
|
5
|
-
| 'affiliate'
|
|
6
|
-
| 'offline'
|
|
7
|
-
| 'referral'
|
|
8
|
-
| 'unknown';
|
|
9
|
-
export type SignupFlow = 'regular' | 'e-cna' | 'e-sales';
|
|
10
|
-
export type Experiments = Record<string, unknown>;
|
|
11
|
-
export type UTMParams = {
|
|
12
|
-
utm_source?: string;
|
|
13
|
-
utm_medium?: string;
|
|
14
|
-
utm_campaign?: string;
|
|
15
|
-
utm_term?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type UTMParamsKeys = keyof UTMParams;
|
|
19
|
-
|
|
20
|
-
export type SourceDetailsCookie = {
|
|
21
|
-
platform_channel: Platform;
|
|
22
|
-
experiment_dict?: Experiments;
|
|
23
|
-
flow?: SignupFlow;
|
|
24
|
-
utm_params?: UTMParams;
|
|
25
|
-
affiliate_channel?: string;
|
|
26
|
-
offline_channel?: string;
|
|
27
|
-
performance_channel?: string;
|
|
28
|
-
revenue_channel: RevenueChannel;
|
|
29
|
-
organic_channel?: string;
|
|
30
|
-
flow_entry?: string;
|
|
31
|
-
first_page?: string;
|
|
32
|
-
last_page?: string;
|
|
33
|
-
guest_id?: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type SourceDetails = {
|
|
37
|
-
platform: Platform;
|
|
38
|
-
experiments?: Experiments;
|
|
39
|
-
flow?: SignupFlow;
|
|
40
|
-
utmParams?: UTMParams;
|
|
41
|
-
affiliateChannel?: string;
|
|
42
|
-
offlineChannel?: string;
|
|
43
|
-
performanceChannel?: string;
|
|
44
|
-
revenueChannel: RevenueChannel;
|
|
45
|
-
organicChannel?: string;
|
|
46
|
-
flowEntry?: string;
|
|
47
|
-
firstPage?: string;
|
|
48
|
-
lastPage?: string;
|
|
49
|
-
guestId?: string;
|
|
50
|
-
};
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { TWENTY_FOUR_HOURS_IN_SECONDS } from '../constants/date-time';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
export const LOCAL_STORAGE_PRIMARY_KEY = 'CUEMATH_WEB';
|
|
5
|
-
|
|
6
|
-
export const checkLocalStorageSupport = (): boolean => {
|
|
7
|
-
try {
|
|
8
|
-
return 'localStorage' in window && window.localStorage !== null;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const removeKeyFromObject = (
|
|
15
|
-
obj: { [x: string]: any },
|
|
16
|
-
keyToRemove: string,
|
|
17
|
-
): null | { [x: string]: any } => {
|
|
18
|
-
if (obj) {
|
|
19
|
-
delete obj[keyToRemove];
|
|
20
|
-
|
|
21
|
-
return obj;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Default expiry set to 24 hours
|
|
28
|
-
export const localStorageSet = (
|
|
29
|
-
key: string | number,
|
|
30
|
-
value: any,
|
|
31
|
-
ttl = TWENTY_FOUR_HOURS_IN_SECONDS,
|
|
32
|
-
): boolean => {
|
|
33
|
-
if (checkLocalStorageSupport()) {
|
|
34
|
-
try {
|
|
35
|
-
let dbData: any = window.localStorage.getItem(LOCAL_STORAGE_PRIMARY_KEY);
|
|
36
|
-
const now = new Date();
|
|
37
|
-
|
|
38
|
-
const item = {
|
|
39
|
-
value,
|
|
40
|
-
expiry: now.getTime() + ttl,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (dbData) {
|
|
44
|
-
dbData = JSON.parse(dbData);
|
|
45
|
-
dbData[key] = item;
|
|
46
|
-
} else {
|
|
47
|
-
dbData = { [key]: item };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
|
|
51
|
-
|
|
52
|
-
return true;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
return false;
|
|
55
|
-
} // case when localStorage space quota is exceeded
|
|
56
|
-
} else {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const localStorageGet = (key: string): null | string => {
|
|
62
|
-
if (checkLocalStorageSupport()) {
|
|
63
|
-
try {
|
|
64
|
-
const primaryLocalStorageValue = window.localStorage.getItem(
|
|
65
|
-
LOCAL_STORAGE_PRIMARY_KEY,
|
|
66
|
-
);
|
|
67
|
-
let dbData =
|
|
68
|
-
primaryLocalStorageValue != null
|
|
69
|
-
? JSON.parse(primaryLocalStorageValue)
|
|
70
|
-
: primaryLocalStorageValue;
|
|
71
|
-
const requestedData = dbData[key];
|
|
72
|
-
const now = new Date();
|
|
73
|
-
|
|
74
|
-
if (now.getTime() > requestedData.expiry) {
|
|
75
|
-
dbData = removeKeyFromObject(dbData, key);
|
|
76
|
-
window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
|
|
77
|
-
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return requestedData.value;
|
|
82
|
-
} catch (e) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const localStorageGetAll = (): null | string => {
|
|
91
|
-
if (checkLocalStorageSupport()) {
|
|
92
|
-
try {
|
|
93
|
-
const primaryLocalStorageValue = window.localStorage.getItem(
|
|
94
|
-
LOCAL_STORAGE_PRIMARY_KEY,
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return primaryLocalStorageValue != null
|
|
98
|
-
? JSON.parse(primaryLocalStorageValue)
|
|
99
|
-
: primaryLocalStorageValue;
|
|
100
|
-
} catch (e) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const localStorageRemove = (key: string): boolean => {
|
|
109
|
-
if (checkLocalStorageSupport()) {
|
|
110
|
-
try {
|
|
111
|
-
const primaryLocalStorageValue = window.localStorage.getItem(
|
|
112
|
-
LOCAL_STORAGE_PRIMARY_KEY,
|
|
113
|
-
);
|
|
114
|
-
let dbData =
|
|
115
|
-
primaryLocalStorageValue != null
|
|
116
|
-
? JSON.parse(primaryLocalStorageValue)
|
|
117
|
-
: primaryLocalStorageValue;
|
|
118
|
-
|
|
119
|
-
if (dbData[key]) {
|
|
120
|
-
dbData = removeKeyFromObject(dbData, key);
|
|
121
|
-
window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
|
|
122
|
-
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return false;
|
|
127
|
-
} catch (e) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const localStorageRemoveAll = (): boolean => {
|
|
136
|
-
if (checkLocalStorageSupport()) {
|
|
137
|
-
try {
|
|
138
|
-
const primaryLocalStorageValue = window.localStorage.getItem(
|
|
139
|
-
LOCAL_STORAGE_PRIMARY_KEY,
|
|
140
|
-
);
|
|
141
|
-
const dbData =
|
|
142
|
-
primaryLocalStorageValue != null
|
|
143
|
-
? JSON.parse(primaryLocalStorageValue)
|
|
144
|
-
: primaryLocalStorageValue;
|
|
145
|
-
|
|
146
|
-
if (dbData) {
|
|
147
|
-
window.localStorage.removeItem(LOCAL_STORAGE_PRIMARY_KEY);
|
|
148
|
-
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return false;
|
|
153
|
-
} catch (e) {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export const removeExpiredKeysOnMount = (): boolean => {
|
|
162
|
-
if (checkLocalStorageSupport()) {
|
|
163
|
-
try {
|
|
164
|
-
const primaryLocalStorageValue = window.localStorage.getItem(
|
|
165
|
-
LOCAL_STORAGE_PRIMARY_KEY,
|
|
166
|
-
);
|
|
167
|
-
let dbData =
|
|
168
|
-
primaryLocalStorageValue != null
|
|
169
|
-
? JSON.parse(primaryLocalStorageValue)
|
|
170
|
-
: primaryLocalStorageValue;
|
|
171
|
-
const now = new Date();
|
|
172
|
-
|
|
173
|
-
if (dbData) {
|
|
174
|
-
dbData = Object.keys(dbData).reduce((accumulator: any, key) => {
|
|
175
|
-
if (now.getTime() < dbData[key].expiry) {
|
|
176
|
-
accumulator[key] = dbData[key];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return accumulator;
|
|
180
|
-
}, {});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (Object.keys(dbData).length) {
|
|
184
|
-
window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
|
|
185
|
-
} else {
|
|
186
|
-
localStorageRemoveAll();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return true;
|
|
190
|
-
} catch (e) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
};
|
package/src/object/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function isEmpty(obj: object): boolean {
|
|
2
|
-
return Object.keys(obj).length === 0;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function nestedMapsAreEqual(map1: Map<any, any>, map2: Map<any, any>): boolean {
|
|
6
|
-
// First, check if the maps have the same size
|
|
7
|
-
if (map1.size !== map2.size) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Then, iterate over each key-value pair in map1 and check if the corresponding key-value pair exists in map2
|
|
12
|
-
for (const [key, value] of map1) {
|
|
13
|
-
if (!map2.has(key) || map2.get(key) !== value) {
|
|
14
|
-
// If the key doesn't exist in map2, or the value for the key is different, the maps are not equal
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// If we haven't returned false by now, the maps are equal
|
|
20
|
-
return true;
|
|
21
|
-
}
|
package/tsconfig.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|