@alextheman/utility 3.5.9 → 3.5.10

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 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;
package/dist/index.d.cts CHANGED
@@ -176,21 +176,73 @@ declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, o
176
176
  declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
177
177
  //#endregion
178
178
  //#region src/functions/date/addDaysToDate.d.ts
179
+ /**
180
+ * Adds a given number of days to the provided date, returning the result as a new instance of Date.
181
+ *
182
+ * @param currentDate - The starting date (defaults to today).
183
+ * @param dayIncrement - The amount of days you want to add (defaults to 1)
184
+ *
185
+ * @returns A new Date instance with the number of days added to the initially provided date.
186
+ */
179
187
  declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
180
188
  //#endregion
181
189
  //#region src/functions/date/formatDateAndTime.d.ts
190
+ /**
191
+ * Creates a human-readable string with information about the input date.
192
+ *
193
+ * @param inputDate - The date to base the string on.
194
+ *
195
+ * @returns A new string with information about the given date.
196
+ *
197
+ * - If the date given is today, the output will be something like `Today at HH:MM`
198
+ * - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
199
+ * - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
200
+ */
182
201
  declare function formatDateAndTime(inputDate: Date): string;
183
202
  //#endregion
184
203
  //#region src/functions/date/isAnniversary.d.ts
204
+ /**
205
+ * Checks if the provided dates are exactly a whole number of years apart.
206
+ *
207
+ * @param firstDate - The first date to compare.
208
+ * @param secondDate - The second date to compare.
209
+ *
210
+ * @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
211
+ */
185
212
  declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
186
213
  //#endregion
187
214
  //#region src/functions/date/isLeapYear.d.ts
215
+ /**
216
+ * Checks if the provided year is a leap year.
217
+ *
218
+ * @param year - The year to check as a number.
219
+ *
220
+ * @throws {TypeError} If the year provided is not an integer.
221
+ *
222
+ * @returns True if the year is a leap year, and false otherwise.
223
+ */
188
224
  declare function isLeapYear(year: number): boolean;
189
225
  //#endregion
190
226
  //#region src/functions/date/isMonthlyMultiple.d.ts
227
+ /**
228
+ * Checks if the provided dates are exactly a whole number of months apart.
229
+ *
230
+ * @param firstDate - The first date to compare.
231
+ * @param secondDate - The second date to compare.
232
+ *
233
+ * @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
234
+ */
191
235
  declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
192
236
  //#endregion
193
237
  //#region src/functions/date/isSameDate.d.ts
238
+ /**
239
+ * Checks if the provided dates happen on the exact same day, month, and year.
240
+ *
241
+ * @param firstDate - The first date to compare.
242
+ * @param secondDate - The second date to compare.
243
+ *
244
+ * @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
245
+ */
194
246
  declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
195
247
  //#endregion
196
248
  //#region src/functions/deepCopy.d.ts
package/dist/index.d.ts CHANGED
@@ -176,21 +176,73 @@ declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, o
176
176
  declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
177
177
  //#endregion
178
178
  //#region src/functions/date/addDaysToDate.d.ts
179
+ /**
180
+ * Adds a given number of days to the provided date, returning the result as a new instance of Date.
181
+ *
182
+ * @param currentDate - The starting date (defaults to today).
183
+ * @param dayIncrement - The amount of days you want to add (defaults to 1)
184
+ *
185
+ * @returns A new Date instance with the number of days added to the initially provided date.
186
+ */
179
187
  declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
180
188
  //#endregion
181
189
  //#region src/functions/date/formatDateAndTime.d.ts
190
+ /**
191
+ * Creates a human-readable string with information about the input date.
192
+ *
193
+ * @param inputDate - The date to base the string on.
194
+ *
195
+ * @returns A new string with information about the given date.
196
+ *
197
+ * - If the date given is today, the output will be something like `Today at HH:MM`
198
+ * - If the date given happened yesterday, the output will be something like `Yesterday at HH:MM`
199
+ * - For any other date, the output will be something like `DD/MM/YYYY, HH:MM`
200
+ */
182
201
  declare function formatDateAndTime(inputDate: Date): string;
183
202
  //#endregion
184
203
  //#region src/functions/date/isAnniversary.d.ts
204
+ /**
205
+ * Checks if the provided dates are exactly a whole number of years apart.
206
+ *
207
+ * @param firstDate - The first date to compare.
208
+ * @param secondDate - The second date to compare.
209
+ *
210
+ * @returns True if the provided dates are exactly a whole number of years apart, and false otherwise.
211
+ */
185
212
  declare function isAnniversary(firstDate: Date, secondDate: Date): boolean;
186
213
  //#endregion
187
214
  //#region src/functions/date/isLeapYear.d.ts
215
+ /**
216
+ * Checks if the provided year is a leap year.
217
+ *
218
+ * @param year - The year to check as a number.
219
+ *
220
+ * @throws {TypeError} If the year provided is not an integer.
221
+ *
222
+ * @returns True if the year is a leap year, and false otherwise.
223
+ */
188
224
  declare function isLeapYear(year: number): boolean;
189
225
  //#endregion
190
226
  //#region src/functions/date/isMonthlyMultiple.d.ts
227
+ /**
228
+ * Checks if the provided dates are exactly a whole number of months apart.
229
+ *
230
+ * @param firstDate - The first date to compare.
231
+ * @param secondDate - The second date to compare.
232
+ *
233
+ * @returns True if the provided dates are exactly a whole number of months apart, and false otherwise.
234
+ */
191
235
  declare function isMonthlyMultiple(firstDate: Date, secondDate: Date): boolean;
192
236
  //#endregion
193
237
  //#region src/functions/date/isSameDate.d.ts
238
+ /**
239
+ * Checks if the provided dates happen on the exact same day, month, and year.
240
+ *
241
+ * @param firstDate - The first date to compare.
242
+ * @param secondDate - The second date to compare.
243
+ *
244
+ * @returns True if the provided dates occur on exactly the same day, month, and year, and returns false otherwise.
245
+ */
194
246
  declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
195
247
  //#endregion
196
248
  //#region src/functions/deepCopy.d.ts
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "3.5.9",
3
+ "version": "3.5.10",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",