@cuemath/web-utils 1.0.7-santosh.5 → 1.0.7-santosh.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/.eslintignore +2 -0
- package/.eslintrc.json +9 -0
- package/.husky/pre-commit +5 -0
- package/.huskyrc +5 -0
- package/.lintstagedrc.yml +1 -0
- package/.nvmrc +1 -0
- package/.prettierrc.json +1 -0
- package/.vscode/settings.json +1 -0
- package/package.json +1 -6
- package/src/constants/country/index.ts +1 -0
- package/src/constants/country/iso-country-code.ts +248 -0
- package/src/constants/date-time/index.ts +45 -0
- package/src/constants/date-time/international-timezones.ts +157 -0
- package/src/constants/index.ts +2 -0
- package/src/cookie/index.ts +59 -0
- package/src/date-time-helper/index.ts +139 -0
- package/src/e-cna/index.ts +23 -0
- package/src/growth-source/index.ts +235 -0
- package/src/growth-source/types.ts +50 -0
- package/src/index.ts +7 -0
- package/src/local-storage/index.ts +196 -0
- package/src/object/index.ts +21 -0
- package/tsconfig.esm.json +17 -0
- package/tsconfig.json +8 -0
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
package/.huskyrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ './**/*.js': ['prettier --write', 'eslint'] }
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v18.12.1
|
package/.prettierrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"@cuemath/prettier-config"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuemath/web-utils",
|
|
3
|
-
"version": "1.0.7-santosh.
|
|
3
|
+
"version": "1.0.7-santosh.8",
|
|
4
4
|
"description": "Shared web utils package",
|
|
5
|
-
"main": "dist/cjs/index.js",
|
|
6
|
-
"module": "dist/esm/index.js",
|
|
7
5
|
"types": "dist/types/index.d.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
"./growth-source": "./dist/cjs/growth-source/index.js",
|
|
@@ -13,9 +11,6 @@
|
|
|
13
11
|
"./growth-source": "./dist/esm/growth-source/index.js",
|
|
14
12
|
".": "./dist/esm/index.js"
|
|
15
13
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
14
|
"scripts": {
|
|
20
15
|
"lint": "tsc --noEmit && eslint 'src/**/*.{js,jsx,ts,tsx,json}'",
|
|
21
16
|
"build:cjs": "tsc --project tsconfig.json",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { COUNTRY_NAME_COUNTRY_CODE_MAP as ISO_COUNTRY_CODE } from './iso-country-code';
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
export const COUNTRY_NAME_COUNTRY_CODE_MAP = {
|
|
2
|
+
'AFGHANISTAN': 'AF',
|
|
3
|
+
'ALAND ISLANDS': 'AX',
|
|
4
|
+
'ALBANIA': 'AL',
|
|
5
|
+
'ALGERIA': 'DZ',
|
|
6
|
+
'AMERICAN SAMOA': 'AS',
|
|
7
|
+
'ANDORRA': 'AD',
|
|
8
|
+
'ANGOLA': 'AO',
|
|
9
|
+
'ANGUILLA': 'AI',
|
|
10
|
+
'ANTARCTICA': 'AQ',
|
|
11
|
+
'ANTIGUA AND BARBUDA': 'AG',
|
|
12
|
+
'ARGENTINA': 'AR',
|
|
13
|
+
'ARMENIA': 'AM',
|
|
14
|
+
'ARUBA': 'AW',
|
|
15
|
+
'AUSTRALIA': 'AU',
|
|
16
|
+
'AUSTRIA': 'AT',
|
|
17
|
+
'AZERBAIJAN': 'AZ',
|
|
18
|
+
'BAHAMAS': 'BS',
|
|
19
|
+
'BAHRAIN': 'BH',
|
|
20
|
+
'BANGLADESH': 'BD',
|
|
21
|
+
'BARBADOS': 'BB',
|
|
22
|
+
'BELARUS': 'BY',
|
|
23
|
+
'BELGIUM': 'BE',
|
|
24
|
+
'BELIZE': 'BZ',
|
|
25
|
+
'BENIN': 'BJ',
|
|
26
|
+
'BERMUDA': 'BM',
|
|
27
|
+
'BHUTAN': 'BT',
|
|
28
|
+
'BOLIVIA': 'BO',
|
|
29
|
+
'BOSNIA AND HERZEGOVINA': 'BA',
|
|
30
|
+
'BOTSWANA': 'BW',
|
|
31
|
+
'BOUVET ISLAND': 'BV',
|
|
32
|
+
'BRAZIL': 'BR',
|
|
33
|
+
'BRITISH INDIAN OCEAN TERRITORY': 'IO',
|
|
34
|
+
'BRUNEI DARUSSALAM': 'BN',
|
|
35
|
+
'BULGARIA': 'BG',
|
|
36
|
+
'BURKINA FASO': 'BF',
|
|
37
|
+
'BURUNDI': 'BI',
|
|
38
|
+
'CAMBODIA': 'KH',
|
|
39
|
+
'CAMEROON': 'CM',
|
|
40
|
+
'CANADA': 'CA',
|
|
41
|
+
'CAPE VERDE': 'CV',
|
|
42
|
+
'CAYMAN ISLANDS': 'KY',
|
|
43
|
+
'CENTRAL AFRICAN REPUBLIC': 'CF',
|
|
44
|
+
'CHAD': 'TD',
|
|
45
|
+
'CHILE': 'CL',
|
|
46
|
+
'CHINA': 'CN',
|
|
47
|
+
'CHRISTMAS ISLAND': 'CX',
|
|
48
|
+
'COCOS (KEELING) ISLANDS': 'CC',
|
|
49
|
+
'COLOMBIA': 'CO',
|
|
50
|
+
'COMOROS': 'KM',
|
|
51
|
+
'CONGO': 'CG',
|
|
52
|
+
'CONGO, DEMOCRATIC REPUBLIC': 'CD',
|
|
53
|
+
'COOK ISLANDS': 'CK',
|
|
54
|
+
'COSTA RICA': 'CR',
|
|
55
|
+
'COTE D"IVOIRE': 'CI',
|
|
56
|
+
'CROATIA': 'HR',
|
|
57
|
+
'CUBA': 'CU',
|
|
58
|
+
'CYPRUS': 'CY',
|
|
59
|
+
'CZECH REPUBLIC': 'CZ',
|
|
60
|
+
'DENMARK': 'DK',
|
|
61
|
+
'DJIBOUTI': 'DJ',
|
|
62
|
+
'DOMINICA': 'DM',
|
|
63
|
+
'DOMINICAN REPUBLIC': 'DO',
|
|
64
|
+
'ECUADOR': 'EC',
|
|
65
|
+
'EGYPT': 'EG',
|
|
66
|
+
'EL SALVADOR': 'SV',
|
|
67
|
+
'EQUATORIAL GUINEA': 'GQ',
|
|
68
|
+
'ERITREA': 'ER',
|
|
69
|
+
'ESTONIA': 'EE',
|
|
70
|
+
'ETHIOPIA': 'ET',
|
|
71
|
+
'FALKLAND ISLANDS (MALVINAS)': 'FK',
|
|
72
|
+
'FAROE ISLANDS': 'FO',
|
|
73
|
+
'FIJI': 'FJ',
|
|
74
|
+
'FINLAND': 'FI',
|
|
75
|
+
'FRANCE': 'FR',
|
|
76
|
+
'FRENCH GUIANA': 'GF',
|
|
77
|
+
'FRENCH POLYNESIA': 'PF',
|
|
78
|
+
'FRENCH SOUTHERN TERRITORIES': 'TF',
|
|
79
|
+
'GABON': 'GA',
|
|
80
|
+
'GAMBIA': 'GM',
|
|
81
|
+
'GEORGIA': 'GE',
|
|
82
|
+
'GERMANY': 'DE',
|
|
83
|
+
'GHANA': 'GH',
|
|
84
|
+
'GIBRALTAR': 'GI',
|
|
85
|
+
'GREECE': 'GR',
|
|
86
|
+
'GREENLAND': 'GL',
|
|
87
|
+
'GRENADA': 'GD',
|
|
88
|
+
'GUADELOUPE': 'GP',
|
|
89
|
+
'GUAM': 'GU',
|
|
90
|
+
'GUATEMALA': 'GT',
|
|
91
|
+
'GUERNSEY': 'GG',
|
|
92
|
+
'GUINEA': 'GN',
|
|
93
|
+
'GUINEA-BISSAU': 'GW',
|
|
94
|
+
'GUYANA': 'GY',
|
|
95
|
+
'HAITI': 'HT',
|
|
96
|
+
'HEARD ISLAND & MCDONALD ISLANDS': 'HM',
|
|
97
|
+
'HOLY SEE (VATICAN CITY STATE)': 'VA',
|
|
98
|
+
'HONDURAS': 'HN',
|
|
99
|
+
'HONG KONG': 'HK',
|
|
100
|
+
'HUNGARY': 'HU',
|
|
101
|
+
'ICELAND': 'IS',
|
|
102
|
+
'INDIA': 'IN',
|
|
103
|
+
'INDONESIA': 'ID',
|
|
104
|
+
'IRAN, ISLAMIC REPUBLIC OF': 'IR',
|
|
105
|
+
'IRAQ': 'IQ',
|
|
106
|
+
'IRELAND': 'IE',
|
|
107
|
+
'ISLE OF MAN': 'IM',
|
|
108
|
+
'ISRAEL': 'IL',
|
|
109
|
+
'ITALY': 'IT',
|
|
110
|
+
'JAMAICA': 'JM',
|
|
111
|
+
'JAPAN': 'JP',
|
|
112
|
+
'JERSEY': 'JE',
|
|
113
|
+
'JORDAN': 'JO',
|
|
114
|
+
'KAZAKHSTAN': 'KZ',
|
|
115
|
+
'KENYA': 'KE',
|
|
116
|
+
'KIRIBATI': 'KI',
|
|
117
|
+
'KOREA': 'KR',
|
|
118
|
+
'NORTH KOREA': 'KP',
|
|
119
|
+
'KUWAIT': 'KW',
|
|
120
|
+
'KYRGYZSTAN': 'KG',
|
|
121
|
+
'LAO PEOPLE"S DEMOCRATIC REPUBLIC': 'LA',
|
|
122
|
+
'LATVIA': 'LV',
|
|
123
|
+
'LEBANON': 'LB',
|
|
124
|
+
'LESOTHO': 'LS',
|
|
125
|
+
'LIBERIA': 'LR',
|
|
126
|
+
'LIBYAN ARAB JAMAHIRIYA': 'LY',
|
|
127
|
+
'LIECHTENSTEIN': 'LI',
|
|
128
|
+
'LITHUANIA': 'LT',
|
|
129
|
+
'LUXEMBOURG': 'LU',
|
|
130
|
+
'MACAO': 'MO',
|
|
131
|
+
'MACEDONIA': 'MK',
|
|
132
|
+
'MADAGASCAR': 'MG',
|
|
133
|
+
'MALAWI': 'MW',
|
|
134
|
+
'MALAYSIA': 'MY',
|
|
135
|
+
'MALDIVES': 'MV',
|
|
136
|
+
'MALI': 'ML',
|
|
137
|
+
'MALTA': 'MT',
|
|
138
|
+
'MARSHALL ISLANDS': 'MH',
|
|
139
|
+
'MARTINIQUE': 'MQ',
|
|
140
|
+
'MAURITANIA': 'MR',
|
|
141
|
+
'MAURITIUS': 'MU',
|
|
142
|
+
'MAYOTTE': 'YT',
|
|
143
|
+
'MEXICO': 'MX',
|
|
144
|
+
'MICRONESIA, FEDERATED STATES OF': 'FM',
|
|
145
|
+
'MOLDOVA': 'MD',
|
|
146
|
+
'MONACO': 'MC',
|
|
147
|
+
'MONGOLIA': 'MN',
|
|
148
|
+
'MONTENEGRO': 'ME',
|
|
149
|
+
'MONTSERRAT': 'MS',
|
|
150
|
+
'MOROCCO': 'MA',
|
|
151
|
+
'MOZAMBIQUE': 'MZ',
|
|
152
|
+
'MYANMAR': 'MM',
|
|
153
|
+
'NAMIBIA': 'NA',
|
|
154
|
+
'NAURU': 'NR',
|
|
155
|
+
'NEPAL': 'NP',
|
|
156
|
+
'NETHERLANDS': 'NL',
|
|
157
|
+
'NETHERLANDS ANTILLES': 'AN',
|
|
158
|
+
'NEW CALEDONIA': 'NC',
|
|
159
|
+
'NEW ZEALAND': 'NZ',
|
|
160
|
+
'NICARAGUA': 'NI',
|
|
161
|
+
'NIGER': 'NE',
|
|
162
|
+
'NIGERIA': 'NG',
|
|
163
|
+
'NIUE': 'NU',
|
|
164
|
+
'NORFOLK ISLAND': 'NF',
|
|
165
|
+
'NORTHERN MARIANA ISLANDS': 'MP',
|
|
166
|
+
'NORWAY': 'NO',
|
|
167
|
+
'OMAN': 'OM',
|
|
168
|
+
'PAKISTAN': 'PK',
|
|
169
|
+
'PALAU': 'PW',
|
|
170
|
+
'PALESTINIAN TERRITORY, OCCUPIED': 'PS',
|
|
171
|
+
'PANAMA': 'PA',
|
|
172
|
+
'PAPUA NEW GUINEA': 'PG',
|
|
173
|
+
'PARAGUAY': 'PY',
|
|
174
|
+
'PERU': 'PE',
|
|
175
|
+
'PHILIPPINES': 'PH',
|
|
176
|
+
'PITCAIRN': 'PN',
|
|
177
|
+
'POLAND': 'PL',
|
|
178
|
+
'PORTUGAL': 'PT',
|
|
179
|
+
'PUERTO RICO': 'PR',
|
|
180
|
+
'QATAR': 'QA',
|
|
181
|
+
'REUNION': 'RE',
|
|
182
|
+
'ROMANIA': 'RO',
|
|
183
|
+
'RUSSIAN FEDERATION': 'RU',
|
|
184
|
+
'RWANDA': 'RW',
|
|
185
|
+
'SAINT BARTHELEMY': 'BL',
|
|
186
|
+
'SAINT HELENA': 'SH',
|
|
187
|
+
'SAINT KITTS AND NEVIS': 'KN',
|
|
188
|
+
'SAINT LUCIA': 'LC',
|
|
189
|
+
'SAINT MARTIN': 'MF',
|
|
190
|
+
'SAINT PIERRE AND MIQUELON': 'PM',
|
|
191
|
+
'SAINT VINCENT AND GRENADINES': 'VC',
|
|
192
|
+
'SAMOA': 'WS',
|
|
193
|
+
'SAN MARINO': 'SM',
|
|
194
|
+
'SAO TOME AND PRINCIPE': 'ST',
|
|
195
|
+
'SAUDI ARABIA': 'SA',
|
|
196
|
+
'SENEGAL': 'SN',
|
|
197
|
+
'SERBIA': 'RS',
|
|
198
|
+
'SEYCHELLES': 'SC',
|
|
199
|
+
'SIERRA LEONE': 'SL',
|
|
200
|
+
'SINGAPORE': 'SG',
|
|
201
|
+
'SLOVAKIA': 'SK',
|
|
202
|
+
'SLOVENIA': 'SI',
|
|
203
|
+
'SOLOMON ISLANDS': 'SB',
|
|
204
|
+
'SOMALIA': 'SO',
|
|
205
|
+
'SOUTH AFRICA': 'ZA',
|
|
206
|
+
'SOUTH GEORGIA AND SANDWICH ISL.': 'GS',
|
|
207
|
+
'SPAIN': 'ES',
|
|
208
|
+
'SRI LANKA': 'LK',
|
|
209
|
+
'SUDAN': 'SD',
|
|
210
|
+
'SURINAME': 'SR',
|
|
211
|
+
'SVALBARD AND JAN MAYEN': 'SJ',
|
|
212
|
+
'SWAZILAND': 'SZ',
|
|
213
|
+
'SWEDEN': 'SE',
|
|
214
|
+
'SWITZERLAND': 'CH',
|
|
215
|
+
'SYRIAN ARAB REPUBLIC': 'SY',
|
|
216
|
+
'TAIWAN': 'TW',
|
|
217
|
+
'TAJIKISTAN': 'TJ',
|
|
218
|
+
'TANZANIA': 'TZ',
|
|
219
|
+
'THAILAND': 'TH',
|
|
220
|
+
'TIMOR-LESTE': 'TL',
|
|
221
|
+
'TOGO': 'TG',
|
|
222
|
+
'TOKELAU': 'TK',
|
|
223
|
+
'TONGA': 'TO',
|
|
224
|
+
'TRINIDAD AND TOBAGO': 'TT',
|
|
225
|
+
'TUNISIA': 'TN',
|
|
226
|
+
'TURKEY': 'TR',
|
|
227
|
+
'TURKMENISTAN': 'TM',
|
|
228
|
+
'TURKS AND CAICOS ISLANDS': 'TC',
|
|
229
|
+
'TUVALU': 'TV',
|
|
230
|
+
'UGANDA': 'UG',
|
|
231
|
+
'UKRAINE': 'UA',
|
|
232
|
+
'UNITED ARAB EMIRATES': 'AE',
|
|
233
|
+
'UNITED KINGDOM': 'GB',
|
|
234
|
+
'UNITED STATES': 'US',
|
|
235
|
+
'UNITED STATES OUTLYING ISLANDS': 'UM',
|
|
236
|
+
'URUGUAY': 'UY',
|
|
237
|
+
'UZBEKISTAN': 'UZ',
|
|
238
|
+
'VANUATU': 'VU',
|
|
239
|
+
'VENEZUELA': 'VE',
|
|
240
|
+
'VIETNAM': 'VN',
|
|
241
|
+
'VIRGIN ISLANDS, BRITISH': 'VG',
|
|
242
|
+
'VIRGIN ISLANDS, U.S.': 'VI',
|
|
243
|
+
'WALLIS AND FUTUNA': 'WF',
|
|
244
|
+
'WESTERN SAHARA': 'EH',
|
|
245
|
+
'YEMEN': 'YE',
|
|
246
|
+
'ZAMBIA': 'ZM',
|
|
247
|
+
'ZIMBABWE': 'ZW',
|
|
248
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { timezones } from './international-timezones';
|
|
2
|
+
|
|
3
|
+
export const DAY = {
|
|
4
|
+
Sun: 'Sunday',
|
|
5
|
+
Mon: 'Monday',
|
|
6
|
+
Tue: 'Tuesday',
|
|
7
|
+
Wed: 'Wednesday',
|
|
8
|
+
Thu: 'Thursday',
|
|
9
|
+
Fri: 'Friday',
|
|
10
|
+
Sat: 'Saturday',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const shorthandWeekDayArray = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
|
|
14
|
+
|
|
15
|
+
export const MONTH_ARRAY = [
|
|
16
|
+
'Jan',
|
|
17
|
+
'Feb',
|
|
18
|
+
'Mar',
|
|
19
|
+
'Apr',
|
|
20
|
+
'May',
|
|
21
|
+
'Jun',
|
|
22
|
+
'Jul',
|
|
23
|
+
'Aug',
|
|
24
|
+
'Sept',
|
|
25
|
+
'Oct',
|
|
26
|
+
'Nov',
|
|
27
|
+
'Dec',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export const weekDayArray: string[] = [
|
|
31
|
+
'Sunday',
|
|
32
|
+
'Monday',
|
|
33
|
+
'Tuesday',
|
|
34
|
+
'Wednesday',
|
|
35
|
+
'Thursday',
|
|
36
|
+
'Friday',
|
|
37
|
+
'Saturday',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export const TWENTY_FOUR_HOURS_IN_SECONDS: number = 24 * 60 * 60; // 86400
|
|
41
|
+
|
|
42
|
+
export const HOUR_FORMAT = {
|
|
43
|
+
TWELVE_HOUR_FORMAT: 12,
|
|
44
|
+
TWENTY_FOUR_HOUR_FORMAT: 24,
|
|
45
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
interface Timezone {
|
|
2
|
+
id: string;
|
|
3
|
+
value: string;
|
|
4
|
+
meta: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const timezones: Timezone[] = [
|
|
8
|
+
{
|
|
9
|
+
id: 'Pacific/Honolulu',
|
|
10
|
+
value: 'HST(GMT-10)',
|
|
11
|
+
meta: 'HST(GMT-10)',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: 'America/Anchorage',
|
|
15
|
+
value: 'AST(GMT-9)',
|
|
16
|
+
meta: 'AST(GMT-9)',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'America/Los_Angeles',
|
|
20
|
+
value: 'PST(GMT-8)',
|
|
21
|
+
meta: 'PST(GMT-8)',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'America/Denver',
|
|
25
|
+
value: 'MST(GMT-7)',
|
|
26
|
+
meta: 'MST(GMT-7)',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'America/Phoenix',
|
|
30
|
+
value: 'MST(GMT-7)',
|
|
31
|
+
meta: 'MST(GMT-7)',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'America/Matamoros',
|
|
35
|
+
value: 'CST(GMT-6)',
|
|
36
|
+
meta: 'CST(GMT-6)',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'America/New_York',
|
|
40
|
+
value: 'EST(GMT-5)',
|
|
41
|
+
meta: 'EST(GMT-5)',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'America/Glace_Bay',
|
|
45
|
+
value: 'AST(GMT-4)',
|
|
46
|
+
meta: 'AST(GMT-4)',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'America/St_Johns',
|
|
50
|
+
value: 'NST(GMT-3:30)',
|
|
51
|
+
meta: 'NST(GMT-3:30)',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: 'America/Noronha',
|
|
55
|
+
value: 'FNT(GMT-2)',
|
|
56
|
+
meta: 'FNT(GMT-2)',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'Asia/Calcutta',
|
|
60
|
+
value: 'IST(GMT+5:30)',
|
|
61
|
+
meta: 'IST(GMT+5:30)',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'Asia/Kolkata',
|
|
65
|
+
value: 'IST(GMT+5:30)',
|
|
66
|
+
meta: 'IST(GMT+5:30)',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: 'Asia/Dubai',
|
|
70
|
+
value: 'GST(GMT+4)',
|
|
71
|
+
meta: 'GST(GMT+4)',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'Asia/Singapore',
|
|
75
|
+
value: 'SGT(GMT+8)',
|
|
76
|
+
meta: 'SGT(GMT+8)',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'Pacific/Auckland',
|
|
80
|
+
value: 'NZDT(GMT+13)',
|
|
81
|
+
meta: 'NZDT(GMT+13)',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'Australia/Adelaide',
|
|
85
|
+
value: 'ACDT(GMT+10:30)',
|
|
86
|
+
meta: 'ACDT(GMT+10:30)',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 'Australia/Perth',
|
|
90
|
+
value: 'AWST(GMT+8)',
|
|
91
|
+
meta: 'AWST(GMT+8)',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'Australia/Sydney',
|
|
95
|
+
value: 'AEDT(GMT+11)',
|
|
96
|
+
meta: 'AEDT(GMT+11)',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 'Australia/Darwin',
|
|
100
|
+
value: 'ACST(GMT+9:30)',
|
|
101
|
+
meta: 'ACST(GMT+9:30)',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: 'Australia/Broken_Hill',
|
|
105
|
+
value: 'ACDT(GMT+10:30)',
|
|
106
|
+
meta: 'ACDT(GMT+10:30)',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'Australia/Melbourne',
|
|
110
|
+
value: 'AEDT(GMT+11)',
|
|
111
|
+
meta: 'AEDT(GMT+11)',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: 'Australia/Brisbane',
|
|
115
|
+
value: 'AEST(GMT+10)',
|
|
116
|
+
meta: 'AEST(GMT+10)',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: 'Australia/Hobart',
|
|
120
|
+
value: 'AEDT(GMT+11)',
|
|
121
|
+
meta: 'AEDT(GMT+11)',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'Europe/London',
|
|
125
|
+
value: 'GMT(GMT+0)',
|
|
126
|
+
meta: 'GMT(GMT+0)',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: 'Asia/Muscat',
|
|
130
|
+
value: 'GST(GMT+4)',
|
|
131
|
+
meta: 'GST(GMT+4)',
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
id: 'Asia/Kuwait',
|
|
135
|
+
value: 'AST(GMT+3)',
|
|
136
|
+
meta: 'AST(GMT+3)',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 'Asia/Bahrain',
|
|
140
|
+
value: 'AST(GMT+3)',
|
|
141
|
+
meta: 'AST(GMT+3)',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: 'Asia/Qatar',
|
|
145
|
+
value: 'AST(GMT+3)',
|
|
146
|
+
meta: 'AST(GMT+3)',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'Asia/Riyadh',
|
|
150
|
+
value: 'AST(GMT+3)',
|
|
151
|
+
meta: 'AST(GMT+3)',
|
|
152
|
+
},
|
|
153
|
+
].map(timezone => ({
|
|
154
|
+
...timezone,
|
|
155
|
+
key: timezone.id,
|
|
156
|
+
label: timezone.meta,
|
|
157
|
+
}));
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export const getCookie = (name: string, cookie: string = document.cookie): string => {
|
|
2
|
+
if (!cookie) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const cookies = cookie.split('; ');
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < cookies.length; i += 1) {
|
|
9
|
+
if (cookies[i]) {
|
|
10
|
+
const [key, value] = cookies[i].split('=');
|
|
11
|
+
|
|
12
|
+
if (key === name) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return '';
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function removeCookie(name: string, subdomain?: boolean): void {
|
|
22
|
+
const date = new Date();
|
|
23
|
+
|
|
24
|
+
// Set it expire in -1 days
|
|
25
|
+
date.setTime(date.getTime() + -1 * 24 * 60 * 60 * 1000);
|
|
26
|
+
|
|
27
|
+
// Set it
|
|
28
|
+
document.cookie = `${name}=; expires=${date.toUTCString()}; path=/${
|
|
29
|
+
subdomain ? '; domain=cuemath.com' : ''
|
|
30
|
+
}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createCookie(
|
|
34
|
+
name: string,
|
|
35
|
+
value: string,
|
|
36
|
+
days: number,
|
|
37
|
+
subdomain?: boolean,
|
|
38
|
+
): void {
|
|
39
|
+
let expires = '';
|
|
40
|
+
|
|
41
|
+
if (days) {
|
|
42
|
+
const date = new Date();
|
|
43
|
+
|
|
44
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
45
|
+
expires = `; expires=${date.toUTCString()}`;
|
|
46
|
+
}
|
|
47
|
+
document.cookie = `${name}=${encodeURIComponent(value)}${expires}; path=/${
|
|
48
|
+
subdomain ? '; domain=cuemath.com' : ''
|
|
49
|
+
}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createCookieWithMidnightExp(name: string, value: string): void {
|
|
53
|
+
const date = new Date();
|
|
54
|
+
|
|
55
|
+
date.setHours(24, 0, 0, 0);
|
|
56
|
+
const expires = `; expires=${date}`;
|
|
57
|
+
|
|
58
|
+
document.cookie = `${name}=${value}${expires}; path=/`;
|
|
59
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
4
|
+
|
|
5
|
+
import { timezones } from '../constants/date-time/international-timezones';
|
|
6
|
+
|
|
7
|
+
type Timestamp = number;
|
|
8
|
+
|
|
9
|
+
export interface DateSlots {
|
|
10
|
+
key: number;
|
|
11
|
+
label: string;
|
|
12
|
+
subLabel: string;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const formatDateTime = (
|
|
17
|
+
dateTime: string | number | Date | dayjs.Dayjs | null | undefined,
|
|
18
|
+
format: string | undefined,
|
|
19
|
+
) => {
|
|
20
|
+
const momentDate = dayjs(dateTime);
|
|
21
|
+
|
|
22
|
+
return momentDate.format(format);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function getCurrentTimestamp(): number {
|
|
26
|
+
if (!Date.now) {
|
|
27
|
+
Date.now = () => new Date().getTime();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Math.floor(Date.now() / 1000);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function dateTimeByTimezone(timestamp: Timestamp, timezone?: string): string {
|
|
34
|
+
let options = {};
|
|
35
|
+
|
|
36
|
+
if (timezone) {
|
|
37
|
+
options = {
|
|
38
|
+
timeZone: timezone,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return new Date(timestamp).toLocaleString('en-US', options);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function dateByTimezone(
|
|
46
|
+
timestamp: number,
|
|
47
|
+
timezone: string,
|
|
48
|
+
format: string,
|
|
49
|
+
): string {
|
|
50
|
+
const datetime = dateTimeByTimezone(timestamp, timezone);
|
|
51
|
+
|
|
52
|
+
return dayjs(datetime).format(format || 'mm/dd/yyyy');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const dateByTimestamp = (timestamp: Timestamp, format: string): string => {
|
|
56
|
+
const datetime = new Date(timestamp).toLocaleString('en-US');
|
|
57
|
+
|
|
58
|
+
return dayjs(datetime).format(format || 'mm/dd/yyyy');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function convertTimeStampToSeconds(timeStamp: Timestamp): number {
|
|
62
|
+
const demoTimeStamp = timeStamp;
|
|
63
|
+
const currentTimeStamp = getCurrentTimestamp();
|
|
64
|
+
|
|
65
|
+
if (Number.isNaN(demoTimeStamp) || Number.isNaN(currentTimeStamp)) {
|
|
66
|
+
return timeStamp;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const demoTimeStampLength = String(demoTimeStamp).length;
|
|
70
|
+
const currentTimeStampLength = String(currentTimeStamp).length;
|
|
71
|
+
|
|
72
|
+
return demoTimeStampLength > currentTimeStampLength ? timeStamp / 1000 : timeStamp;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function formatTimestamp(datetime: Timestamp, format: string | undefined): string {
|
|
76
|
+
const timeStamp = convertTimeStampToSeconds(datetime);
|
|
77
|
+
|
|
78
|
+
return dayjs.unix(timeStamp).format(format);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getTimezone(): string {
|
|
82
|
+
return Intl?.DateTimeFormat().resolvedOptions().timeZone;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function timeToX(
|
|
86
|
+
datetime: string | number | Date | dayjs.Dayjs | null | undefined,
|
|
87
|
+
): string {
|
|
88
|
+
dayjs.extend(relativeTime);
|
|
89
|
+
|
|
90
|
+
return dayjs().to(datetime, true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getCurrentDatebyTimezone(timezone: string): string {
|
|
94
|
+
let options = {};
|
|
95
|
+
|
|
96
|
+
if (timezone) {
|
|
97
|
+
options = {
|
|
98
|
+
timeZone: timezone,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return new Date().toLocaleString('en-US', options);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function getTimeDiff(
|
|
106
|
+
date1: string | number | Date | dayjs.Dayjs | null | undefined,
|
|
107
|
+
date2: string | number | Date | dayjs.Dayjs | null | undefined,
|
|
108
|
+
): { days: any; hour: any; minute: any; seconds: any; distance: any } {
|
|
109
|
+
const dateTime1 = dayjs(date1);
|
|
110
|
+
const dateTime2 = dayjs(date2);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
days: dateTime1.diff(dateTime2, 'days'),
|
|
114
|
+
hour: dateTime1.diff(dateTime2, 'hour'),
|
|
115
|
+
minute: dateTime1.diff(dateTime2, 'minute'),
|
|
116
|
+
seconds: dateTime1.diff(dateTime2, 'seconds'),
|
|
117
|
+
distance: dateTime1.diff(dateTime2),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function getISOTimeString(demoTs: number): string {
|
|
122
|
+
return new Date(demoTs * 1000).toISOString().replace(/-|:|\.\d\d\d/g, '');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function getDateAfterDays(days: number): string {
|
|
126
|
+
return formatDateTime(dayjs().add(days, 'day'), 'D MMM, YYYY').toUpperCase();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const convertedTimezone = (selectedTimezone: string): string => {
|
|
130
|
+
const formattedTimezone = timezones?.find(
|
|
131
|
+
currentTimezone => currentTimezone?.id === selectedTimezone,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return formattedTimezone?.value ?? selectedTimezone?.replace(/_/g, ' ');
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const convertSecondsToMiliseconds = (seconds: number) => {
|
|
138
|
+
return seconds * 1000;
|
|
139
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TWENTY_FOUR_HOURS_IN_SECONDS } from '../constants/date-time';
|
|
2
|
+
import { getCurrentDatebyTimezone } from '../date-time-helper/index';
|
|
3
|
+
|
|
4
|
+
// if adding any change in this function, then need update at all the places where we are using this function in website and astro
|
|
5
|
+
export const getDates = (
|
|
6
|
+
timezone: string,
|
|
7
|
+
): Array<{ futureDate: number; disabled: boolean }> => {
|
|
8
|
+
const currentDate = Date.parse(getCurrentDatebyTimezone(timezone)) / 1000;
|
|
9
|
+
const dates = [];
|
|
10
|
+
|
|
11
|
+
const days = 10;
|
|
12
|
+
const buffer = 2;
|
|
13
|
+
|
|
14
|
+
// getting dates by adding 86400 seconds(24 hours)
|
|
15
|
+
for (let i = 0; i < days; i += 1) {
|
|
16
|
+
dates.push({
|
|
17
|
+
futureDate: currentDate + TWENTY_FOUR_HOURS_IN_SECONDS * i,
|
|
18
|
+
disabled: !(i > buffer),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return dates;
|
|
23
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
} else if (platform === 'astro') {
|
|
55
|
+
revenueChannel = 'performance';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (utmSource) {
|
|
59
|
+
switch (true) {
|
|
60
|
+
case /^affiliate-/.test(utmSource):
|
|
61
|
+
revenueChannel = 'affiliate';
|
|
62
|
+
break;
|
|
63
|
+
case /^offline-/.test(utmSource):
|
|
64
|
+
revenueChannel = 'offline';
|
|
65
|
+
break;
|
|
66
|
+
case /^referral-/.test(utmSource):
|
|
67
|
+
revenueChannel = 'referral';
|
|
68
|
+
break;
|
|
69
|
+
case /^performance-/.test(utmSource):
|
|
70
|
+
revenueChannel = 'performance';
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return revenueChannel;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
if Platform = website, then decide based on experiment key
|
|
80
|
+
if Platform = Astro, decide logic once BAU is started
|
|
81
|
+
if Platform = APP, decide logic
|
|
82
|
+
if Platform = chatbot, decide based on chatbot experiment key
|
|
83
|
+
*/
|
|
84
|
+
const getFlow = (platform: Platform, experiments?: Experiments): SignupFlow => {
|
|
85
|
+
let flow: SignupFlow = 'regular';
|
|
86
|
+
|
|
87
|
+
if (platform === 'website') {
|
|
88
|
+
if (experiments) {
|
|
89
|
+
const ecnaExp = Object.keys(experiments).find(
|
|
90
|
+
experiment => experiment.indexOf('ecna') !== -1,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
flow = ecnaExp && experiments[ecnaExp] === 'b' ? 'e-cna' : 'regular';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return flow;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const getUTMParams = (): Partial<UTMParams> => {
|
|
101
|
+
if (typeof window === undefined) return {};
|
|
102
|
+
|
|
103
|
+
const search = new URLSearchParams(window.location.search);
|
|
104
|
+
const utmParams = UTM_PARAMS.reduce((acc: UTMParams, param) => {
|
|
105
|
+
const utmParam = search.get(param) as string;
|
|
106
|
+
|
|
107
|
+
if (utmParam) {
|
|
108
|
+
acc[param] = utmParam;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return acc;
|
|
112
|
+
}, {});
|
|
113
|
+
|
|
114
|
+
return utmParams;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const getFirstPage = (): string => {
|
|
118
|
+
if (typeof window === undefined) return '';
|
|
119
|
+
|
|
120
|
+
return window.location.pathname;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/* TODO: Align Marketing Team on UTM source convention
|
|
124
|
+
affiliate-<channel>
|
|
125
|
+
performance-<channel>
|
|
126
|
+
organic-<channel>
|
|
127
|
+
offline-<channel>
|
|
128
|
+
*/
|
|
129
|
+
const getChannel = (utmSource?: string): string => {
|
|
130
|
+
// TODO: UTM source patter for FB, GOOGLE...
|
|
131
|
+
if (!utmSource) return '';
|
|
132
|
+
|
|
133
|
+
let channel = '';
|
|
134
|
+
|
|
135
|
+
if (utmSource) {
|
|
136
|
+
switch (true) {
|
|
137
|
+
case /^affiliate-/.test(utmSource):
|
|
138
|
+
case /^offline-/.test(utmSource):
|
|
139
|
+
case /^referral-/.test(utmSource):
|
|
140
|
+
case /^performance-/.test(utmSource):
|
|
141
|
+
channel = utmSource.split('-')[1];
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return channel;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/*
|
|
152
|
+
Set Static Source Details of user on Visit of Platform
|
|
153
|
+
*/
|
|
154
|
+
export const initSourceDetails = async ({
|
|
155
|
+
platform,
|
|
156
|
+
experiments,
|
|
157
|
+
flow,
|
|
158
|
+
affiliateChannel,
|
|
159
|
+
offlineChannel,
|
|
160
|
+
organicChannel,
|
|
161
|
+
performanceChannel,
|
|
162
|
+
revenueChannel,
|
|
163
|
+
guestId,
|
|
164
|
+
}: SourceDetails): Promise<void> => {
|
|
165
|
+
const utmParams: Partial<UTMParams> = getUTMParams();
|
|
166
|
+
const { utm_source: utmSource } = utmParams;
|
|
167
|
+
const leadChannel = getChannel(utmSource);
|
|
168
|
+
|
|
169
|
+
/*
|
|
170
|
+
source cookie was added in cross subdomain for few days initially,
|
|
171
|
+
which was later changed to subdomain specific. Now to sending older cookie to backend, removing older cookie
|
|
172
|
+
*/
|
|
173
|
+
removeCookie(SOURCE_DETAILS_COOKIE, true);
|
|
174
|
+
|
|
175
|
+
revenueChannel = revenueChannel || getRevenueChannel(platform, utmSource);
|
|
176
|
+
|
|
177
|
+
if (utmSource) {
|
|
178
|
+
affiliateChannel =
|
|
179
|
+
revenueChannel === 'affiliate' ? affiliateChannel || leadChannel : undefined;
|
|
180
|
+
offlineChannel =
|
|
181
|
+
revenueChannel === 'offline' ? offlineChannel || leadChannel : undefined;
|
|
182
|
+
organicChannel =
|
|
183
|
+
revenueChannel === 'organic' ? organicChannel || leadChannel : undefined;
|
|
184
|
+
performanceChannel =
|
|
185
|
+
revenueChannel === 'performance' ? performanceChannel || leadChannel : undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!isSourcePresent()) {
|
|
189
|
+
const sourceDetails: SourceDetailsCookie = {
|
|
190
|
+
platform_channel: platform,
|
|
191
|
+
experiment_dict: experiments,
|
|
192
|
+
utm_params: utmParams,
|
|
193
|
+
flow: flow || getFlow(platform, experiments),
|
|
194
|
+
affiliate_channel: affiliateChannel,
|
|
195
|
+
offline_channel: offlineChannel,
|
|
196
|
+
organic_channel: organicChannel,
|
|
197
|
+
performance_channel: performanceChannel,
|
|
198
|
+
revenue_channel: revenueChannel,
|
|
199
|
+
first_page: getFirstPage(),
|
|
200
|
+
guest_id: guestId,
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
writeSourceCookie(sourceDetails);
|
|
204
|
+
} else {
|
|
205
|
+
let updatedSource: Partial<SourceDetailsCookie> = {
|
|
206
|
+
experiment_dict: experiments,
|
|
207
|
+
flow: flow || getFlow(platform, experiments),
|
|
208
|
+
guest_id: guestId,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (utmSource) {
|
|
212
|
+
updatedSource = {
|
|
213
|
+
...updatedSource,
|
|
214
|
+
utm_params: utmParams,
|
|
215
|
+
affiliate_channel: affiliateChannel,
|
|
216
|
+
offline_channel: offlineChannel,
|
|
217
|
+
organic_channel: organicChannel,
|
|
218
|
+
performance_channel: performanceChannel,
|
|
219
|
+
revenue_channel: revenueChannel,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
updateSourceCookie(updatedSource);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// Last Page which user visited signup before
|
|
228
|
+
export const setLastPage = async (pagePath: string): Promise<void> => {
|
|
229
|
+
updateSourceCookie({ last_page: pagePath });
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// set Entry point where user clicked to Signup
|
|
233
|
+
export const setFlowEntryPoint = async (flowEntry: string): Promise<void> => {
|
|
234
|
+
updateSourceCookie({ flow_entry: flowEntry });
|
|
235
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@cuemath/ts-config/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2015",
|
|
5
|
+
"module": "es6",
|
|
6
|
+
"outDir": "dist/esm",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"baseUrl": ".",
|
|
11
|
+
"paths": {
|
|
12
|
+
"growth-source": ["./src/growth-source"],
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["node_modules"]
|
|
17
|
+
}
|