wedance-shared 1.0.24 → 1.0.25

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.
@@ -4,14 +4,14 @@ import { Timestamp } from "firebase/firestore";
4
4
  * @param timestamp Firestore Timestamp or null/undefined
5
5
  * @returns JavaScript Date object or null if input is null/undefined
6
6
  */
7
- export declare const timestampToDate: (timestamp: Timestamp | null | undefined) => Date | null;
7
+ export declare const timestampToDate: (timestamp: Timestamp) => Date;
8
8
  export declare function timestampToIsoString(timestamp: Timestamp): string;
9
9
  /**
10
10
  * Converts a JavaScript Date to a Firestore Timestamp
11
11
  * @param date JavaScript Date object or null/undefined
12
12
  * @returns Firestore Timestamp or null if input is null/undefined
13
13
  */
14
- export declare const dateToTimestamp: (date: Date | null | undefined) => Timestamp | null;
14
+ export declare const dateToTimestamp: (date: Date) => Timestamp;
15
15
  /**
16
16
  * Formats a Firestore Timestamp to a string using the provided format
17
17
  * Uses day.js library - install with: npm install dayjs
@@ -21,23 +21,23 @@ export declare const dateToTimestamp: (date: Date | null | undefined) => Timesta
21
21
  * @param defaultValue Value to return if timestamp is null/undefined
22
22
  * @returns Formatted date string or defaultValue if timestamp is null/undefined
23
23
  */
24
- export declare const formatTimestamp: (timestamp: Timestamp | null | undefined, formatStr?: string, defaultValue?: string) => string;
24
+ export declare const formatTimestamp: (timestamp: Timestamp, formatStr?: string) => string;
25
25
  /**
26
26
  * Checks if a Firestore Timestamp is before current time
27
27
  * @param timestamp Firestore Timestamp to check
28
28
  * @returns boolean indicating if timestamp is in the past
29
29
  */
30
- export declare const isTimestampInPast: (timestamp: Timestamp | null | undefined) => boolean;
30
+ export declare const isTimestampInPast: (timestamp: Timestamp) => boolean;
31
31
  /**
32
32
  * Checks if a Firestore Timestamp is after current time
33
33
  * @param timestamp Firestore Timestamp to check
34
34
  * @returns boolean indicating if timestamp is in the future
35
35
  */
36
- export declare const isTimestampInFuture: (timestamp: Timestamp | null | undefined) => boolean;
36
+ export declare const isTimestampInFuture: (timestamp: Timestamp) => boolean;
37
37
  /**
38
38
  * Gets the relative time between now and a Firestore Timestamp (e.g. "2 hours ago", "in 3 days")
39
39
  * Uses day.js with relativeTime plugin for localized relative time formatting
40
40
  * @param timestamp Firestore Timestamp
41
41
  * @returns String representation of relative time
42
42
  */
43
- export declare const getRelativeTime: (timestamp: Timestamp | null | undefined) => string;
43
+ export declare const getRelativeTime: (timestamp: Timestamp) => string;
@@ -9,8 +9,9 @@ dayjs.extend(relativeTime);
9
9
  * @returns JavaScript Date object or null if input is null/undefined
10
10
  */
11
11
  export const timestampToDate = (timestamp) => {
12
- if (!timestamp)
13
- return null;
12
+ if (!timestamp) {
13
+ throw new Error("Timestamp is null or undefined");
14
+ }
14
15
  return new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
15
16
  };
16
17
  export function timestampToIsoString(timestamp) {
@@ -22,8 +23,9 @@ export function timestampToIsoString(timestamp) {
22
23
  * @returns Firestore Timestamp or null if input is null/undefined
23
24
  */
24
25
  export const dateToTimestamp = (date) => {
25
- if (!date)
26
- return null;
26
+ if (!date) {
27
+ throw new Error("Date is null or undefined");
28
+ }
27
29
  return Timestamp.fromDate(date);
28
30
  };
29
31
  /**
@@ -35,19 +37,14 @@ export const dateToTimestamp = (date) => {
35
37
  * @param defaultValue Value to return if timestamp is null/undefined
36
38
  * @returns Formatted date string or defaultValue if timestamp is null/undefined
37
39
  */
38
- export const formatTimestamp = (timestamp, formatStr = "MMM D, YYYY", defaultValue = "") => {
39
- if (!timestamp)
40
- return defaultValue;
41
- try {
42
- // Convert timestamp to Date
43
- const date = new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
44
- // Use dayjs to format the date according to the format string
45
- return dayjs(date).format(formatStr);
46
- }
47
- catch (error) {
48
- console.error("Error formatting timestamp:", error);
49
- return defaultValue;
40
+ export const formatTimestamp = (timestamp, formatStr = "MMM D, YYYY") => {
41
+ if (!timestamp) {
42
+ throw new Error("Timestamp is null or undefined");
50
43
  }
44
+ // Convert timestamp to Date
45
+ const date = new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
46
+ // Use dayjs to format the date according to the format string
47
+ return dayjs(date).format(formatStr);
51
48
  };
52
49
  /**
53
50
  * Checks if a Firestore Timestamp is before current time
@@ -55,8 +52,9 @@ export const formatTimestamp = (timestamp, formatStr = "MMM D, YYYY", defaultVal
55
52
  * @returns boolean indicating if timestamp is in the past
56
53
  */
57
54
  export const isTimestampInPast = (timestamp) => {
58
- if (!timestamp)
59
- return false;
55
+ if (!timestamp) {
56
+ throw new Error("Timestamp is null or undefined");
57
+ }
60
58
  // Convert timestamp to milliseconds manually
61
59
  const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
62
60
  return timestampMillis < Date.now();
@@ -67,8 +65,9 @@ export const isTimestampInPast = (timestamp) => {
67
65
  * @returns boolean indicating if timestamp is in the future
68
66
  */
69
67
  export const isTimestampInFuture = (timestamp) => {
70
- if (!timestamp)
71
- return false;
68
+ if (!timestamp) {
69
+ throw new Error("Timestamp is null or undefined");
70
+ }
72
71
  // Convert timestamp to milliseconds manually
73
72
  const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
74
73
  return timestampMillis > Date.now();
@@ -80,17 +79,12 @@ export const isTimestampInFuture = (timestamp) => {
80
79
  * @returns String representation of relative time
81
80
  */
82
81
  export const getRelativeTime = (timestamp) => {
83
- if (!timestamp)
84
- return "";
85
- try {
86
- // Convert timestamp to milliseconds manually
87
- const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
88
- // Use dayjs to get relative time
89
- return dayjs(timestampMillis).fromNow();
90
- }
91
- catch (error) {
92
- console.error("Error generating relative time:", error);
93
- return "";
82
+ if (!timestamp) {
83
+ throw new Error("Timestamp is null or undefined");
94
84
  }
85
+ // Convert timestamp to milliseconds manually
86
+ const timestampMillis = timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
87
+ // Use dayjs to get relative time
88
+ return dayjs(timestampMillis).fromNow();
95
89
  };
96
90
  //# sourceMappingURL=date.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,mCAAmC;AACnC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAuC,EAC1B,EAAE;IACf,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,SAAoB;IACvD,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,IAA6B,EACX,EAAE;IACpB,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAAuC,EACvC,YAAoB,aAAa,EACjC,eAAuB,EAAE,EACjB,EAAE;IACV,IAAI,CAAC,SAAS;QAAE,OAAO,YAAY,CAAC;IAEpC,IAAI,CAAC;QACH,4BAA4B;QAC5B,MAAM,IAAI,GAAG,IAAI,IAAI,CACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,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MAAM,eAAe,GACnB,SAAS,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC;IAE7D,iCAAiC;IACjC,OAAO,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,CAAC;AAC1C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wedance-shared",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "This repository contains shared TypeScript types and interfaces used across multiple WeDance applications:",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/utils/date.ts CHANGED
@@ -10,10 +10,10 @@ dayjs.extend(relativeTime);
10
10
  * @param timestamp Firestore Timestamp or null/undefined
11
11
  * @returns JavaScript Date object or null if input is null/undefined
12
12
  */
13
- export const timestampToDate = (
14
- timestamp: Timestamp | null | undefined
15
- ): Date | null => {
16
- if (!timestamp) return null;
13
+ export const timestampToDate = (timestamp: Timestamp): Date => {
14
+ if (!timestamp) {
15
+ throw new Error("Timestamp is null or undefined");
16
+ }
17
17
  return new Date(timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000);
18
18
  };
19
19
 
@@ -26,10 +26,10 @@ export function timestampToIsoString(timestamp: Timestamp) {
26
26
  * @param date JavaScript Date object or null/undefined
27
27
  * @returns Firestore Timestamp or null if input is null/undefined
28
28
  */
29
- export const dateToTimestamp = (
30
- date: Date | null | undefined
31
- ): Timestamp | null => {
32
- if (!date) return null;
29
+ export const dateToTimestamp = (date: Date): Timestamp => {
30
+ if (!date) {
31
+ throw new Error("Date is null or undefined");
32
+ }
33
33
  return Timestamp.fromDate(date);
34
34
  };
35
35
 
@@ -43,24 +43,20 @@ export const dateToTimestamp = (
43
43
  * @returns Formatted date string or defaultValue if timestamp is null/undefined
44
44
  */
45
45
  export const formatTimestamp = (
46
- timestamp: Timestamp | null | undefined,
47
- formatStr: string = "MMM D, YYYY",
48
- defaultValue: string = ""
46
+ timestamp: Timestamp,
47
+ formatStr: string = "MMM D, YYYY"
49
48
  ): string => {
50
- if (!timestamp) return defaultValue;
49
+ if (!timestamp) {
50
+ throw new Error("Timestamp is null or undefined");
51
+ }
51
52
 
52
- try {
53
- // Convert timestamp to Date
54
- const date = new Date(
55
- timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000
56
- );
53
+ // Convert timestamp to Date
54
+ const date = new Date(
55
+ timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000
56
+ );
57
57
 
58
- // Use dayjs to format the date according to the format string
59
- return dayjs(date).format(formatStr);
60
- } catch (error) {
61
- console.error("Error formatting timestamp:", error);
62
- return defaultValue;
63
- }
58
+ // Use dayjs to format the date according to the format string
59
+ return dayjs(date).format(formatStr);
64
60
  };
65
61
 
66
62
  /**
@@ -68,10 +64,10 @@ export const formatTimestamp = (
68
64
  * @param timestamp Firestore Timestamp to check
69
65
  * @returns boolean indicating if timestamp is in the past
70
66
  */
71
- export const isTimestampInPast = (
72
- timestamp: Timestamp | null | undefined
73
- ): boolean => {
74
- if (!timestamp) return false;
67
+ export const isTimestampInPast = (timestamp: Timestamp): boolean => {
68
+ if (!timestamp) {
69
+ throw new Error("Timestamp is null or undefined");
70
+ }
75
71
 
76
72
  // Convert timestamp to milliseconds manually
77
73
  const timestampMillis =
@@ -84,10 +80,10 @@ export const isTimestampInPast = (
84
80
  * @param timestamp Firestore Timestamp to check
85
81
  * @returns boolean indicating if timestamp is in the future
86
82
  */
87
- export const isTimestampInFuture = (
88
- timestamp: Timestamp | null | undefined
89
- ): boolean => {
90
- if (!timestamp) return false;
83
+ export const isTimestampInFuture = (timestamp: Timestamp): boolean => {
84
+ if (!timestamp) {
85
+ throw new Error("Timestamp is null or undefined");
86
+ }
91
87
 
92
88
  // Convert timestamp to milliseconds manually
93
89
  const timestampMillis =
@@ -101,20 +97,15 @@ export const isTimestampInFuture = (
101
97
  * @param timestamp Firestore Timestamp
102
98
  * @returns String representation of relative time
103
99
  */
104
- export const getRelativeTime = (
105
- timestamp: Timestamp | null | undefined
106
- ): string => {
107
- if (!timestamp) return "";
100
+ export const getRelativeTime = (timestamp: Timestamp): string => {
101
+ if (!timestamp) {
102
+ throw new Error("Timestamp is null or undefined");
103
+ }
108
104
 
109
- try {
110
- // Convert timestamp to milliseconds manually
111
- const timestampMillis =
112
- timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
105
+ // Convert timestamp to milliseconds manually
106
+ const timestampMillis =
107
+ timestamp.seconds * 1000 + timestamp.nanoseconds / 1000000;
113
108
 
114
- // Use dayjs to get relative time
115
- return dayjs(timestampMillis).fromNow();
116
- } catch (error) {
117
- console.error("Error generating relative time:", error);
118
- return "";
119
- }
109
+ // Use dayjs to get relative time
110
+ return dayjs(timestampMillis).fromNow();
120
111
  };