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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuemath/web-utils",
3
- "version": "0.0.1-beta.3",
3
+ "version": "0.0.1-beta.5",
4
4
  "description": "Shareable utils package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -9,7 +9,8 @@
9
9
  "build-watch": "tsc -w",
10
10
  "prepublishOnly": "rm -rf dist && yarn build",
11
11
  "prepare": "husky install",
12
- "precommit": "lint-staged"
12
+ "precommit": "lint-staged",
13
+ "release": "lerna publish from-package"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
@@ -40,7 +41,8 @@
40
41
  },
41
42
  "dependencies": {
42
43
  "@types/node": "^18.11.18",
43
- "dayjs": "^1.11.7"
44
+ "dayjs": "^1.11.7",
45
+ "lerna": "^6.4.1"
44
46
  },
45
47
  "lint-staged": {
46
48
  "*.{js,json,css,scss,html,md,ts}": [
@@ -27,7 +27,7 @@ export const convertedTimezone = (selectedTimezone: string) => {
27
27
  return formattedTimezone[0]?.value;
28
28
  }
29
29
 
30
- return selectedTimezone?.replace(/_/g, ' ');
30
+ return selectedTimezone?.replaceAll('_', ' ');
31
31
  };
32
32
 
33
33
  export const getHourInTwelveHourFormat = (hour: number) => {
@@ -36,7 +36,7 @@ export function getCurrentTimestamp(): number {
36
36
  return Math.floor(Date.now() / 1000);
37
37
  }
38
38
 
39
- export function dateTimeByTimezone(timestamp: Timestamp, timezone?: string): string {
39
+ export function dateTimeByTimezone(timestamp: Timestamp, timezone?: string) {
40
40
  let options = {};
41
41
 
42
42
  if (timezone) {
@@ -48,19 +48,19 @@ export function dateTimeByTimezone(timestamp: Timestamp, timezone?: string): str
48
48
  return new Date(timestamp).toLocaleString('en-US', options);
49
49
  }
50
50
 
51
- export function dateByTimezone(timestamp: number, timezone: string, format: string): string {
51
+ export function dateByTimezone(timestamp: number, timezone: string, format: string) {
52
52
  const datetime = dateTimeByTimezone(timestamp, timezone);
53
53
 
54
54
  return dayjs(datetime).format(format || 'mm/dd/yyyy');
55
55
  }
56
56
 
57
- export const dateByTimestamp = (timestamp: Timestamp, format: string): string => {
57
+ export const dateByTimestamp = (timestamp: Timestamp, format: string) => {
58
58
  const datetime = new Date(timestamp).toLocaleString('en-US');
59
59
 
60
60
  return dayjs(datetime).format(format || 'mm/dd/yyyy');
61
61
  };
62
62
 
63
- export function convertTimeStampToSeconds(timeStamp: Timestamp): number {
63
+ export function convertTimeStampToSeconds(timeStamp: Timestamp) {
64
64
  const demoTimeStamp = timeStamp;
65
65
  const currentTimeStamp = getCurrentTimestamp();
66
66
 
@@ -74,25 +74,25 @@ export function convertTimeStampToSeconds(timeStamp: Timestamp): number {
74
74
  return demoTimeStampLength > currentTimeStampLength ? timeStamp / 1000 : timeStamp;
75
75
  }
76
76
 
77
- export function formatTimestamp(datetime: Timestamp, format: string | undefined): string {
77
+ export function formatTimestamp(datetime: Timestamp, format: string | undefined) {
78
78
  const timeStamp = convertTimeStampToSeconds(datetime);
79
79
 
80
80
  return dayjs.unix(timeStamp).format(format);
81
81
  }
82
82
 
83
- export function getTimezone(): string {
83
+ export function getTimezone() {
84
84
  return Intl?.DateTimeFormat().resolvedOptions().timeZone;
85
85
  }
86
86
 
87
87
  export function timeToX(
88
88
  datetime: string | number | Date | dayjs.Dayjs | null | undefined,
89
- ): string {
89
+ ) {
90
90
  dayjs.extend(relativeTime);
91
91
 
92
92
  return dayjs().to(datetime, true);
93
93
  }
94
94
 
95
- export function getCurrentDatebyTimezone(timezone: string): string {
95
+ export function getCurrentDatebyTimezone(timezone: string) {
96
96
  let options = {};
97
97
 
98
98
  if (timezone) {
@@ -107,7 +107,7 @@ export function getCurrentDatebyTimezone(timezone: string): string {
107
107
  export function getTimeDiff(
108
108
  date1: string | number | Date | dayjs.Dayjs | null | undefined,
109
109
  date2: string | number | Date | dayjs.Dayjs | null | undefined,
110
- ) : {days: any, hour: any, minute: any, seconds: any, distance: any} {
110
+ ) {
111
111
  const dateTime1 = dayjs(date1);
112
112
  const dateTime2 = dayjs(date2);
113
113
 
@@ -120,15 +120,63 @@ export function getTimeDiff(
120
120
  };
121
121
  }
122
122
 
123
- export function getISOTimeString(demoTs: number): string {
123
+ // function roundTime(time: Date) {
124
+ // time.setHours(time.getHours() + Math.round(time.getMinutes() / 60));
125
+ // time.setMinutes(0, 0, 0);
126
+ // }
127
+
128
+ // function getTimeString(increment: number, time: Date, timezone: string) {
129
+ // const value = dateByTimezone(time, timezone, 'hh:mm a');
130
+
131
+ // time.setTime(time.getTime() + increment * 60 * 1000);
132
+
133
+ // return value;
134
+ // }
135
+
136
+ // export function getSlotsTillNextDay(interval: number, timezone: string) {
137
+ // const today = new Date();
138
+ // const curr = new Date();
139
+
140
+ // roundTime(today);
141
+ // roundTime(curr);
142
+
143
+ // const slots = [];
144
+
145
+ // while (getTimeDiff(today, curr).days !== -1) {
146
+ // slots.push({
147
+ // id: curr.getTime(),
148
+ // value: getTimeString(interval, curr, timezone),
149
+ // });
150
+ // }
151
+
152
+ // return slots;
153
+ // }
154
+
155
+ export function getISOTimeString(demoTs: number) {
124
156
  return new Date(demoTs * 1000).toISOString().replace(/-|:|\.\d\d\d/g, '');
125
157
  }
126
158
 
127
- export function getDateAfterDays(days: number): string {
159
+ export function getDateAfterDays(days: number) {
128
160
  return formatDateTime(dayjs().add(days, 'day'), 'D MMM, YYYY').toUpperCase();
129
161
  }
130
162
 
131
- export const convertedTimezone = (selectedTimezone: string): string => {
163
+ // function convertTZ(date: string | number | Date, tzString: any){
164
+ // return new Date(
165
+ // (typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', {
166
+ // timeZone: tzString,
167
+ // }),
168
+ // );
169
+ // }
170
+
171
+ // export function getUtcTimestamp(timeZone: any, date: string) {
172
+ // const time = convertTZ(date, timeZone);
173
+
174
+ // const parsedDate = Date.parse(time);
175
+
176
+ // return parsedDate / 1000;
177
+ // }
178
+
179
+ export const convertedTimezone = (selectedTimezone: string) => {
132
180
  const formattedTimezone = timezones?.filter(
133
181
  currentTimezone => currentTimezone?.id === selectedTimezone,
134
182
  );
@@ -137,10 +185,10 @@ export const convertedTimezone = (selectedTimezone: string): string => {
137
185
  return formattedTimezone[0]?.value;
138
186
  }
139
187
 
140
- return selectedTimezone?.replace(/_/g, ' ');
188
+ return selectedTimezone?.replaceAll('_', ' ');
141
189
  };
142
190
 
143
- export const getHourInTwelveHourFormat = (hour: number): number => {
191
+ export const getHourInTwelveHourFormat = (hour: number) => {
144
192
  return hour % 12 === 0 ? 12 : hour % 12;
145
193
  };
146
194
 
@@ -148,7 +196,7 @@ export const getMeridiemAccordingToHourAndHourFormat = (
148
196
  hour: number,
149
197
  hourFormat: number,
150
198
  meridiem = '',
151
- ): string => {
199
+ ) => {
152
200
  if (hourFormat === HOUR_FORMAT.TWENTY_FOUR_HOUR_FORMAT) {
153
201
  return hour / 12 >= 1 ? 'PM' : 'AM';
154
202
  }
@@ -156,7 +204,7 @@ export const getMeridiemAccordingToHourAndHourFormat = (
156
204
  return hour === 12 ? 'PM' : meridiem;
157
205
  };
158
206
 
159
- export const getTimeSlotDuration = (selectedTime: number, selectedTimezone: any): string => {
207
+ export const getTimeSlotDuration = (selectedTime: number, selectedTimezone: any) => {
160
208
  const firstHour = getHourInTwelveHourFormat(selectedTime);
161
209
  const firstMeridiem = getMeridiemAccordingToHourAndHourFormat(
162
210
  selectedTime,
@@ -179,7 +227,7 @@ export const convertSecondsToMiliseconds = (seconds: number) => {
179
227
  };
180
228
 
181
229
  // convert date into Sept 01, Thursday format
182
- export const convertDate = (selectedDate: number, selectedTimezone: string): string => {
230
+ export const convertDate = (selectedDate: number, selectedTimezone: string) => {
183
231
  const slotDate = formatTimestamp(selectedDate, 'DD-MM-YYYY');
184
232
  const dayOfWeek = dateByTimezone(selectedDate * 1000, selectedTimezone, 'dddd');
185
233
  const dateArr = slotDate?.split('-');
@@ -189,7 +237,7 @@ export const convertDate = (selectedDate: number, selectedTimezone: string): str
189
237
  return `${monthArray[parseInt(month, 10) - 1]} ${day}, ${dayOfWeek}`;
190
238
  };
191
239
 
192
- export const getModifiedDateSlots = (dateSlotsData: { label: string }[]): { label: string; removeBorder?: boolean }[][] => {
240
+ export const getModifiedDateSlots = (dateSlotsData: { label: string }[]) => {
193
241
  const startWeekIndex = shorthandWeekDayArray?.indexOf(dateSlotsData?.[0]?.label);
194
242
 
195
243
  // get all days
@@ -229,7 +277,7 @@ export const getModifiedDateSlots = (dateSlotsData: { label: string }[]): { labe
229
277
  };
230
278
 
231
279
  // Array of 7 days
232
- export const getDates = (timezone: string): { futureDate: any; disabled: any; }[] => {
280
+ export const getDates = (timezone: string) => {
233
281
  const currentDate = Date.parse(getCurrentDatebyTimezone(timezone)) / 1000;
234
282
  const dates = [];
235
283
 
@@ -247,16 +295,16 @@ export const getDates = (timezone: string): { futureDate: any; disabled: any; }
247
295
  export function formatDateFromTimestamp(
248
296
  timestamp: string | number | Date,
249
297
  format: string,
250
- ) : string {
298
+ ) {
251
299
  const datetime = new Date(timestamp).toLocaleString('en-US');
252
300
 
253
301
  return dayjs(datetime).format(format || 'mm/dd/yyyy');
254
302
  }
255
303
 
256
- export function getAvailableDateSlots(currentTimezone: any): DateSlots [] {
304
+ export function getAvailableDateSlots(currentTimezone: any) {
257
305
  const availableDateSlots: DateSlots[] = [];
258
306
 
259
- getDates(currentTimezone).map((item: { futureDate: any; disabled: any; }) => {
307
+ getDates(currentTimezone).map(item => {
260
308
  const { futureDate, disabled } = item;
261
309
 
262
310
  availableDateSlots.push({
@@ -276,8 +324,8 @@ export const toTimestamp = (strDate: string) => {
276
324
  return Date.parse(strDate) / 1000;
277
325
  };
278
326
 
279
- export const getDateSlots = (timezone: any): { [x: string]: any } => {
280
- return getDates(timezone).map((item: { futureDate: any; disabled: any; }) => {
327
+ export const getDateSlots = (timezone: any) => {
328
+ return getDates(timezone).map(item => {
281
329
  const { futureDate, disabled } = item;
282
330
 
283
331
  return {
@@ -289,7 +337,16 @@ export const getDateSlots = (timezone: any): { [x: string]: any } => {
289
337
  });
290
338
  };
291
339
 
292
- export const getTimeSlotDurationForSlotPage = (selectedTime: string): string => {
340
+ // export const getUtcUnixTimestamp = (date: number, time: any, timezone: any) => {
341
+ // const formatDate = formatTimestamp(date, 'MM/DD/YYYY');
342
+ // const convertedDatTime = dateTimeByTimezone(
343
+ // toTimestamp(`${formatDate} ${time}`) * 1000
344
+ // );
345
+
346
+ // return getUtcTimestamp(timezone, convertedDatTime);
347
+ // };
348
+
349
+ export const getTimeSlotDurationForSlotPage = (selectedTime: string) => {
293
350
  const timeArr = selectedTime.split(':');
294
351
  const firstHour = timeArr?.[0];
295
352
  const meridiem = timeArr?.[1]?.split(' ')?.[1];
@@ -303,4 +360,6 @@ export const getTimeSlotDurationForSlotPage = (selectedTime: string): string =>
303
360
  );
304
361
 
305
362
  return `${firstHour} ${meridiem.toLowerCase()} - ${secondHour} ${secondMeridiem.toLowerCase()}`;
306
- };
363
+ };
364
+
365
+ export * from './e-cna';