@8ms/helpers 2.3.25 → 2.3.26
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 +118 -189
- package/.github/workflows/deploy_npmjs.yml +0 -41
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.12.0.cjs +0 -942
- package/.yarnrc.yml +0 -2
- package/dist/_class/index.d.mts +0 -2
- package/dist/_class/index.mjs +0 -61
- package/dist/adverity/index.d.mts +0 -2
- package/dist/adverity/index.mjs +0 -64
- package/dist/adverity/server/index.d.mts +0 -18
- package/dist/adverity/server/index.mjs +0 -25
- package/dist/api/index.d.mts +0 -2
- package/dist/api/index.mjs +0 -3
- package/dist/api-DGKJDAfb.mjs +0 -139
- package/dist/array/index.d.mts +0 -11
- package/dist/array/index.mjs +0 -12
- package/dist/atInternet/index.d.mts +0 -20
- package/dist/atInternet/index.mjs +0 -18
- package/dist/aws/ec2/server/index.d.mts +0 -18
- package/dist/aws/ec2/server/index.mjs +0 -48
- package/dist/aws/ecs/server/index.d.mts +0 -59
- package/dist/aws/ecs/server/index.mjs +0 -113
- package/dist/aws/glue/server/index.d.mts +0 -19
- package/dist/aws/glue/server/index.mjs +0 -36
- package/dist/aws/lambda/server/index.d.mts +0 -28
- package/dist/aws/lambda/server/index.mjs +0 -57
- package/dist/aws/s3/server/index.d.mts +0 -124
- package/dist/aws/s3/server/index.mjs +0 -360
- package/dist/aws/server/index.d.mts +0 -2
- package/dist/aws/server/index.mjs +0 -3
- package/dist/aws/ses/server/index.d.mts +0 -105
- package/dist/aws/ses/server/index.mjs +0 -268
- package/dist/aws/sqs/server/index.d.mts +0 -41
- package/dist/aws/sqs/server/index.mjs +0 -56
- package/dist/aws/ssm/server/index.d.mts +0 -18
- package/dist/aws/ssm/server/index.mjs +0 -47
- package/dist/axios/index.d.mts +0 -22
- package/dist/axios/index.mjs +0 -50
- package/dist/boolean/index.d.mts +0 -7
- package/dist/boolean/index.mjs +0 -13
- package/dist/brightData/serpApi/server/index.d.mts +0 -93
- package/dist/brightData/serpApi/server/index.mjs +0 -229
- package/dist/brightData/server/index.d.mts +0 -2
- package/dist/brightData/server/index.mjs +0 -18
- package/dist/brightData/webScraperIde/server/index.d.mts +0 -19
- package/dist/brightData/webScraperIde/server/index.mjs +0 -50
- package/dist/cache/server/index.d.mts +0 -10
- package/dist/cache/server/index.mjs +0 -31
- package/dist/chunk-DDarj8oW.mjs +0 -7
- package/dist/crud/index.d.mts +0 -10
- package/dist/crud/index.mjs +0 -10
- package/dist/crypto/index.d.mts +0 -25
- package/dist/crypto/index.mjs +0 -57
- package/dist/date/index.d.mts +0 -2
- package/dist/date/index.mjs +0 -471
- package/dist/drizzle/server/index.d.mts +0 -22
- package/dist/drizzle/server/index.mjs +0 -69
- package/dist/environment/index.d.mts +0 -37
- package/dist/environment/index.mjs +0 -60
- package/dist/eskimi/index.d.mts +0 -52
- package/dist/eskimi/index.mjs +0 -90
- package/dist/eskimi/server/index.d.mts +0 -25
- package/dist/eskimi/server/index.mjs +0 -50
- package/dist/file/index.d.mts +0 -7
- package/dist/file/index.mjs +0 -20
- package/dist/file/server/index.d.mts +0 -8
- package/dist/file/server/index.mjs +0 -16
- package/dist/geo/index.d.mts +0 -26
- package/dist/geo/index.mjs +0 -1591
- package/dist/getDecimal-CafxtLhH.mjs +0 -40
- package/dist/googleAds/keywordPlanner/server/index.d.mts +0 -45
- package/dist/googleAds/keywordPlanner/server/index.mjs +0 -51
- package/dist/googleAds/server/index.d.mts +0 -27
- package/dist/googleAds/server/index.mjs +0 -48
- package/dist/googleCloud/bigquery/server/index.d.mts +0 -82
- package/dist/googleCloud/bigquery/server/index.mjs +0 -133
- package/dist/googleCloud/server/index.d.mts +0 -2
- package/dist/googleCloud/server/index.mjs +0 -24
- package/dist/googleCloud/sheets/server/index.d.mts +0 -22
- package/dist/googleCloud/sheets/server/index.mjs +0 -31
- package/dist/googleCloud/storage/server/index.d.mts +0 -31
- package/dist/googleCloud/storage/server/index.mjs +0 -79
- package/dist/googlePageSpeed/server/index.d.mts +0 -34
- package/dist/googlePageSpeed/server/index.mjs +0 -53
- package/dist/googleSearchIncidents/server/index.d.mts +0 -73
- package/dist/googleSearchIncidents/server/index.mjs +0 -55
- package/dist/greenDomain/server/index.d.mts +0 -25
- package/dist/greenDomain/server/index.mjs +0 -31
- package/dist/index-1fBbJGQz.d.mts +0 -246
- package/dist/index-BHuvb_7y.d.mts +0 -116
- package/dist/index-BfyGIdDD.d.mts +0 -18
- package/dist/index-CqTOMR8f.d.mts +0 -17
- package/dist/index-DW9yJLtI.d.mts +0 -67
- package/dist/index-DmCSxHCc.d.mts +0 -32
- package/dist/index-DwB8X1lz.d.mts +0 -32
- package/dist/inngest/index.d.mts +0 -10
- package/dist/inngest/index.mjs +0 -10
- package/dist/json/index.d.mts +0 -7
- package/dist/json/index.mjs +0 -27
- package/dist/littleWarden/server/index.d.mts +0 -56
- package/dist/littleWarden/server/index.mjs +0 -79
- package/dist/lodash/index.d.mts +0 -45
- package/dist/lodash/index.mjs +0 -176
- package/dist/lumar/api/server/index.d.mts +0 -66
- package/dist/lumar/api/server/index.mjs +0 -111
- package/dist/lumar/graphql/server/index.d.mts +0 -308
- package/dist/lumar/graphql/server/index.mjs +0 -172
- package/dist/myTarget/server/index.d.mts +0 -9
- package/dist/myTarget/server/index.mjs +0 -16
- package/dist/nextAuth/index.d.mts +0 -12
- package/dist/nextAuth/index.mjs +0 -15
- package/dist/nextJs/client/index.d.mts +0 -10
- package/dist/nextJs/client/index.mjs +0 -12
- package/dist/nextJs/index.d.mts +0 -19
- package/dist/nextJs/index.mjs +0 -12
- package/dist/number/index.d.mts +0 -54
- package/dist/number/index.mjs +0 -75
- package/dist/object/index.d.mts +0 -8
- package/dist/object/index.mjs +0 -22
- package/dist/onePassword/server/index.d.mts +0 -24
- package/dist/onePassword/server/index.mjs +0 -50
- package/dist/openAi/server/index.d.mts +0 -20
- package/dist/openAi/server/index.mjs +0 -46
- package/dist/prisma/index.d.mts +0 -7
- package/dist/prisma/index.mjs +0 -15
- package/dist/prisma/server/index.d.mts +0 -31
- package/dist/prisma/server/index.mjs +0 -64
- package/dist/server-Bwy4JI8Z.mjs +0 -33
- package/dist/snapchat/server/index.d.mts +0 -25
- package/dist/snapchat/server/index.mjs +0 -39
- package/dist/sorting/index.d.mts +0 -25
- package/dist/sorting/index.mjs +0 -50
- package/dist/stream/server/index.d.mts +0 -15
- package/dist/stream/server/index.mjs +0 -48
- package/dist/string/index.d.mts +0 -107
- package/dist/string/index.mjs +0 -187
- package/dist/swr/client/index.d.mts +0 -46
- package/dist/swr/client/index.mjs +0 -40
- package/dist/upTimeRobot/server/index.d.mts +0 -72
- package/dist/upTimeRobot/server/index.mjs +0 -82
- package/dist/url/index.d.mts +0 -29
- package/dist/url/index.mjs +0 -52
- package/dist/url/server/index.d.mts +0 -9
- package/dist/url/server/index.mjs +0 -35
- package/dist/util/index.d.mts +0 -50
- package/dist/util/index.mjs +0 -107
- package/dist/util/server/index.d.mts +0 -27
- package/dist/util/server/index.mjs +0 -61
- package/dist/webWorker/index.d.mts +0 -11
- package/dist/webWorker/index.mjs +0 -11
- package/dist/xml/server/index.d.mts +0 -4
- package/dist/xml/server/index.mjs +0 -17
- package/tsdown.config.ts +0 -11
package/dist/date/index.mjs
DELETED
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import { DateTime, Interval } from "luxon";
|
|
2
|
-
|
|
3
|
-
//#region src/date/date.ts
|
|
4
|
-
const defaultDate = "1901-01-01";
|
|
5
|
-
const defaultDateNumber = 19010101;
|
|
6
|
-
const defaultDateTime = "1901-01-01 00:00:00";
|
|
7
|
-
/**
|
|
8
|
-
* Used by Google Ads API.
|
|
9
|
-
*/
|
|
10
|
-
const month = {
|
|
11
|
-
JANUARY: "JANUARY",
|
|
12
|
-
FEBRUARY: "FEBRUARY",
|
|
13
|
-
MARCH: "MARCH",
|
|
14
|
-
APRIL: "APRIL",
|
|
15
|
-
MAY: "MAY",
|
|
16
|
-
JUNE: "JUNE",
|
|
17
|
-
JULY: "JULY",
|
|
18
|
-
AUGUST: "AUGUST",
|
|
19
|
-
SEPTEMBER: "SEPTEMBER",
|
|
20
|
-
OCTOBER: "OCTOBER",
|
|
21
|
-
NOVEMBER: "NOVEMBER",
|
|
22
|
-
DECEMBER: "DECEMBER"
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/date/calculation.ts
|
|
27
|
-
/**
|
|
28
|
-
* Return unix timestamp in seconds.
|
|
29
|
-
*/
|
|
30
|
-
const getUnix = (input) => {
|
|
31
|
-
return getLuxonDate(input).toUnixInteger();
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Assume the input is always UTC.
|
|
35
|
-
*
|
|
36
|
-
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
37
|
-
*/
|
|
38
|
-
const getLuxonDate = (input, setMidnight) => {
|
|
39
|
-
let instance = DateTime.now().toUTC();
|
|
40
|
-
if (input) if (input instanceof Date) instance = DateTime.fromJSDate(input, { zone: "utc" });
|
|
41
|
-
else if (input instanceof DateTime) instance = input.toUTC();
|
|
42
|
-
else if ("number" === typeof input) if (input >= 19000101 && input <= 99991231) {
|
|
43
|
-
const dateStr = input.toString();
|
|
44
|
-
const year = parseInt(dateStr.substring(0, 4));
|
|
45
|
-
const month = parseInt(dateStr.substring(4, 6));
|
|
46
|
-
const day = parseInt(dateStr.substring(6, 8));
|
|
47
|
-
instance = DateTime.fromObject({
|
|
48
|
-
year,
|
|
49
|
-
month,
|
|
50
|
-
day
|
|
51
|
-
}, { zone: "utc" });
|
|
52
|
-
} else if (input < 1e10) instance = DateTime.fromSeconds(input, { zone: "utc" });
|
|
53
|
-
else instance = DateTime.fromMillis(input, { zone: "utc" });
|
|
54
|
-
else {
|
|
55
|
-
instance = DateTime.fromISO(input.toString(), { zone: "utc" });
|
|
56
|
-
if (!instance.isValid) instance = DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
|
|
57
|
-
}
|
|
58
|
-
instance = instance.setZone("utc", { keepLocalTime: false });
|
|
59
|
-
if (setMidnight) instance = instance.set({
|
|
60
|
-
hour: 0,
|
|
61
|
-
minute: 0,
|
|
62
|
-
second: 0,
|
|
63
|
-
millisecond: 0
|
|
64
|
-
});
|
|
65
|
-
return instance;
|
|
66
|
-
};
|
|
67
|
-
const isMonday = (input) => {
|
|
68
|
-
return getLuxonDate(input).weekday === 1;
|
|
69
|
-
};
|
|
70
|
-
const isTuesday = (input) => {
|
|
71
|
-
return getLuxonDate(input).weekday === 2;
|
|
72
|
-
};
|
|
73
|
-
const isWednesday = (input) => {
|
|
74
|
-
return getLuxonDate(input).weekday === 3;
|
|
75
|
-
};
|
|
76
|
-
const isThursday = (input) => {
|
|
77
|
-
return getLuxonDate(input).weekday === 4;
|
|
78
|
-
};
|
|
79
|
-
const isFriday = (input) => {
|
|
80
|
-
return getLuxonDate(input).weekday === 6;
|
|
81
|
-
};
|
|
82
|
-
const isSaturday = (input) => {
|
|
83
|
-
return getLuxonDate(input).weekday === 6;
|
|
84
|
-
};
|
|
85
|
-
const isSunday = (input) => {
|
|
86
|
-
return getLuxonDate(input).weekday === 7;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Determines if a given date falls on a weekend.
|
|
90
|
-
*
|
|
91
|
-
* This function checks whether the day of the week for the provided input corresponds
|
|
92
|
-
* to Saturday or Sunday, where weekday values of 6 and 7 represent Saturday and Sunday, respectively.
|
|
93
|
-
*/
|
|
94
|
-
const isWeekend = (input) => {
|
|
95
|
-
const luxonDate = getLuxonDate(input);
|
|
96
|
-
return 6 === luxonDate.weekday || 7 === luxonDate.weekday;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Calculates the difference in minutes between two provided dates.
|
|
100
|
-
*/
|
|
101
|
-
const differenceInMinutes = (start, end) => {
|
|
102
|
-
const startDate = getLuxonDate(start);
|
|
103
|
-
return getLuxonDate(end).diff(startDate, "minutes").minutes;
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Calculates the difference in business days between two dates.
|
|
107
|
-
* Business days are considered as weekdays (Monday to Friday).
|
|
108
|
-
*/
|
|
109
|
-
const differenceInBusinessDays = (start, end) => {
|
|
110
|
-
const startDate = getLuxonDate(start);
|
|
111
|
-
const endDate = getLuxonDate(end);
|
|
112
|
-
let businessDays = 0;
|
|
113
|
-
let current = startDate.startOf("day");
|
|
114
|
-
while (current < endDate.startOf("day")) {
|
|
115
|
-
if (current.weekday <= 5) businessDays++;
|
|
116
|
-
current = current.plus({ days: 1 });
|
|
117
|
-
}
|
|
118
|
-
return businessDays;
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
|
|
122
|
-
* https://date-fns.org/v2.28.0/docs/eachDayOfInterval
|
|
123
|
-
* https://www.gov.uk/when-do-the-clocks-change
|
|
124
|
-
*/
|
|
125
|
-
const getDatesBetween = (start, end) => {
|
|
126
|
-
const startInstance = getLuxonDate(start);
|
|
127
|
-
const endInstance = getLuxonDate(end);
|
|
128
|
-
return Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day")).splitBy({ day: 1 }).map((d) => d.start);
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Get an array of DateTime objects representing the 1st of each month between start and end dates.
|
|
132
|
-
*/
|
|
133
|
-
const getMonthsBetween = (start, end) => {
|
|
134
|
-
const months = [];
|
|
135
|
-
const endDate = getLuxonDate(end).startOf("month");
|
|
136
|
-
let current = getLuxonDate(start).startOf("month");
|
|
137
|
-
while (current <= endDate) {
|
|
138
|
-
months.push(current);
|
|
139
|
-
current = current.plus({ months: 1 });
|
|
140
|
-
}
|
|
141
|
-
return months;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* If a given date is beyond the maximum, return the maximum.
|
|
145
|
-
*/
|
|
146
|
-
const getMax = (input, max) => {
|
|
147
|
-
return input > max ? max : input;
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* If a given date is before the minimum, return the minimum.
|
|
151
|
-
*/
|
|
152
|
-
const getMin = (input, min) => {
|
|
153
|
-
return input < min ? min : input;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Retrieve the closest last Monday relative to the input or today.
|
|
157
|
-
* 0 weeksAgo - Tuesday (10th), return Monday (8th)
|
|
158
|
-
* 1 weeksAgo - Tuesday (10th), return Monday (1st)
|
|
159
|
-
*/
|
|
160
|
-
const getMonday = (input, weeksAgo) => {
|
|
161
|
-
let instance = getLuxonDate(input);
|
|
162
|
-
if ("Mon" !== instance.toFormat("EEE")) {
|
|
163
|
-
const isoDay = Number(instance.toFormat("E")) - 1;
|
|
164
|
-
instance = instance.minus({ days: isoDay });
|
|
165
|
-
}
|
|
166
|
-
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
167
|
-
return instance;
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* Retrieve the closest last Sunday relative to the input or today.
|
|
171
|
-
* 0 weeksAgo - Tuesday (17th), return Sunday (14th)
|
|
172
|
-
* 1 weeksAgo - Tuesday (17th), return Monday (7th)
|
|
173
|
-
*/
|
|
174
|
-
const getSunday = (input, weeksAgo) => {
|
|
175
|
-
let instance = getLuxonDate(input);
|
|
176
|
-
if ("Sun" !== instance.toFormat("EEE")) {
|
|
177
|
-
const isoDay = Number(instance.toFormat("E"));
|
|
178
|
-
instance = instance.minus({ days: isoDay });
|
|
179
|
-
}
|
|
180
|
-
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
181
|
-
return instance;
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* Return an object of start/end predefined date of Last Week.
|
|
185
|
-
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
186
|
-
*/
|
|
187
|
-
const getLastWeek = () => {
|
|
188
|
-
return {
|
|
189
|
-
end: getMonday(void 0, 0),
|
|
190
|
-
start: getSunday(void 0, 1)
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Return an object of start/end predefined date of This Week.
|
|
195
|
-
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
196
|
-
*/
|
|
197
|
-
const getThisWeek = () => {
|
|
198
|
-
return {
|
|
199
|
-
end: getMonday(void 0, 0),
|
|
200
|
-
start: getSunday(void 0, -1)
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Return an object of start/end predefined date of Two Weeks Ago.
|
|
205
|
-
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
206
|
-
*/
|
|
207
|
-
const getTwoWeeksAgo = () => {
|
|
208
|
-
return {
|
|
209
|
-
end: getMonday(void 0, 1),
|
|
210
|
-
start: getSunday(void 0, 2)
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Shortcut to get today's date.
|
|
215
|
-
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
216
|
-
*/
|
|
217
|
-
const getToday = (setMidnight) => {
|
|
218
|
-
return getLuxonDate(void 0, setMidnight);
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* From a given input, move the date back X weeksAgo
|
|
222
|
-
*/
|
|
223
|
-
const getWeeksAgo = (input, weeksAgo) => {
|
|
224
|
-
let instance = getLuxonDate(input);
|
|
225
|
-
instance = instance.plus({ weeks: weeksAgo });
|
|
226
|
-
return instance;
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* Shortcut to get yesterday's date.
|
|
230
|
-
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
231
|
-
*/
|
|
232
|
-
const getYesterday = (input) => {
|
|
233
|
-
let instance = getLuxonDate(input);
|
|
234
|
-
instance = instance.minus({ days: 1 });
|
|
235
|
-
return instance;
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Check to see if a given timeframe is This Week.
|
|
239
|
-
*/
|
|
240
|
-
const isThisWeek = (start, end) => {
|
|
241
|
-
const inputWeek = {
|
|
242
|
-
start: getLuxonDate(start),
|
|
243
|
-
end: getLuxonDate(end)
|
|
244
|
-
};
|
|
245
|
-
const thisWeek = getThisWeek();
|
|
246
|
-
return inputWeek.start.hasSame(thisWeek.start, "day") && inputWeek.end.hasSame(thisWeek.end, "day");
|
|
247
|
-
};
|
|
248
|
-
/**
|
|
249
|
-
* Check to see if a given timeframe is Last Week.
|
|
250
|
-
*/
|
|
251
|
-
const isLastWeek = (start, end) => {
|
|
252
|
-
const inputWeek = {
|
|
253
|
-
start: getLuxonDate(start),
|
|
254
|
-
end: getLuxonDate(end)
|
|
255
|
-
};
|
|
256
|
-
const lastWeek = getLastWeek();
|
|
257
|
-
return inputWeek.start.hasSame(lastWeek.start, "day") && inputWeek.end.hasSame(lastWeek.end, "day");
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
//#endregion
|
|
261
|
-
//#region src/date/financialYear.ts
|
|
262
|
-
/**
|
|
263
|
-
* Get the financial year based on an optional year.
|
|
264
|
-
*/
|
|
265
|
-
const getFinancialYear = (year) => {
|
|
266
|
-
let financialYear = year;
|
|
267
|
-
if ("undefined" === typeof year) {
|
|
268
|
-
const todayInstance = getToday();
|
|
269
|
-
if (todayInstance < getLuxonDate(`${todayInstance.toFormat("yyyy")}-04-01`)) financialYear = Number(todayInstance.toFormat("yyyy")) - 1;
|
|
270
|
-
else financialYear = Number(todayInstance.toFormat("yyyy"));
|
|
271
|
-
}
|
|
272
|
-
let yearStartInstance = getLuxonDate(`${financialYear}-04-01`);
|
|
273
|
-
if ("Mon" !== yearStartInstance.toFormat("EEE")) {
|
|
274
|
-
const daysToSubtract = Number(yearStartInstance.toFormat("E")) - 1;
|
|
275
|
-
yearStartInstance = yearStartInstance.minus({ days: daysToSubtract });
|
|
276
|
-
}
|
|
277
|
-
let yearEndInstance = getLuxonDate(`${financialYear + 1}-03-31`);
|
|
278
|
-
if ("Sun" !== yearEndInstance.toFormat("EEE")) {
|
|
279
|
-
const daysToAdd = 7 - Number(yearEndInstance.toFormat("E"));
|
|
280
|
-
yearEndInstance = yearEndInstance.plus({ days: daysToAdd });
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
end: yearEndInstance,
|
|
284
|
-
start: yearStartInstance
|
|
285
|
-
};
|
|
286
|
-
};
|
|
287
|
-
/**
|
|
288
|
-
* Return the current financial year up to today.
|
|
289
|
-
*/
|
|
290
|
-
const getFinancialYearToDate = () => {
|
|
291
|
-
return {
|
|
292
|
-
end: getToday(),
|
|
293
|
-
start: getFinancialYear().start
|
|
294
|
-
};
|
|
295
|
-
};
|
|
296
|
-
/**
|
|
297
|
-
* Return the current financial year up to yesterday.
|
|
298
|
-
* Timezone should always be London based
|
|
299
|
-
*/
|
|
300
|
-
const getFinancialYearToYesterday = () => {
|
|
301
|
-
return {
|
|
302
|
-
end: getYesterday(),
|
|
303
|
-
start: getFinancialYear().start
|
|
304
|
-
};
|
|
305
|
-
};
|
|
306
|
-
/**
|
|
307
|
-
* Get the current financial year.
|
|
308
|
-
*/
|
|
309
|
-
const getFinancialYearWeeks = (year) => {
|
|
310
|
-
const financialYear = getFinancialYear(year);
|
|
311
|
-
return Interval.fromDateTimes(financialYear.start, financialYear.end).splitBy({ weeks: 1 });
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
//#endregion
|
|
315
|
-
//#region src/date/format.ts
|
|
316
|
-
/**
|
|
317
|
-
* Convert a number of seconds into HH:MM:SS
|
|
318
|
-
* https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
|
|
319
|
-
*/
|
|
320
|
-
const getDurationHours = (seconds) => {
|
|
321
|
-
let response = "00:00:00";
|
|
322
|
-
if (seconds > 0) {
|
|
323
|
-
const calculated = {
|
|
324
|
-
hours: Math.floor(seconds / 3600),
|
|
325
|
-
minutes: Math.floor(seconds % 3600 / 60),
|
|
326
|
-
seconds: seconds % 60
|
|
327
|
-
};
|
|
328
|
-
const output = {
|
|
329
|
-
hours: calculated.hours < 10 ? "0" + calculated.hours : calculated.hours,
|
|
330
|
-
minutes: calculated.minutes < 10 ? "0" + calculated.minutes : calculated.minutes,
|
|
331
|
-
seconds: calculated.seconds < 10 ? "0" + calculated.seconds : calculated.seconds
|
|
332
|
-
};
|
|
333
|
-
response = `${output.hours}:${output.minutes}:${output.seconds}`;
|
|
334
|
-
}
|
|
335
|
-
return response;
|
|
336
|
-
};
|
|
337
|
-
/**
|
|
338
|
-
* Convert a number of seconds into MM:SS
|
|
339
|
-
* https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
|
|
340
|
-
*/
|
|
341
|
-
const getDurationMinutes = (seconds) => {
|
|
342
|
-
let response = "00:00";
|
|
343
|
-
if (seconds > 0) {
|
|
344
|
-
const calculated = {
|
|
345
|
-
minutes: Math.floor(seconds % 3600 / 60),
|
|
346
|
-
seconds: seconds % 60
|
|
347
|
-
};
|
|
348
|
-
const output = {
|
|
349
|
-
minutes: calculated.minutes < 10 ? "0" + calculated.minutes : calculated.minutes,
|
|
350
|
-
seconds: calculated.seconds < 10 ? "0" + calculated.seconds : calculated.seconds
|
|
351
|
-
};
|
|
352
|
-
response = `${output.minutes}:${output.seconds}`;
|
|
353
|
-
}
|
|
354
|
-
return response;
|
|
355
|
-
};
|
|
356
|
-
/**
|
|
357
|
-
* Simple function takes any DateTime, String or Number and formats it.
|
|
358
|
-
*/
|
|
359
|
-
const format = (input, dateFormat) => {
|
|
360
|
-
return getLuxonDate(input).toFormat(dateFormat);
|
|
361
|
-
};
|
|
362
|
-
/**
|
|
363
|
-
* Convert a Date into a dd number.
|
|
364
|
-
*/
|
|
365
|
-
const getDayNumber = (input) => {
|
|
366
|
-
return Number(format(input, "dd"));
|
|
367
|
-
};
|
|
368
|
-
/**
|
|
369
|
-
* Whenever we are displaying a month and year date in Codex, this will be the standardised format.
|
|
370
|
-
* Example: 1901-02-03 → 3 Feb 1901
|
|
371
|
-
*/
|
|
372
|
-
const getFullDate = (input) => {
|
|
373
|
-
return format(input, "d MMM yyyy");
|
|
374
|
-
};
|
|
375
|
-
/**
|
|
376
|
-
* Whenever we are displaying a month and year date in Codex, this will be the standardised format.
|
|
377
|
-
* Example: 1901-02-03 01:23:45 → 1:23am 3 Feb 1901
|
|
378
|
-
*/
|
|
379
|
-
const getFullDateTime = (input) => {
|
|
380
|
-
return format(input, "d MMM yyyy h:mm:ss");
|
|
381
|
-
};
|
|
382
|
-
/**
|
|
383
|
-
* Returns a MMM YYYY value as a number for a given year.
|
|
384
|
-
* Example: 1901-02-03 → Feb 1901
|
|
385
|
-
*/
|
|
386
|
-
const getMonthYearString = (input) => {
|
|
387
|
-
return format(input, "MMM yyyy");
|
|
388
|
-
};
|
|
389
|
-
/**
|
|
390
|
-
* Returns a YYYY MMM value as a number for a given year.
|
|
391
|
-
* Example: 1901-02-03 → 1901 Feb
|
|
392
|
-
*/
|
|
393
|
-
const getYearMonthString = (input) => {
|
|
394
|
-
return format(input, "yyyy MMM");
|
|
395
|
-
};
|
|
396
|
-
/**
|
|
397
|
-
* Shorthand to get the current date.
|
|
398
|
-
*/
|
|
399
|
-
const getTodayYmdString = (setMidnight) => {
|
|
400
|
-
return getYmdString(getToday(setMidnight));
|
|
401
|
-
};
|
|
402
|
-
/**
|
|
403
|
-
* Shorthand to get the current date.
|
|
404
|
-
*/
|
|
405
|
-
const getTodayYmdHisString = (setMidnight) => {
|
|
406
|
-
return getYmdHisString(getToday(setMidnight));
|
|
407
|
-
};
|
|
408
|
-
/**
|
|
409
|
-
* Shorthand to get the current date.
|
|
410
|
-
*/
|
|
411
|
-
const getTodayYmdNumber = (setMidnight) => {
|
|
412
|
-
return getYmdNumber(getToday(setMidnight));
|
|
413
|
-
};
|
|
414
|
-
/**
|
|
415
|
-
* Shorthand to get the current date.
|
|
416
|
-
*/
|
|
417
|
-
const getTodayYmdHisNumber = (setMidnight) => {
|
|
418
|
-
return getYmdHisNumber(getToday(setMidnight));
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Convert a Date into a YYYY number.
|
|
422
|
-
*/
|
|
423
|
-
const getYearNumber = (input) => {
|
|
424
|
-
return Number(format(input, "yyyy"));
|
|
425
|
-
};
|
|
426
|
-
/**
|
|
427
|
-
* Returns a YYYYMMDDHHIISS value as a number.
|
|
428
|
-
* Example: 1901-02-03 01:23:45 → 19010203012345
|
|
429
|
-
*/
|
|
430
|
-
const getYmdHisNumber = (input) => {
|
|
431
|
-
return Number(format(input, "yyyyMMddHHmmss"));
|
|
432
|
-
};
|
|
433
|
-
/**
|
|
434
|
-
* Returns a YYYY-MM-DD HH:MM:SS value as a string.
|
|
435
|
-
* Example: 1901-02-03 → 1901-02-03 00:00:00
|
|
436
|
-
*/
|
|
437
|
-
const getYmdHisString = (input) => {
|
|
438
|
-
return format(input, "yyyy-MM-dd HH:mm:ss");
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* Returns a YYYYMMDD value as a number.
|
|
442
|
-
* Example: 1901-02-03 → 19010203
|
|
443
|
-
*/
|
|
444
|
-
const getYmdNumber = (input) => {
|
|
445
|
-
return Number(format(input, "yyyyMMdd"));
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* Whenever we are displaying a YYYY-MM-DD date in Codex
|
|
449
|
-
* Example: 1901-02-03 → 1901-02-03
|
|
450
|
-
*/
|
|
451
|
-
const getYmdString = (input) => {
|
|
452
|
-
return format(input, "yyyy-MM-dd");
|
|
453
|
-
};
|
|
454
|
-
/**
|
|
455
|
-
* Convert an Excel date "e.g. 44216" into a JavaScript date object.
|
|
456
|
-
* https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript
|
|
457
|
-
*/
|
|
458
|
-
const getLuxonDateFromExcel = (serial) => {
|
|
459
|
-
const utcValue = Math.floor(serial - 25569) * 86400;
|
|
460
|
-
const dateInfo = /* @__PURE__ */ new Date(utcValue * 1e3);
|
|
461
|
-
const fractionalDay = serial - Math.floor(serial) + 1e-7;
|
|
462
|
-
let totalSeconds = Math.floor(86400 * fractionalDay);
|
|
463
|
-
const seconds = totalSeconds % 60;
|
|
464
|
-
totalSeconds -= seconds;
|
|
465
|
-
const hours = Math.floor(totalSeconds / 3600);
|
|
466
|
-
const minutes = Math.floor(totalSeconds / 60) % 60;
|
|
467
|
-
return DateTime.fromISO(`${dateInfo.getFullYear()}-${dateInfo.getMonth()}-${dateInfo.getDate()}T${hours}:${minutes}:${seconds}Z`);
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
//#endregion
|
|
471
|
-
export { defaultDate, defaultDateNumber, defaultDateTime, differenceInBusinessDays, differenceInMinutes, format, getDatesBetween, getDayNumber, getDurationHours, getDurationMinutes, getFinancialYear, getFinancialYearToDate, getFinancialYearToYesterday, getFinancialYearWeeks, getFullDate, getFullDateTime, getLastWeek, getLuxonDate, getLuxonDateFromExcel, getMax, getMin, getMonday, getMonthYearString, getMonthsBetween, getSunday, getThisWeek, getToday, getTodayYmdHisNumber, getTodayYmdHisString, getTodayYmdNumber, getTodayYmdString, getTwoWeeksAgo, getUnix, getWeeksAgo, getYearMonthString, getYearNumber, getYesterday, getYmdHisNumber, getYmdHisString, getYmdNumber, getYmdString, isFriday, isLastWeek, isMonday, isSaturday, isSunday, isThisWeek, isThursday, isTuesday, isWednesday, isWeekend, month };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { t as BaseNamespace } from "../../index-DwB8X1lz.mjs";
|
|
2
|
-
import { defineRelations } from "drizzle-orm";
|
|
3
|
-
|
|
4
|
-
//#region src/drizzle/server/DrizzleNamespace.d.ts
|
|
5
|
-
declare class DrizzleNamespace<TClient = any> extends BaseNamespace {
|
|
6
|
-
client: TClient;
|
|
7
|
-
config: DrizzleConfig;
|
|
8
|
-
ensureInit: () => Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/drizzle/server/drizzle.d.ts
|
|
12
|
-
type DrizzleConfig = {
|
|
13
|
-
relations?: ReturnType<typeof defineRelations>;
|
|
14
|
-
url: string;
|
|
15
|
-
isDebug: boolean;
|
|
16
|
-
isPlanetScale: boolean;
|
|
17
|
-
isMysql: boolean;
|
|
18
|
-
isPostgres: boolean;
|
|
19
|
-
};
|
|
20
|
-
declare const drizzleClient: <TClient = any>(key?: string, config?: DrizzleConfig) => Promise<DrizzleNamespace<TClient>>;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { DrizzleConfig, DrizzleNamespace, drizzleClient };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { getError } from "../../util/index.mjs";
|
|
2
|
-
import { BaseNamespace } from "../../_class/index.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/drizzle/server/DrizzleNamespace.ts
|
|
5
|
-
var DrizzleNamespace = class extends BaseNamespace {
|
|
6
|
-
ensureInit = async () => {
|
|
7
|
-
if (!this.client) {
|
|
8
|
-
let logger = void 0;
|
|
9
|
-
if (this.config.isDebug) {
|
|
10
|
-
const { DefaultLogger } = await import("drizzle-orm/logger");
|
|
11
|
-
logger = new DefaultLogger();
|
|
12
|
-
}
|
|
13
|
-
if (this.config.isPlanetScale) try {
|
|
14
|
-
const { drizzle } = await import("drizzle-orm/planetscale-serverless");
|
|
15
|
-
this.client = drizzle({
|
|
16
|
-
connection: { url: this.config.url },
|
|
17
|
-
relations: this.config?.relations,
|
|
18
|
-
logger
|
|
19
|
-
});
|
|
20
|
-
} catch (e) {
|
|
21
|
-
throw new Error(`PlanetScale driver not installed - ${getError(e)}`);
|
|
22
|
-
}
|
|
23
|
-
else if (this.config.isMysql) try {
|
|
24
|
-
const { drizzle } = await import("drizzle-orm/mysql2");
|
|
25
|
-
this.client = drizzle({
|
|
26
|
-
connection: this.config.url,
|
|
27
|
-
relations: this.config?.relations,
|
|
28
|
-
logger
|
|
29
|
-
});
|
|
30
|
-
} catch (e) {
|
|
31
|
-
throw new Error(`MySQL2 driver not installed - ${getError(e)}`);
|
|
32
|
-
}
|
|
33
|
-
else if (this.config.isPostgres) try {
|
|
34
|
-
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
35
|
-
this.client = drizzle({
|
|
36
|
-
connection: this.config.url,
|
|
37
|
-
relations: this.config?.relations,
|
|
38
|
-
logger
|
|
39
|
-
});
|
|
40
|
-
} catch (e) {
|
|
41
|
-
throw new Error(`Postgres (pg) driver not installed - ${getError(e)}`);
|
|
42
|
-
}
|
|
43
|
-
else throw new Error(`No database type configured — set DATABASE_IS_PLANETSCALE, DATABASE_IS_MYSQL or DATABASE_IS_POSTGRES to "true"`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/drizzle/server/drizzle.ts
|
|
50
|
-
const drizzleNamespaces = /* @__PURE__ */ new Map();
|
|
51
|
-
const drizzleClient = async (key = "default", config) => {
|
|
52
|
-
if (drizzleNamespaces.has(key)) return drizzleNamespaces.get(key);
|
|
53
|
-
if (!config) if (key === "default") config = {
|
|
54
|
-
relations: void 0,
|
|
55
|
-
url: process.env.DATABASE_URL,
|
|
56
|
-
isDebug: "true" === process.env.DATABASE_IS_DEBUG,
|
|
57
|
-
isPlanetScale: "true" === process.env.DATABASE_IS_PLANETSCALE,
|
|
58
|
-
isMysql: "true" === process.env.DATABASE_IS_MYSQL,
|
|
59
|
-
isPostgres: "true" === process.env.DATABASE_IS_POSTGRES
|
|
60
|
-
};
|
|
61
|
-
else throw new Error(`Config required for namespace '${key}'`);
|
|
62
|
-
const namespace = new DrizzleNamespace(key, config);
|
|
63
|
-
await namespace.ensureInit();
|
|
64
|
-
drizzleNamespaces.set(key, namespace);
|
|
65
|
-
return namespace;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { DrizzleNamespace, drizzleClient };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
//#region src/environment/environment.d.ts
|
|
2
|
-
declare const environment: {
|
|
3
|
-
readonly DEVELOPMENT: "development";
|
|
4
|
-
readonly STAGING: "staging";
|
|
5
|
-
readonly PRODUCTION: "production";
|
|
6
|
-
};
|
|
7
|
-
type Environment = typeof environment[keyof typeof environment];
|
|
8
|
-
declare const platform: {
|
|
9
|
-
readonly AWS: "AWS";
|
|
10
|
-
readonly VERCEL: "VERCEL";
|
|
11
|
-
};
|
|
12
|
-
type Platform = typeof platform[keyof typeof platform];
|
|
13
|
-
/**
|
|
14
|
-
* Determine the environment we're using.
|
|
15
|
-
*/
|
|
16
|
-
declare const getEnvironment: () => Environment;
|
|
17
|
-
/**
|
|
18
|
-
* Check to see if we are working on AWS Lambda.
|
|
19
|
-
*/
|
|
20
|
-
declare const isAws: () => boolean;
|
|
21
|
-
declare const isVercel: () => boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Some code should only run on the server side to protect the data.
|
|
24
|
-
*/
|
|
25
|
-
declare const isServer: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Check the environment currently running.
|
|
28
|
-
*/
|
|
29
|
-
declare const isDevelopment: () => boolean;
|
|
30
|
-
declare const isStaging: () => boolean;
|
|
31
|
-
declare const isProduction: () => boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Check to see if we are developing locally or on the hosted platform.
|
|
34
|
-
*/
|
|
35
|
-
declare const isLocalhost: () => boolean;
|
|
36
|
-
//#endregion
|
|
37
|
-
export { Environment, Platform, environment, getEnvironment, isAws, isDevelopment, isLocalhost, isProduction, isServer, isStaging, isVercel, platform };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
//#region src/environment/environment.ts
|
|
2
|
-
const environment = {
|
|
3
|
-
DEVELOPMENT: "development",
|
|
4
|
-
STAGING: "staging",
|
|
5
|
-
PRODUCTION: "production"
|
|
6
|
-
};
|
|
7
|
-
const platform = {
|
|
8
|
-
AWS: "AWS",
|
|
9
|
-
VERCEL: "VERCEL"
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Determine the environment we're using.
|
|
13
|
-
*/
|
|
14
|
-
const getEnvironment = () => {
|
|
15
|
-
let platformEnvironment = process.env.ENVIRONMENT;
|
|
16
|
-
let response;
|
|
17
|
-
if (process.env.EMS_ENVIRONMENT) platformEnvironment = process.env.EMS_ENVIRONMENT;
|
|
18
|
-
else if (process.env.NEXT_PUBLIC_EMS_ENVIRONMENT) platformEnvironment = process.env.NEXT_PUBLIC_EMS_ENVIRONMENT;
|
|
19
|
-
else if (process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF) platformEnvironment = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF;
|
|
20
|
-
else if (process.env.VERCEL_GIT_COMMIT_REF) platformEnvironment = process.env.VERCEL_GIT_COMMIT_REF;
|
|
21
|
-
switch (platformEnvironment.toLowerCase().trim()) {
|
|
22
|
-
case "production":
|
|
23
|
-
response = environment.PRODUCTION;
|
|
24
|
-
break;
|
|
25
|
-
case "demo":
|
|
26
|
-
case "preview":
|
|
27
|
-
case "staging":
|
|
28
|
-
response = environment.STAGING;
|
|
29
|
-
break;
|
|
30
|
-
default: response = environment.DEVELOPMENT;
|
|
31
|
-
}
|
|
32
|
-
return response;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Check to see if we are working on AWS Lambda.
|
|
36
|
-
*/
|
|
37
|
-
const isAws = () => platform.AWS === process.env["EMS_PLATFORM"];
|
|
38
|
-
const isVercel = () => void 0 !== process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF;
|
|
39
|
-
/**
|
|
40
|
-
* Some code should only run on the server side to protect the data.
|
|
41
|
-
*/
|
|
42
|
-
const isServer = typeof window === "undefined";
|
|
43
|
-
/**
|
|
44
|
-
* Check the environment currently running.
|
|
45
|
-
*/
|
|
46
|
-
const isDevelopment = () => environment.DEVELOPMENT === getEnvironment();
|
|
47
|
-
const isStaging = () => environment.STAGING === getEnvironment();
|
|
48
|
-
const isProduction = () => environment.PRODUCTION === getEnvironment();
|
|
49
|
-
/**
|
|
50
|
-
* Check to see if we are developing locally or on the hosted platform.
|
|
51
|
-
*/
|
|
52
|
-
const isLocalhost = () => {
|
|
53
|
-
if ("true" === process.env["IS_LOCAL"]) return true;
|
|
54
|
-
if (isAws()) return "true" === process.env["AWS_SAM_LOCAL"];
|
|
55
|
-
if (isVercel()) return void 0 === process.env["NEXT_PUBLIC_VERCEL_GIT_REPO_ID"];
|
|
56
|
-
return false;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
export { environment, getEnvironment, isAws, isDevelopment, isLocalhost, isProduction, isServer, isStaging, isVercel, platform };
|