sveltacular 0.0.72 → 0.0.73
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/helpers/date.d.ts +9 -4
- package/dist/helpers/date.js +29 -6
- package/dist/helpers/remove-properties.d.ts +1 -0
- package/dist/helpers/remove-properties.js +10 -0
- package/dist/helpers/transform.d.ts +4 -0
- package/dist/helpers/transform.js +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
package/dist/helpers/date.d.ts
CHANGED
|
@@ -8,11 +8,16 @@ export declare const addMinutes: (minutes: number, fromDateTime?: string | Date)
|
|
|
8
8
|
export declare const addHours: (hours: number, fromDateTime?: string | Date) => Date;
|
|
9
9
|
export declare const addSeconds: (seconds: number, fromDateTime?: string | Date) => Date;
|
|
10
10
|
export declare const addUnits: (value: number, units: DateUnit, fromDateTime?: string | Date) => Date;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const dateTimeToHuman: (dateTime: string) => string;
|
|
14
|
-
export declare const
|
|
11
|
+
export declare const dateTimeFromTz: (dateTime: string | null) => string;
|
|
12
|
+
export declare const dateTimeToTz: (dateTime: string) => string | null;
|
|
13
|
+
export declare const dateTimeToHuman: (dateTime: string, locale?: string) => string;
|
|
14
|
+
export declare const toDateTime: (date?: string | Date) => Date;
|
|
15
|
+
export declare const toDate: (date?: Date | string) => string;
|
|
16
|
+
export declare const dateTimeToInput: (dateTime?: Date | string) => string;
|
|
15
17
|
export declare const isDateString: (date: string) => date is string;
|
|
16
18
|
export declare const isDateTimeString: (dateTime: string) => dateTime is string;
|
|
17
19
|
export declare const isDateOrDateTimeString: (dateOrDateTime: unknown) => dateOrDateTime is string;
|
|
18
20
|
export declare const formatDateTime: (dateTime: string | Date) => string;
|
|
21
|
+
export declare const toHumanReadableDuration: (duration: number, singularUnits: string) => string;
|
|
22
|
+
export declare const diffDates: (start: string | Date, end: string | Date) => number;
|
|
23
|
+
export declare const isBetween: (date: string | Date, start: string | Date, end: string | Date) => boolean;
|
package/dist/helpers/date.js
CHANGED
|
@@ -59,7 +59,7 @@ export const addUnits = (value, units, fromDateTime) => {
|
|
|
59
59
|
return date;
|
|
60
60
|
};
|
|
61
61
|
// Convert datetime from YYYY-MM-DDTHH:MM+TZ format to YYYY-MM-DD HH:MM format
|
|
62
|
-
export const
|
|
62
|
+
export const dateTimeFromTz = (dateTime) => {
|
|
63
63
|
if (!dateTime)
|
|
64
64
|
return '';
|
|
65
65
|
const date = new Date(dateTime);
|
|
@@ -68,7 +68,7 @@ export const dateTimeFromSupabase = (dateTime) => {
|
|
|
68
68
|
return date.toISOString().split('.')[0].slice(0, -3);
|
|
69
69
|
};
|
|
70
70
|
// Convert datetime from YYYY-MM-DD HH:MM format to YYYY-MM-DDTHH:MM+TZ format
|
|
71
|
-
export const
|
|
71
|
+
export const dateTimeToTz = (dateTime) => {
|
|
72
72
|
if (!dateTime)
|
|
73
73
|
return null;
|
|
74
74
|
const date = new Date(dateTime);
|
|
@@ -79,23 +79,29 @@ export const dateTimeToSupabase = (dateTime) => {
|
|
|
79
79
|
/*
|
|
80
80
|
* Convert datetime to human-readable format with AM/PM, no seconds
|
|
81
81
|
*/
|
|
82
|
-
export const dateTimeToHuman = (dateTime) => {
|
|
82
|
+
export const dateTimeToHuman = (dateTime, locale = 'en-US') => {
|
|
83
83
|
const date = new Date(dateTime);
|
|
84
|
-
const datePart = date.toLocaleString(
|
|
84
|
+
const datePart = date.toLocaleString(locale, {
|
|
85
85
|
month: 'long',
|
|
86
86
|
day: 'numeric',
|
|
87
87
|
year: 'numeric'
|
|
88
88
|
});
|
|
89
|
-
const timePart = date.toLocaleString(
|
|
89
|
+
const timePart = date.toLocaleString(locale, {
|
|
90
90
|
hour: 'numeric',
|
|
91
91
|
minute: 'numeric',
|
|
92
92
|
timeZoneName: 'short'
|
|
93
93
|
});
|
|
94
94
|
return `${datePart} @ ${timePart}`;
|
|
95
95
|
};
|
|
96
|
+
export const toDateTime = (date) => {
|
|
97
|
+
return date ? new Date(date) : new Date();
|
|
98
|
+
};
|
|
99
|
+
export const toDate = (date) => {
|
|
100
|
+
return toDateTime(date).toISOString().split('T')[0];
|
|
101
|
+
};
|
|
96
102
|
// From JavaScript date to YYYY-MM-DD HH:MM format
|
|
97
103
|
export const dateTimeToInput = (dateTime) => {
|
|
98
|
-
dateTime = dateTime
|
|
104
|
+
dateTime = toDateTime(dateTime);
|
|
99
105
|
const offset = dateTime.getTimezoneOffset();
|
|
100
106
|
dateTime.setMinutes(dateTime.getMinutes() - offset);
|
|
101
107
|
return dateTime.toISOString().split('.')[0].slice(0, -3);
|
|
@@ -119,3 +125,20 @@ export const formatDateTime = (dateTime) => {
|
|
|
119
125
|
date.setMinutes(date.getMinutes() - offset);
|
|
120
126
|
return date.toISOString().split('.')[0].slice(0, -3);
|
|
121
127
|
};
|
|
128
|
+
export const toHumanReadableDuration = (duration, singularUnits) => {
|
|
129
|
+
return duration > 0 && duration <= 1
|
|
130
|
+
? `${duration} ${singularUnits}`
|
|
131
|
+
: `${duration} ${singularUnits}s`;
|
|
132
|
+
};
|
|
133
|
+
export const diffDates = (start, end) => {
|
|
134
|
+
const startDate = new Date(start);
|
|
135
|
+
const endDate = new Date(end);
|
|
136
|
+
const duration = endDate.getTime() - startDate.getTime();
|
|
137
|
+
return duration;
|
|
138
|
+
};
|
|
139
|
+
export const isBetween = (date, start, end) => {
|
|
140
|
+
const dateToCheck = new Date(date);
|
|
141
|
+
const startDate = new Date(start);
|
|
142
|
+
const endDate = new Date(end);
|
|
143
|
+
return dateToCheck >= startDate && dateToCheck <= endDate;
|
|
144
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const removeProperties: (obj: unknown, props: string[]) => Record<string, unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Remove properties from an object from an array of strings representing the property names
|
|
2
|
+
export const removeProperties = (obj, props) => {
|
|
3
|
+
if (!obj)
|
|
4
|
+
return {};
|
|
5
|
+
const newObj = { ...obj };
|
|
6
|
+
props.forEach((prop) => {
|
|
7
|
+
delete newObj[prop];
|
|
8
|
+
});
|
|
9
|
+
return newObj;
|
|
10
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -100,9 +100,11 @@ export * from './helpers/debounce.js';
|
|
|
100
100
|
export * from './helpers/navigate-to.js';
|
|
101
101
|
export * from './helpers/nobr.js';
|
|
102
102
|
export * from './helpers/random.js';
|
|
103
|
+
export * from './helpers/remove-properties.js';
|
|
103
104
|
export * from './helpers/round-to-decimals.js';
|
|
104
105
|
export * from './helpers/split-new-lines.js';
|
|
105
106
|
export * from './helpers/subscribable.js';
|
|
107
|
+
export * from './helpers/transform.js';
|
|
106
108
|
export * from './helpers/ucfirst.js';
|
|
107
109
|
export * from './helpers/unique-id.js';
|
|
108
110
|
export * from './data/index.js';
|
package/dist/index.js
CHANGED
|
@@ -111,9 +111,11 @@ export * from './helpers/debounce.js';
|
|
|
111
111
|
export * from './helpers/navigate-to.js';
|
|
112
112
|
export * from './helpers/nobr.js';
|
|
113
113
|
export * from './helpers/random.js';
|
|
114
|
+
export * from './helpers/remove-properties.js';
|
|
114
115
|
export * from './helpers/round-to-decimals.js';
|
|
115
116
|
export * from './helpers/split-new-lines.js';
|
|
116
117
|
export * from './helpers/subscribable.js';
|
|
118
|
+
export * from './helpers/transform.js';
|
|
117
119
|
export * from './helpers/ucfirst.js';
|
|
118
120
|
export * from './helpers/unique-id.js';
|
|
119
121
|
// Data
|