@alextheman/utility 3.5.9 → 3.6.0
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/index.cjs +68 -14
- package/dist/index.d.cts +65 -9
- package/dist/index.d.ts +65 -9
- package/dist/index.js +68 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -264,8 +264,16 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
264
264
|
|
|
265
265
|
//#endregion
|
|
266
266
|
//#region src/functions/date/addDaysToDate.ts
|
|
267
|
+
/**
|
|
268
|
+
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
269
|
+
*
|
|
270
|
+
* @param currentDate - The starting date (defaults to today).
|
|
271
|
+
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
272
|
+
*
|
|
273
|
+
* @returns A new Date instance with the number of days added to the initially provided date.
|
|
274
|
+
*/
|
|
267
275
|
function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement = 1) {
|
|
268
|
-
const newDate = currentDate;
|
|
276
|
+
const newDate = new Date(currentDate);
|
|
269
277
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
270
278
|
return newDate;
|
|
271
279
|
}
|
|
@@ -273,6 +281,14 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
273
281
|
|
|
274
282
|
//#endregion
|
|
275
283
|
//#region src/functions/date/isSameDate.ts
|
|
284
|
+
/**
|
|
285
|
+
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
286
|
+
*
|
|
287
|
+
* @param firstDate - The first date to compare.
|
|
288
|
+
* @param secondDate - The second date to compare.
|
|
289
|
+
*
|
|
290
|
+
* @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
|
|
291
|
+
*/
|
|
276
292
|
function isSameDate(firstDate, secondDate) {
|
|
277
293
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
278
294
|
}
|
|
@@ -280,6 +296,17 @@ var isSameDate_default = isSameDate;
|
|
|
280
296
|
|
|
281
297
|
//#endregion
|
|
282
298
|
//#region src/functions/date/formatDateAndTime.ts
|
|
299
|
+
/**
|
|
300
|
+
* Creates a human-readable string with information about the input date.
|
|
301
|
+
*
|
|
302
|
+
* @param inputDate - The date to base the string on.
|
|
303
|
+
*
|
|
304
|
+
* @returns A new string with information about the given date.
|
|
305
|
+
*
|
|
306
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
307
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
308
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
309
|
+
*/
|
|
283
310
|
function formatDateAndTime(inputDate) {
|
|
284
311
|
const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
|
|
285
312
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -292,6 +319,15 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
292
319
|
|
|
293
320
|
//#endregion
|
|
294
321
|
//#region src/functions/date/isLeapYear.ts
|
|
322
|
+
/**
|
|
323
|
+
* Checks if the provided year is a leap year.
|
|
324
|
+
*
|
|
325
|
+
* @param year - The year to check as a number.
|
|
326
|
+
*
|
|
327
|
+
* @throws {TypeError} If the year provided is not an integer.
|
|
328
|
+
*
|
|
329
|
+
* @returns True if the year is a leap year, and false otherwise.
|
|
330
|
+
*/
|
|
295
331
|
function isLeapYear(year) {
|
|
296
332
|
const parsedYear = parseIntStrict_default(`${year}`);
|
|
297
333
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
@@ -304,6 +340,14 @@ function checkLeapYear(firstDate, secondDate) {
|
|
|
304
340
|
if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
305
341
|
return false;
|
|
306
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Checks if the provided dates are exactly a whole number of years apart.
|
|
345
|
+
*
|
|
346
|
+
* @param firstDate - The first date to compare.
|
|
347
|
+
* @param secondDate - The second date to compare.
|
|
348
|
+
*
|
|
349
|
+
* @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
|
|
350
|
+
*/
|
|
307
351
|
function isAnniversary(firstDate, secondDate) {
|
|
308
352
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
309
353
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
@@ -342,6 +386,14 @@ function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
342
386
|
}
|
|
343
387
|
return false;
|
|
344
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Checks if the provided dates are exactly a whole number of months apart.
|
|
391
|
+
*
|
|
392
|
+
* @param firstDate - The first date to compare.
|
|
393
|
+
* @param secondDate - The second date to compare.
|
|
394
|
+
*
|
|
395
|
+
* @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
|
|
396
|
+
*/
|
|
345
397
|
function isMonthlyMultiple(firstDate, secondDate) {
|
|
346
398
|
if (endOfMonthChecksButNotFebruary(firstDate, secondDate) || endOfMonthChecksButNotFebruary(secondDate, firstDate)) return true;
|
|
347
399
|
if (nonLeapYearFebruaryChecks(firstDate, secondDate) || nonLeapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
@@ -458,6 +510,18 @@ function parseBoolean(inputString) {
|
|
|
458
510
|
const stringToBoolean = parseBoolean;
|
|
459
511
|
var parseBoolean_default = parseBoolean;
|
|
460
512
|
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/functions/parsers/parseEnv.ts
|
|
515
|
+
const envSchema = zod.z.enum([
|
|
516
|
+
"test",
|
|
517
|
+
"development",
|
|
518
|
+
"production"
|
|
519
|
+
]);
|
|
520
|
+
function parseEnv(data) {
|
|
521
|
+
return envSchema.parse(data);
|
|
522
|
+
}
|
|
523
|
+
var parseEnv_default = parseEnv;
|
|
524
|
+
|
|
461
525
|
//#endregion
|
|
462
526
|
//#region src/functions/parsers/parseFormData.ts
|
|
463
527
|
function parseFormData(formData, dataParser) {
|
|
@@ -527,26 +591,16 @@ var DataError_default = DataError;
|
|
|
527
591
|
//#endregion
|
|
528
592
|
//#region src/types/Email.ts
|
|
529
593
|
const emailSchema = zod.default.email().brand();
|
|
594
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
530
595
|
function parseEmail(data) {
|
|
531
596
|
return emailSchema.parse(data);
|
|
532
597
|
}
|
|
533
598
|
var Email_default = parseEmail;
|
|
534
599
|
|
|
535
|
-
//#endregion
|
|
536
|
-
//#region src/types/Env.ts
|
|
537
|
-
const envSchema = zod.z.enum([
|
|
538
|
-
"test",
|
|
539
|
-
"development",
|
|
540
|
-
"production"
|
|
541
|
-
]);
|
|
542
|
-
function parseEnv(data = "development") {
|
|
543
|
-
return envSchema.parse(data);
|
|
544
|
-
}
|
|
545
|
-
var Env_default = parseEnv;
|
|
546
|
-
|
|
547
600
|
//#endregion
|
|
548
601
|
//#region src/types/UUID.ts
|
|
549
602
|
const uuidSchema = zod.default.uuid().brand();
|
|
603
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
550
604
|
function parseUUID(UUID) {
|
|
551
605
|
return uuidSchema.parse(UUID);
|
|
552
606
|
}
|
|
@@ -732,7 +786,7 @@ exports.omitProperties = omitProperties_default;
|
|
|
732
786
|
exports.paralleliseArrays = paralleliseArrays_default;
|
|
733
787
|
exports.parseBoolean = parseBoolean_default;
|
|
734
788
|
exports.parseEmail = Email_default;
|
|
735
|
-
exports.parseEnv =
|
|
789
|
+
exports.parseEnv = parseEnv_default;
|
|
736
790
|
exports.parseFormData = parseFormData_default;
|
|
737
791
|
exports.parseIntStrict = parseIntStrict_default;
|
|
738
792
|
exports.parseUUID = UUID_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -115,21 +115,16 @@ declare class DataError extends Error {
|
|
|
115
115
|
//#endregion
|
|
116
116
|
//#region src/types/Email.d.ts
|
|
117
117
|
declare const emailSchema: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
118
|
+
/** @deprecated Please use the inferred type from `z.email() from Zod instead.` */
|
|
118
119
|
type Email = z.infer<typeof emailSchema>;
|
|
120
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
119
121
|
declare function parseEmail(data: unknown): Email;
|
|
120
122
|
//#endregion
|
|
121
|
-
//#region src/types/Env.d.ts
|
|
122
|
-
declare const envSchema: z$1.ZodEnum<{
|
|
123
|
-
test: "test";
|
|
124
|
-
development: "development";
|
|
125
|
-
production: "production";
|
|
126
|
-
}>;
|
|
127
|
-
type Env = z$1.infer<typeof envSchema>;
|
|
128
|
-
declare function parseEnv(data?: unknown): Env;
|
|
129
|
-
//#endregion
|
|
130
123
|
//#region src/types/UUID.d.ts
|
|
131
124
|
declare const uuidSchema: z.core.$ZodBranded<z.ZodUUID, "UUID">;
|
|
125
|
+
/** @deprecated Please use the inferred type from `z.uuid() from Zod instead.` */
|
|
132
126
|
type UUID = z.infer<typeof uuidSchema>;
|
|
127
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
133
128
|
declare function parseUUID(UUID: unknown): UUID;
|
|
134
129
|
//#endregion
|
|
135
130
|
//#region src/types/ArrayElement.d.ts
|
|
@@ -176,21 +171,73 @@ declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, o
|
|
|
176
171
|
declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
|
|
177
172
|
//#endregion
|
|
178
173
|
//#region src/functions/date/addDaysToDate.d.ts
|
|
174
|
+
/**
|
|
175
|
+
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
176
|
+
*
|
|
177
|
+
* @param currentDate - The starting date (defaults to today).
|
|
178
|
+
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
179
|
+
*
|
|
180
|
+
* @returns A new Date instance with the number of days added to the initially provided date.
|
|
181
|
+
*/
|
|
179
182
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
180
183
|
//#endregion
|
|
181
184
|
//#region src/functions/date/formatDateAndTime.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Creates a human-readable string with information about the input date.
|
|
187
|
+
*
|
|
188
|
+
* @param inputDate - The date to base the string on.
|
|
189
|
+
*
|
|
190
|
+
* @returns A new string with information about the given date.
|
|
191
|
+
*
|
|
192
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
193
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
194
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
195
|
+
*/
|
|
182
196
|
declare function formatDateAndTime(inputDate: Date): string;
|
|
183
197
|
//#endregion
|
|
184
198
|
//#region src/functions/date/isAnniversary.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Checks if the provided dates are exactly a whole number of years apart.
|
|
201
|
+
*
|
|
202
|
+
* @param firstDate - The first date to compare.
|
|
203
|
+
* @param secondDate - The second date to compare.
|
|
204
|
+
*
|
|
205
|
+
* @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
|
|
206
|
+
*/
|
|
185
207
|
declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
|
|
186
208
|
//#endregion
|
|
187
209
|
//#region src/functions/date/isLeapYear.d.ts
|
|
210
|
+
/**
|
|
211
|
+
* Checks if the provided year is a leap year.
|
|
212
|
+
*
|
|
213
|
+
* @param year - The year to check as a number.
|
|
214
|
+
*
|
|
215
|
+
* @throws {TypeError} If the year provided is not an integer.
|
|
216
|
+
*
|
|
217
|
+
* @returns True if the year is a leap year, and false otherwise.
|
|
218
|
+
*/
|
|
188
219
|
declare function isLeapYear(year: number): boolean;
|
|
189
220
|
//#endregion
|
|
190
221
|
//#region src/functions/date/isMonthlyMultiple.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Checks if the provided dates are exactly a whole number of months apart.
|
|
224
|
+
*
|
|
225
|
+
* @param firstDate - The first date to compare.
|
|
226
|
+
* @param secondDate - The second date to compare.
|
|
227
|
+
*
|
|
228
|
+
* @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
|
|
229
|
+
*/
|
|
191
230
|
declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
192
231
|
//#endregion
|
|
193
232
|
//#region src/functions/date/isSameDate.d.ts
|
|
233
|
+
/**
|
|
234
|
+
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
235
|
+
*
|
|
236
|
+
* @param firstDate - The first date to compare.
|
|
237
|
+
* @param secondDate - The second date to compare.
|
|
238
|
+
*
|
|
239
|
+
* @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
|
|
240
|
+
*/
|
|
194
241
|
declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
195
242
|
//#endregion
|
|
196
243
|
//#region src/functions/deepCopy.d.ts
|
|
@@ -226,6 +273,15 @@ declare function parseBoolean(inputString: string): boolean;
|
|
|
226
273
|
/** @deprecated This function has been renamed to parseBoolean. */
|
|
227
274
|
declare const stringToBoolean: typeof parseBoolean;
|
|
228
275
|
//#endregion
|
|
276
|
+
//#region src/functions/parsers/parseEnv.d.ts
|
|
277
|
+
declare const envSchema: z$1.ZodEnum<{
|
|
278
|
+
test: "test";
|
|
279
|
+
development: "development";
|
|
280
|
+
production: "production";
|
|
281
|
+
}>;
|
|
282
|
+
type Env = z$1.infer<typeof envSchema>;
|
|
283
|
+
declare function parseEnv(data: unknown): Env;
|
|
284
|
+
//#endregion
|
|
229
285
|
//#region src/functions/parsers/parseFormData.d.ts
|
|
230
286
|
declare function parseFormData<T>(formData: FormData, dataParser: (data: Record<string, string | Blob>) => T): T;
|
|
231
287
|
declare function parseFormData(formData: FormData): Record<string, string | Blob>;
|
package/dist/index.d.ts
CHANGED
|
@@ -115,21 +115,16 @@ declare class DataError extends Error {
|
|
|
115
115
|
//#endregion
|
|
116
116
|
//#region src/types/Email.d.ts
|
|
117
117
|
declare const emailSchema: z.core.$ZodBranded<z.ZodEmail, "Email">;
|
|
118
|
+
/** @deprecated Please use the inferred type from `z.email() from Zod instead.` */
|
|
118
119
|
type Email = z.infer<typeof emailSchema>;
|
|
120
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
119
121
|
declare function parseEmail(data: unknown): Email;
|
|
120
122
|
//#endregion
|
|
121
|
-
//#region src/types/Env.d.ts
|
|
122
|
-
declare const envSchema: z$1.ZodEnum<{
|
|
123
|
-
test: "test";
|
|
124
|
-
development: "development";
|
|
125
|
-
production: "production";
|
|
126
|
-
}>;
|
|
127
|
-
type Env = z$1.infer<typeof envSchema>;
|
|
128
|
-
declare function parseEnv(data?: unknown): Env;
|
|
129
|
-
//#endregion
|
|
130
123
|
//#region src/types/UUID.d.ts
|
|
131
124
|
declare const uuidSchema: z.core.$ZodBranded<z.ZodUUID, "UUID">;
|
|
125
|
+
/** @deprecated Please use the inferred type from `z.uuid() from Zod instead.` */
|
|
132
126
|
type UUID = z.infer<typeof uuidSchema>;
|
|
127
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
133
128
|
declare function parseUUID(UUID: unknown): UUID;
|
|
134
129
|
//#endregion
|
|
135
130
|
//#region src/types/ArrayElement.d.ts
|
|
@@ -176,21 +171,73 @@ declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, o
|
|
|
176
171
|
declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
|
|
177
172
|
//#endregion
|
|
178
173
|
//#region src/functions/date/addDaysToDate.d.ts
|
|
174
|
+
/**
|
|
175
|
+
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
176
|
+
*
|
|
177
|
+
* @param currentDate - The starting date (defaults to today).
|
|
178
|
+
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
179
|
+
*
|
|
180
|
+
* @returns A new Date instance with the number of days added to the initially provided date.
|
|
181
|
+
*/
|
|
179
182
|
declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
180
183
|
//#endregion
|
|
181
184
|
//#region src/functions/date/formatDateAndTime.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Creates a human-readable string with information about the input date.
|
|
187
|
+
*
|
|
188
|
+
* @param inputDate - The date to base the string on.
|
|
189
|
+
*
|
|
190
|
+
* @returns A new string with information about the given date.
|
|
191
|
+
*
|
|
192
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
193
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
194
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
195
|
+
*/
|
|
182
196
|
declare function formatDateAndTime(inputDate: Date): string;
|
|
183
197
|
//#endregion
|
|
184
198
|
//#region src/functions/date/isAnniversary.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Checks if the provided dates are exactly a whole number of years apart.
|
|
201
|
+
*
|
|
202
|
+
* @param firstDate - The first date to compare.
|
|
203
|
+
* @param secondDate - The second date to compare.
|
|
204
|
+
*
|
|
205
|
+
* @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
|
|
206
|
+
*/
|
|
185
207
|
declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
|
|
186
208
|
//#endregion
|
|
187
209
|
//#region src/functions/date/isLeapYear.d.ts
|
|
210
|
+
/**
|
|
211
|
+
* Checks if the provided year is a leap year.
|
|
212
|
+
*
|
|
213
|
+
* @param year - The year to check as a number.
|
|
214
|
+
*
|
|
215
|
+
* @throws {TypeError} If the year provided is not an integer.
|
|
216
|
+
*
|
|
217
|
+
* @returns True if the year is a leap year, and false otherwise.
|
|
218
|
+
*/
|
|
188
219
|
declare function isLeapYear(year: number): boolean;
|
|
189
220
|
//#endregion
|
|
190
221
|
//#region src/functions/date/isMonthlyMultiple.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Checks if the provided dates are exactly a whole number of months apart.
|
|
224
|
+
*
|
|
225
|
+
* @param firstDate - The first date to compare.
|
|
226
|
+
* @param secondDate - The second date to compare.
|
|
227
|
+
*
|
|
228
|
+
* @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
|
|
229
|
+
*/
|
|
191
230
|
declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
|
|
192
231
|
//#endregion
|
|
193
232
|
//#region src/functions/date/isSameDate.d.ts
|
|
233
|
+
/**
|
|
234
|
+
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
235
|
+
*
|
|
236
|
+
* @param firstDate - The first date to compare.
|
|
237
|
+
* @param secondDate - The second date to compare.
|
|
238
|
+
*
|
|
239
|
+
* @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
|
|
240
|
+
*/
|
|
194
241
|
declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
195
242
|
//#endregion
|
|
196
243
|
//#region src/functions/deepCopy.d.ts
|
|
@@ -226,6 +273,15 @@ declare function parseBoolean(inputString: string): boolean;
|
|
|
226
273
|
/** @deprecated This function has been renamed to parseBoolean. */
|
|
227
274
|
declare const stringToBoolean: typeof parseBoolean;
|
|
228
275
|
//#endregion
|
|
276
|
+
//#region src/functions/parsers/parseEnv.d.ts
|
|
277
|
+
declare const envSchema: z$1.ZodEnum<{
|
|
278
|
+
test: "test";
|
|
279
|
+
development: "development";
|
|
280
|
+
production: "production";
|
|
281
|
+
}>;
|
|
282
|
+
type Env = z$1.infer<typeof envSchema>;
|
|
283
|
+
declare function parseEnv(data: unknown): Env;
|
|
284
|
+
//#endregion
|
|
229
285
|
//#region src/functions/parsers/parseFormData.d.ts
|
|
230
286
|
declare function parseFormData<T>(formData: FormData, dataParser: (data: Record<string, string | Blob>) => T): T;
|
|
231
287
|
declare function parseFormData(formData: FormData): Record<string, string | Blob>;
|
package/dist/index.js
CHANGED
|
@@ -235,8 +235,16 @@ var createTemplateStringsArray_default = createTemplateStringsArray;
|
|
|
235
235
|
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/functions/date/addDaysToDate.ts
|
|
238
|
+
/**
|
|
239
|
+
* Adds a given number of days to the provided date, returning the result as a new instance of Date.
|
|
240
|
+
*
|
|
241
|
+
* @param currentDate - The starting date (defaults to today).
|
|
242
|
+
* @param dayIncrement - The amount of days you want to add (defaults to 1)
|
|
243
|
+
*
|
|
244
|
+
* @returns A new Date instance with the number of days added to the initially provided date.
|
|
245
|
+
*/
|
|
238
246
|
function addDaysToDate(currentDate = /* @__PURE__ */ new Date(), dayIncrement = 1) {
|
|
239
|
-
const newDate = currentDate;
|
|
247
|
+
const newDate = new Date(currentDate);
|
|
240
248
|
newDate.setDate(newDate.getDate() + dayIncrement);
|
|
241
249
|
return newDate;
|
|
242
250
|
}
|
|
@@ -244,6 +252,14 @@ var addDaysToDate_default = addDaysToDate;
|
|
|
244
252
|
|
|
245
253
|
//#endregion
|
|
246
254
|
//#region src/functions/date/isSameDate.ts
|
|
255
|
+
/**
|
|
256
|
+
* Checks if the provided dates happen on the exact same day, month, and year.
|
|
257
|
+
*
|
|
258
|
+
* @param firstDate - The first date to compare.
|
|
259
|
+
* @param secondDate - The second date to compare.
|
|
260
|
+
*
|
|
261
|
+
* @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
|
|
262
|
+
*/
|
|
247
263
|
function isSameDate(firstDate, secondDate) {
|
|
248
264
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth() && firstDate.getFullYear() === secondDate.getFullYear();
|
|
249
265
|
}
|
|
@@ -251,6 +267,17 @@ var isSameDate_default = isSameDate;
|
|
|
251
267
|
|
|
252
268
|
//#endregion
|
|
253
269
|
//#region src/functions/date/formatDateAndTime.ts
|
|
270
|
+
/**
|
|
271
|
+
* Creates a human-readable string with information about the input date.
|
|
272
|
+
*
|
|
273
|
+
* @param inputDate - The date to base the string on.
|
|
274
|
+
*
|
|
275
|
+
* @returns A new string with information about the given date.
|
|
276
|
+
*
|
|
277
|
+
* - If the date given is today, the output will be something like `Today at HH:MM`
|
|
278
|
+
* - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
|
|
279
|
+
* - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
|
|
280
|
+
*/
|
|
254
281
|
function formatDateAndTime(inputDate) {
|
|
255
282
|
const yesterday = addDaysToDate_default(/* @__PURE__ */ new Date(), -1);
|
|
256
283
|
const today = /* @__PURE__ */ new Date();
|
|
@@ -263,6 +290,15 @@ var formatDateAndTime_default = formatDateAndTime;
|
|
|
263
290
|
|
|
264
291
|
//#endregion
|
|
265
292
|
//#region src/functions/date/isLeapYear.ts
|
|
293
|
+
/**
|
|
294
|
+
* Checks if the provided year is a leap year.
|
|
295
|
+
*
|
|
296
|
+
* @param year - The year to check as a number.
|
|
297
|
+
*
|
|
298
|
+
* @throws {TypeError} If the year provided is not an integer.
|
|
299
|
+
*
|
|
300
|
+
* @returns True if the year is a leap year, and false otherwise.
|
|
301
|
+
*/
|
|
266
302
|
function isLeapYear(year) {
|
|
267
303
|
const parsedYear = parseIntStrict_default(`${year}`);
|
|
268
304
|
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
@@ -275,6 +311,14 @@ function checkLeapYear(firstDate, secondDate) {
|
|
|
275
311
|
if (isLeapYear_default(firstDate.getFullYear()) && firstDate.getMonth() === 1 && secondDate.getMonth() === 1) return firstDate.getDate() === 29 && secondDate.getDate() === 28;
|
|
276
312
|
return false;
|
|
277
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Checks if the provided dates are exactly a whole number of years apart.
|
|
316
|
+
*
|
|
317
|
+
* @param firstDate - The first date to compare.
|
|
318
|
+
* @param secondDate - The second date to compare.
|
|
319
|
+
*
|
|
320
|
+
* @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
|
|
321
|
+
*/
|
|
278
322
|
function isAnniversary(firstDate, secondDate) {
|
|
279
323
|
if (checkLeapYear(firstDate, secondDate) || checkLeapYear(secondDate, firstDate)) return true;
|
|
280
324
|
return firstDate.getDate() === secondDate.getDate() && firstDate.getMonth() === secondDate.getMonth();
|
|
@@ -313,6 +357,14 @@ function leapYearFebruaryChecks(firstDate, secondDate) {
|
|
|
313
357
|
}
|
|
314
358
|
return false;
|
|
315
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Checks if the provided dates are exactly a whole number of months apart.
|
|
362
|
+
*
|
|
363
|
+
* @param firstDate - The first date to compare.
|
|
364
|
+
* @param secondDate - The second date to compare.
|
|
365
|
+
*
|
|
366
|
+
* @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
|
|
367
|
+
*/
|
|
316
368
|
function isMonthlyMultiple(firstDate, secondDate) {
|
|
317
369
|
if (endOfMonthChecksButNotFebruary(firstDate, secondDate) || endOfMonthChecksButNotFebruary(secondDate, firstDate)) return true;
|
|
318
370
|
if (nonLeapYearFebruaryChecks(firstDate, secondDate) || nonLeapYearFebruaryChecks(secondDate, firstDate)) return true;
|
|
@@ -429,6 +481,18 @@ function parseBoolean(inputString) {
|
|
|
429
481
|
const stringToBoolean = parseBoolean;
|
|
430
482
|
var parseBoolean_default = parseBoolean;
|
|
431
483
|
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/functions/parsers/parseEnv.ts
|
|
486
|
+
const envSchema = z$1.enum([
|
|
487
|
+
"test",
|
|
488
|
+
"development",
|
|
489
|
+
"production"
|
|
490
|
+
]);
|
|
491
|
+
function parseEnv(data) {
|
|
492
|
+
return envSchema.parse(data);
|
|
493
|
+
}
|
|
494
|
+
var parseEnv_default = parseEnv;
|
|
495
|
+
|
|
432
496
|
//#endregion
|
|
433
497
|
//#region src/functions/parsers/parseFormData.ts
|
|
434
498
|
function parseFormData(formData, dataParser) {
|
|
@@ -498,26 +562,16 @@ var DataError_default = DataError;
|
|
|
498
562
|
//#endregion
|
|
499
563
|
//#region src/types/Email.ts
|
|
500
564
|
const emailSchema = z.email().brand();
|
|
565
|
+
/** @deprecated Please use `z.email().parse() from Zod instead.`*/
|
|
501
566
|
function parseEmail(data) {
|
|
502
567
|
return emailSchema.parse(data);
|
|
503
568
|
}
|
|
504
569
|
var Email_default = parseEmail;
|
|
505
570
|
|
|
506
|
-
//#endregion
|
|
507
|
-
//#region src/types/Env.ts
|
|
508
|
-
const envSchema = z$1.enum([
|
|
509
|
-
"test",
|
|
510
|
-
"development",
|
|
511
|
-
"production"
|
|
512
|
-
]);
|
|
513
|
-
function parseEnv(data = "development") {
|
|
514
|
-
return envSchema.parse(data);
|
|
515
|
-
}
|
|
516
|
-
var Env_default = parseEnv;
|
|
517
|
-
|
|
518
571
|
//#endregion
|
|
519
572
|
//#region src/types/UUID.ts
|
|
520
573
|
const uuidSchema = z.uuid().brand();
|
|
574
|
+
/** @deprecated Please use `z.uuid().parse() from Zod instead.`*/
|
|
521
575
|
function parseUUID(UUID) {
|
|
522
576
|
return uuidSchema.parse(UUID);
|
|
523
577
|
}
|
|
@@ -671,4 +725,4 @@ function wait(seconds) {
|
|
|
671
725
|
var wait_default = wait;
|
|
672
726
|
|
|
673
727
|
//#endregion
|
|
674
|
-
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail,
|
|
728
|
+
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
|