@cuemath/web-utils 0.0.1-beta.5 → 0.0.1

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 (59) hide show
  1. package/.husky/pre-commit +0 -1
  2. package/.vscode/settings.json +1 -0
  3. package/dist/index.js +0 -6
  4. package/package.json +5 -22
  5. package/src/cookie/index.ts +1 -33
  6. package/src/index.ts +0 -6
  7. package/.eslintignore +0 -2
  8. package/.huskyrc +0 -5
  9. package/.lintstagedrc.yml +0 -5
  10. package/src/constants/country/index.ts +0 -2
  11. package/src/constants/country/iso-country-code.ts +0 -248
  12. package/src/constants/date-time/index.ts +0 -43
  13. package/src/constants/date-time/international-timezones.ts +0 -157
  14. package/src/constants/e-cna/index.ts +0 -45
  15. package/src/constants/index.ts +0 -2
  16. package/src/country/index.ts +0 -9
  17. package/src/date-time-helper/e-cna.ts +0 -205
  18. package/src/date-time-helper/index.ts +0 -365
  19. package/src/e-cna/flow/aggregator.ts +0 -12
  20. package/src/e-cna/flow/index.ts +0 -1
  21. package/src/e-cna/flow/variants/default.ts +0 -42
  22. package/src/e-cna/flow/variants/index.ts +0 -1
  23. package/src/e-cna/index.ts +0 -249
  24. package/src/e-cna/slides/child_hobbies/index.ts +0 -1
  25. package/src/e-cna/slides/child_hobbies/variants.ts +0 -13
  26. package/src/e-cna/slides/child_personality/index.ts +0 -1
  27. package/src/e-cna/slides/child_personality/variants.ts +0 -12
  28. package/src/e-cna/slides/curriculum/index.ts +0 -1
  29. package/src/e-cna/slides/curriculum/variants.ts +0 -14
  30. package/src/e-cna/slides/grade/index.ts +0 -1
  31. package/src/e-cna/slides/grade/variants.ts +0 -29
  32. package/src/e-cna/slides/index.ts +0 -17
  33. package/src/e-cna/slides/intro/index.ts +0 -1
  34. package/src/e-cna/slides/intro/variants.ts +0 -7
  35. package/src/e-cna/slides/key_need_l1/index.ts +0 -1
  36. package/src/e-cna/slides/key_need_l1/variants.ts +0 -44
  37. package/src/e-cna/slides/key_need_l2/index.ts +0 -1
  38. package/src/e-cna/slides/key_need_l2/variants.ts +0 -143
  39. package/src/e-cna/slides/key_need_l3/index.ts +0 -1
  40. package/src/e-cna/slides/key_need_l3/variants.ts +0 -13
  41. package/src/e-cna/slides/math-perception/index.ts +0 -1
  42. package/src/e-cna/slides/math-perception/variants.ts +0 -30
  43. package/src/e-cna/slides/other_curriculum/index.ts +0 -1
  44. package/src/e-cna/slides/other_curriculum/variants.ts +0 -14
  45. package/src/e-cna/slides/school_performance_5_12/index.ts +0 -1
  46. package/src/e-cna/slides/school_performance_5_12/variants.ts +0 -23
  47. package/src/e-cna/slides/school_performance_kg_4/index.ts +0 -1
  48. package/src/e-cna/slides/school_performance_kg_4/variants.ts +0 -25
  49. package/src/e-cna/slides/secondary_needs/index.ts +0 -1
  50. package/src/e-cna/slides/secondary_needs/variants.ts +0 -26
  51. package/src/e-cna/slides/signup/index.ts +0 -1
  52. package/src/e-cna/slides/signup/variants.ts +0 -7
  53. package/src/e-cna/slides/signup_refer/index.ts +0 -1
  54. package/src/e-cna/slides/signup_refer/variants.ts +0 -16
  55. package/src/e-cna/slides/slot_pick/index.ts +0 -1
  56. package/src/e-cna/slides/slot_pick/variants.ts +0 -7
  57. package/src/e-cna/utils/index.ts +0 -32
  58. package/src/local-storage/index.ts +0 -186
  59. package/src/object/index.ts +0 -26
@@ -1,25 +0,0 @@
1
- export const school_performance_kg_4 = {
2
- DEFAULT: {
3
- id: 4,
4
- questionID: 'school_performance_kg_4',
5
- type: 'options_thin',
6
- question: "What does your child's teacher say about math performance at school?",
7
- options: [
8
- {
9
- value: "Can improve. You've got potential.",
10
- logo: '/static/e-cna-form/one-star.svg',
11
- },
12
- {
13
- value: 'Pretty good but you can do even better',
14
- logo: '/static/e-cna-form/two-stars.svg',
15
- },
16
- {
17
- value: "Awesome job! You're on track!",
18
- logo: '/static/e-cna-form/three-stars.svg',
19
- },
20
- ],
21
-
22
- defaultNextquestionID: 'key_need_l1',
23
- questionUUID: 'a3fdfdf8-6d34-42b9-8bbe-d9568b797881',
24
- },
25
- };
@@ -1 +0,0 @@
1
- export * from './variants';
@@ -1,26 +0,0 @@
1
- const getSecondaryKeyNeeds = () => [
2
- {
3
- value:
4
- "I'd like them to build strong math foundation and get support for schoolwork.",
5
- },
6
- { value: "I'd like them to be faster at calculations / Mental math." },
7
- { value: "I'd like them to bridge learning gaps from previous and current grades." },
8
- { value: 'I want my child to practice math regulalry.' },
9
- { value: "I'd like them to develop interest and start enjoying math without fear." },
10
- { value: 'I want my child to practice advanced and competitive math.' },
11
- ];
12
-
13
- export const secondary_needs = {
14
- DEFAULT: {
15
- id: 13,
16
- questionID: 'secondary_needs',
17
- type: 'options_multiselect',
18
- question: 'Is there anything else we should focus on?',
19
- description: 'You can select more than 1.',
20
- get options() {
21
- return getSecondaryKeyNeeds();
22
- },
23
- defaultNextquestionID: 'child_personality',
24
- questionUUID: '4e1830f2-d37d-4c6f-9e56-1bd1e6660984',
25
- },
26
- };
@@ -1 +0,0 @@
1
- export * from './variants';
@@ -1,7 +0,0 @@
1
- export const signup = {
2
- DEFAULT: {
3
- id: 'parent_student_details',
4
- questionID: 'demo',
5
- nextSlide: 'parent_student_details',
6
- },
7
- };
@@ -1 +0,0 @@
1
- export * from './variants';
@@ -1,16 +0,0 @@
1
- export const signup_refer = {
2
- DEFAULT: {
3
- id: 16,
4
- questionID: 'signup_refer',
5
- type: 'options',
6
- question: 'How did you learn about Cuemath?',
7
- options: [
8
- { value: 'Friends/Family' },
9
- { value: 'Online Search' },
10
- { value: 'Social Media' },
11
- { value: 'App Store/Play Store' },
12
- { value: 'Others' },
13
- ],
14
- questionUUID: 'ea8f4ed7-4214-4dcd-a818-701bf1843626',
15
- },
16
- };
@@ -1 +0,0 @@
1
- export * from './variants';
@@ -1,7 +0,0 @@
1
- export const slot_pick = {
2
- DEFAULT: {
3
- id: 'slot_pick',
4
- questionID: 'demo',
5
- nextSlide: 'parent_student_details',
6
- },
7
- };
@@ -1,32 +0,0 @@
1
- import { getCookie } from '../../cookie';
2
- import { localStorageGet } from '../../local-storage';
3
- import { SLIDE_TYPES, CUE_COUNTRY_CODE_KEY, LOCAL_STORAGE_KEYS } from '../../constants';
4
-
5
- const K6Countries = ['AU', 'NZ']
6
-
7
- export function checkGradeCountry(
8
- country: string[],
9
- currentGrade: string,
10
- lessThanGrade: number,
11
- ): boolean {
12
- if (
13
- country.includes(getCookie(CUE_COUNTRY_CODE_KEY)) &&
14
- (parseInt(currentGrade, 10) <= lessThanGrade || currentGrade === 'KG')
15
- ) {
16
- return true;
17
- }
18
-
19
- return false;
20
- }
21
-
22
- export function isK4Student() {
23
- return checkGradeCountry(K6Countries, localStorageGet(LOCAL_STORAGE_KEYS.STUDENT_GRADE), 4);
24
- }
25
-
26
- export function isK6Student() {
27
- return checkGradeCountry(K6Countries, localStorageGet(LOCAL_STORAGE_KEYS.STUDENT_GRADE), 6);
28
- }
29
-
30
- export function getPerformanceQuestionAccordingToGrade() {
31
- return isK4Student() ? SLIDE_TYPES.SCHOOL_PERFORMANCE_KG_4 : SLIDE_TYPES.SCHOOL_PERFORMANCE_5_12;
32
- }
@@ -1,186 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export const LOCAL_STORAGE_PRIMARY_KEY = 'CUEMATH_WEB';
3
-
4
- export const checkLocalStorageSupport = () : boolean => {
5
- try {
6
- return 'localStorage' in window && window.localStorage !== null;
7
- } catch (e) {
8
- return false;
9
- }
10
- };
11
-
12
- export const removeKeyFromObject = (obj: { [x: string]: any }, keyToRemove: string) => {
13
- if (obj) {
14
- delete obj[keyToRemove];
15
- return obj
16
- }
17
-
18
- return null;
19
- };
20
-
21
- // Default expiry set to 24 hours
22
- export const localStorageSet = (key: string | number, value: any, ttl = 86400000) => {
23
- if (checkLocalStorageSupport()) {
24
- try {
25
- let dbData: any = window.localStorage.getItem(LOCAL_STORAGE_PRIMARY_KEY);
26
- const now = new Date();
27
-
28
- const item = {
29
- value,
30
- expiry: now.getTime() + ttl,
31
- };
32
-
33
- if (dbData) {
34
- dbData = JSON.parse(dbData);
35
- dbData[key] = item;
36
- } else {
37
- dbData = { [key]: item };
38
- }
39
-
40
- window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
41
-
42
- return true;
43
- } catch (e) {
44
- return false;
45
- } // case when localStorage space quota is exceeded
46
- } else {
47
- return false;
48
- }
49
- };
50
-
51
- export const localStorageGet = (key: string) => {
52
- if (checkLocalStorageSupport()) {
53
- try {
54
- const primaryLocalStorageValue = window.localStorage.getItem(
55
- LOCAL_STORAGE_PRIMARY_KEY,
56
- );
57
- let dbData =
58
- primaryLocalStorageValue != null
59
- ? JSON.parse(primaryLocalStorageValue)
60
- : primaryLocalStorageValue;
61
- const requestedData = dbData[key];
62
- const now = new Date();
63
-
64
- if (now.getTime() > requestedData.expiry) {
65
- dbData = removeKeyFromObject(dbData, key);
66
- window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
67
-
68
- return null;
69
- }
70
-
71
- return requestedData.value;
72
- } catch (e) {
73
- return null;
74
- }
75
- } else {
76
- return null;
77
- }
78
- };
79
-
80
- export const localStorageGetAll = () => {
81
- if (checkLocalStorageSupport()) {
82
- try {
83
- const primaryLocalStorageValue = window.localStorage.getItem(
84
- LOCAL_STORAGE_PRIMARY_KEY,
85
- );
86
-
87
- return primaryLocalStorageValue != null
88
- ? JSON.parse(primaryLocalStorageValue)
89
- : primaryLocalStorageValue;
90
- } catch (e) {
91
- return null;
92
- }
93
- } else {
94
- return null;
95
- }
96
- };
97
-
98
- export const localStorageRemove = (key: string) => {
99
- if (checkLocalStorageSupport()) {
100
- try {
101
- const primaryLocalStorageValue = window.localStorage.getItem(
102
- LOCAL_STORAGE_PRIMARY_KEY,
103
- );
104
- let dbData =
105
- primaryLocalStorageValue != null
106
- ? JSON.parse(primaryLocalStorageValue)
107
- : primaryLocalStorageValue;
108
-
109
- if (dbData[key]) {
110
- dbData = removeKeyFromObject(dbData, key);
111
- window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
112
-
113
- return true;
114
- }
115
-
116
- return false;
117
- } catch (e) {
118
- return false;
119
- }
120
- } else {
121
- return false;
122
- }
123
- };
124
-
125
- export const localStorageRemoveAll = () => {
126
- if (checkLocalStorageSupport()) {
127
- try {
128
- const primaryLocalStorageValue = window.localStorage.getItem(
129
- LOCAL_STORAGE_PRIMARY_KEY,
130
- );
131
- const dbData =
132
- primaryLocalStorageValue != null
133
- ? JSON.parse(primaryLocalStorageValue)
134
- : primaryLocalStorageValue;
135
-
136
- if (dbData) {
137
- window.localStorage.removeItem(LOCAL_STORAGE_PRIMARY_KEY);
138
-
139
- return true;
140
- }
141
-
142
- return false;
143
- } catch (e) {
144
- return false;
145
- }
146
- } else {
147
- return false;
148
- }
149
- };
150
-
151
- export const removeExpiredKeysOnMount = () => {
152
- if (checkLocalStorageSupport()) {
153
- try {
154
- const primaryLocalStorageValue = window.localStorage.getItem(
155
- LOCAL_STORAGE_PRIMARY_KEY,
156
- );
157
- let dbData =
158
- primaryLocalStorageValue != null
159
- ? JSON.parse(primaryLocalStorageValue)
160
- : primaryLocalStorageValue;
161
- const now = new Date();
162
-
163
- if (dbData) {
164
- dbData = Object.keys(dbData).reduce((accumulator: any, key) => {
165
- if (now.getTime() < dbData[key].expiry) {
166
- accumulator[key] = dbData[key];
167
- }
168
-
169
- return accumulator;
170
- }, {});
171
- }
172
-
173
- if (Object.keys(dbData).length) {
174
- window.localStorage.setItem(LOCAL_STORAGE_PRIMARY_KEY, JSON.stringify(dbData));
175
- } else {
176
- localStorageRemoveAll();
177
- }
178
-
179
- return true;
180
- } catch (e) {
181
- return false;
182
- }
183
- } else {
184
- return false;
185
- }
186
- };
@@ -1,26 +0,0 @@
1
- export function isEmpty(obj: object): boolean {
2
- return Object.keys(obj).length === 0;
3
- }
4
-
5
- // In this case both object have same key names Don't use to compare objects
6
- export function isMapEqual(
7
- map1: { [x: string]: any },
8
- map2: { [x: string]: any },
9
- ): boolean {
10
- const map1Keys = Object.keys(map1);
11
- const map2Keys = Object.keys(map2);
12
-
13
- if (map1Keys.length !== map2Keys.length) {
14
- return false;
15
- }
16
- for (let i = 0; i < map1Keys.length; i += 1) {
17
- const key = map1Keys[i];
18
-
19
- if (map1[key] !== map2[key]) {
20
- return false;
21
- }
22
- }
23
-
24
- return true;
25
- }
26
-