@catbee/utils 2.0.0-next.1 → 2.0.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.
Files changed (87) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +50 -36
  3. package/array/index.cjs +37 -5
  4. package/array/index.d.ts +59 -8
  5. package/array/index.mjs +32 -4
  6. package/async/index.cjs +24 -3
  7. package/async/index.d.ts +18 -2
  8. package/async/index.mjs +24 -4
  9. package/cache/index.cjs +1 -1
  10. package/cache/index.d.ts +1 -1
  11. package/cache/index.mjs +1 -1
  12. package/config/index.cjs +8 -8
  13. package/config/index.d.ts +1 -1
  14. package/config/index.mjs +4 -4
  15. package/context-store/index.cjs +2 -3
  16. package/context-store/index.d.ts +1 -1
  17. package/context-store/index.mjs +2 -3
  18. package/crypto/index.cjs +55 -5
  19. package/crypto/index.d.ts +63 -2
  20. package/crypto/index.mjs +52 -7
  21. package/date/index.cjs +630 -1
  22. package/date/index.d.ts +487 -2
  23. package/date/index.mjs +621 -2
  24. package/{decorators → decorator}/index.cjs +425 -304
  25. package/{decorators → decorator}/index.d.ts +3 -2
  26. package/{decorators → decorator}/index.mjs +425 -304
  27. package/{dir → directory}/index.cjs +1 -1
  28. package/{dir → directory}/index.d.ts +1 -1
  29. package/{dir → directory}/index.mjs +1 -1
  30. package/env/index.cjs +90 -42
  31. package/env/index.d.ts +12 -1
  32. package/env/index.mjs +90 -42
  33. package/exception/index.cjs +1 -1
  34. package/exception/index.d.ts +1 -1
  35. package/exception/index.mjs +1 -1
  36. package/fs/index.cjs +1 -1
  37. package/fs/index.d.ts +1 -1
  38. package/fs/index.mjs +1 -1
  39. package/http-status-codes/index.cjs +1 -1
  40. package/http-status-codes/index.d.ts +1 -1
  41. package/http-status-codes/index.mjs +1 -1
  42. package/id/index.cjs +1 -1
  43. package/id/index.d.ts +1 -1
  44. package/id/index.mjs +1 -1
  45. package/index.cjs +10 -10
  46. package/index.d.ts +4 -4
  47. package/index.mjs +4 -4
  48. package/logger/index.cjs +2 -4
  49. package/logger/index.d.ts +2 -2
  50. package/logger/index.mjs +2 -4
  51. package/middleware/index.cjs +1 -1
  52. package/middleware/index.d.ts +1 -1
  53. package/middleware/index.mjs +1 -1
  54. package/{obj → object}/index.cjs +182 -108
  55. package/{obj → object}/index.d.ts +38 -2
  56. package/{obj → object}/index.mjs +180 -109
  57. package/package.json +31 -13
  58. package/performance/index.cjs +2 -2
  59. package/performance/index.d.ts +1 -1
  60. package/performance/index.mjs +2 -2
  61. package/request/index.cjs +36 -24
  62. package/request/index.d.ts +1 -1
  63. package/request/index.mjs +36 -24
  64. package/response/index.cjs +1 -1
  65. package/response/index.d.ts +1 -1
  66. package/response/index.mjs +1 -1
  67. package/server/index.cjs +230 -131
  68. package/server/index.d.ts +81 -1
  69. package/server/index.mjs +226 -127
  70. package/stream/index.cjs +1 -1
  71. package/stream/index.d.ts +1 -1
  72. package/stream/index.mjs +1 -1
  73. package/string/index.cjs +34 -1
  74. package/string/index.d.ts +45 -2
  75. package/string/index.mjs +31 -2
  76. package/type/index.cjs +18 -1
  77. package/type/index.d.ts +38 -2
  78. package/type/index.mjs +16 -2
  79. package/types/index.cjs +1 -1
  80. package/types/index.d.ts +3 -3
  81. package/types/index.mjs +1 -1
  82. package/url/index.cjs +61 -1
  83. package/url/index.d.ts +59 -2
  84. package/url/index.mjs +57 -2
  85. package/validation/index.cjs +3 -3
  86. package/validation/index.d.ts +1 -1
  87. package/validation/index.mjs +3 -3
package/date/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -209,6 +209,491 @@ declare function parseDuration(value: string | number): number;
209
209
  * ```
210
210
  */
211
211
  declare function getDateFromDuration(input: string): Date;
212
+ /**
213
+ * Checks if a date is on a weekend (Saturday or Sunday).
214
+ *
215
+ * @param {Date | number} date - The date to check.
216
+ * @returns {boolean} True if weekend.
217
+ *
218
+ * @example
219
+ * isWeekend(new Date('2024-01-06')); // true (Saturday)
220
+ */
221
+ declare function isWeekend(date: Date | number): boolean;
222
+ /**
223
+ * Checks if a date is today.
224
+ *
225
+ * @param {Date | number} date - The date to check.
226
+ * @returns {boolean} True if today.
227
+ *
228
+ * @example
229
+ * isToday(new Date()); // true
230
+ */
231
+ declare function isToday(date: Date | number): boolean;
232
+ /**
233
+ * Checks if a date is in the future.
234
+ *
235
+ * @param {Date | number} date - The date to check.
236
+ * @returns {boolean} True if in the future.
237
+ *
238
+ * @example
239
+ * isFuture(new Date('2099-01-01')); // true
240
+ */
241
+ declare function isFuture(date: Date | number): boolean;
242
+ /**
243
+ * Checks if a date is in the past.
244
+ *
245
+ * @param {Date | number} date - The date to check.
246
+ * @returns {boolean} True if in the past.
247
+ *
248
+ * @example
249
+ * isPast(new Date('2020-01-01')); // true
250
+ */
251
+ declare function isPast(date: Date | number): boolean;
252
+ /**
253
+ * Adds days to a date.
254
+ *
255
+ * @param {Date | number} date - The base date.
256
+ * @param {number} days - Number of days to add (can be negative).
257
+ * @returns {Date} New date with days added.
258
+ *
259
+ * @example
260
+ * addDays(new Date('2024-01-15'), 7); // 2024-01-22
261
+ */
262
+ declare function addDays(date: Date | number, days: number): Date;
263
+ /**
264
+ * Adds months to a date.
265
+ *
266
+ * @param {Date | number} date - The base date.
267
+ * @param {number} months - Number of months to add (can be negative).
268
+ * @returns {Date} New date with months added.
269
+ *
270
+ * @example
271
+ * addMonths(new Date('2024-01-31'), 1); // 2024-02-29 (leap year)
272
+ */
273
+ declare function addMonths(date: Date | number, months: number): Date;
274
+ /**
275
+ * Adds years to a date.
276
+ *
277
+ * @param {Date | number} date - The base date.
278
+ * @param {number} years - Number of years to add (can be negative).
279
+ * @returns {Date} New date with years added.
280
+ *
281
+ * @example
282
+ * addYears(new Date('2024-01-15'), 5); // 2029-01-15
283
+ */
284
+ declare function addYears(date: Date | number, years: number): Date;
285
+ /**
286
+ * Gets the quarter of the year for a date (1-4).
287
+ *
288
+ * @param {Date | number} date - The date.
289
+ * @returns {1 | 2 | 3 | 4} Quarter number.
290
+ *
291
+ * @example
292
+ * quarterOf(new Date('2024-03-15')); // 1
293
+ * quarterOf(new Date('2024-07-15')); // 3
294
+ */
295
+ declare function quarterOf(date: Date | number): 1 | 2 | 3 | 4;
296
+ /**
297
+ * Gets the ISO week number of the year for a date.
298
+ *
299
+ * @param {Date | number} date - The date.
300
+ * @returns {number} Week number (1-53).
301
+ *
302
+ * @example
303
+ * weekOfYear(new Date('2024-01-15')); // 3
304
+ */
305
+ declare function weekOfYear(date: Date | number): number;
306
+
307
+ /**
308
+ * DateBuilder class for fluent date manipulation and building.
309
+ * Provides a chainable API similar to Java's date builders.
310
+ * All methods return a new instance, making it immutable.
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // Create a date builder
315
+ * const date = new DateBuilder()
316
+ * .year(2024)
317
+ * .month(5)
318
+ * .day(15)
319
+ * .hour(14)
320
+ * .minute(30)
321
+ * .build();
322
+ *
323
+ * // Chain operations
324
+ * const nextWeek = new DateBuilder()
325
+ * .addDays(7)
326
+ * .startOfDay()
327
+ * .build();
328
+ *
329
+ * // Use with existing date
330
+ * const modified = DateBuilder.from(new Date())
331
+ * .addMonths(2)
332
+ * .endOfMonth()
333
+ * .format('yyyy-MM-dd');
334
+ * ```
335
+ */
336
+ declare class DateBuilder {
337
+ private readonly date;
338
+ /**
339
+ * Creates a new DateBuilder instance.
340
+ * @param date - Initial date (default: current date/time)
341
+ */
342
+ constructor(date?: Date | number | string);
343
+ /**
344
+ * Create a DateBuilder from an existing date.
345
+ * @param date - Date to build from
346
+ */
347
+ static from(date: Date | number | string): DateBuilder;
348
+ /**
349
+ * Create a DateBuilder for the current moment.
350
+ */
351
+ static now(): DateBuilder;
352
+ /**
353
+ * Create a DateBuilder for a specific date.
354
+ * @param year - Year
355
+ * @param month - Month (1-12, not 0-11)
356
+ * @param day - Day of month
357
+ * @param hour - Hour (default: 0)
358
+ * @param minute - Minute (default: 0)
359
+ * @param second - Second (default: 0)
360
+ * @param millisecond - Millisecond (default: 0)
361
+ */
362
+ static of(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number): DateBuilder;
363
+ /**
364
+ * Parse a date string into a DateBuilder.
365
+ * @param dateString - Date string to parse
366
+ */
367
+ static parse(dateString: string): DateBuilder;
368
+ /**
369
+ * Create a DateBuilder from a duration string (e.g., "5m", "2h", "1d" from now).
370
+ * @param duration - Duration string
371
+ */
372
+ static fromDuration(duration: string): DateBuilder;
373
+ /**
374
+ * Clone this DateBuilder instance.
375
+ */
376
+ clone(): DateBuilder;
377
+ /**
378
+ * Set the year.
379
+ * @param year - Year to set
380
+ */
381
+ year(year: number): DateBuilder;
382
+ /**
383
+ * Set the month (1-12, not 0-11).
384
+ * @param month - Month to set (1-12)
385
+ */
386
+ month(month: number): DateBuilder;
387
+ /**
388
+ * Set the day of the month.
389
+ * @param day - Day to set
390
+ */
391
+ day(day: number): DateBuilder;
392
+ /**
393
+ * Set the hour.
394
+ * @param hour - Hour to set
395
+ */
396
+ hour(hour: number): DateBuilder;
397
+ /**
398
+ * Set the minute.
399
+ * @param minute - Minute to set
400
+ */
401
+ minute(minute: number): DateBuilder;
402
+ /**
403
+ * Set the second.
404
+ * @param second - Second to set
405
+ */
406
+ second(second: number): DateBuilder;
407
+ /**
408
+ * Set the millisecond.
409
+ * @param millisecond - Millisecond to set
410
+ */
411
+ millisecond(millisecond: number): DateBuilder;
412
+ /**
413
+ * Add years to the date.
414
+ * @param years - Number of years to add (can be negative)
415
+ */
416
+ addYears(years: number): DateBuilder;
417
+ /**
418
+ * Add months to the date.
419
+ * @param months - Number of months to add (can be negative)
420
+ */
421
+ addMonths(months: number): DateBuilder;
422
+ /**
423
+ * Add days to the date.
424
+ * @param days - Number of days to add (can be negative)
425
+ */
426
+ addDays(days: number): DateBuilder;
427
+ /**
428
+ * Add hours to the date.
429
+ * @param hours - Number of hours to add (can be negative)
430
+ */
431
+ addHours(hours: number): DateBuilder;
432
+ /**
433
+ * Add minutes to the date.
434
+ * @param minutes - Number of minutes to add (can be negative)
435
+ */
436
+ addMinutes(minutes: number): DateBuilder;
437
+ /**
438
+ * Add seconds to the date.
439
+ * @param seconds - Number of seconds to add (can be negative)
440
+ */
441
+ addSeconds(seconds: number): DateBuilder;
442
+ /**
443
+ * Add milliseconds to the date.
444
+ * @param milliseconds - Number of milliseconds to add (can be negative)
445
+ */
446
+ addMilliseconds(milliseconds: number): DateBuilder;
447
+ /**
448
+ * Subtract years from the date.
449
+ * @param years - Number of years to subtract
450
+ */
451
+ subtractYears(years: number): DateBuilder;
452
+ /**
453
+ * Subtract months from the date.
454
+ * @param months - Number of months to subtract
455
+ */
456
+ subtractMonths(months: number): DateBuilder;
457
+ /**
458
+ * Subtract days from the date.
459
+ * @param days - Number of days to subtract
460
+ */
461
+ subtractDays(days: number): DateBuilder;
462
+ /**
463
+ * Subtract hours from the date.
464
+ * @param hours - Number of hours to subtract
465
+ */
466
+ subtractHours(hours: number): DateBuilder;
467
+ /**
468
+ * Subtract minutes from the date.
469
+ * @param minutes - Number of minutes to subtract
470
+ */
471
+ subtractMinutes(minutes: number): DateBuilder;
472
+ /**
473
+ * Subtract seconds from the date.
474
+ * @param seconds - Number of seconds to subtract
475
+ */
476
+ subtractSeconds(seconds: number): DateBuilder;
477
+ /**
478
+ * Set to the start of the second.
479
+ */
480
+ startOfSecond(): DateBuilder;
481
+ /**
482
+ * Set to the start of the minute.
483
+ */
484
+ startOfMinute(): DateBuilder;
485
+ /**
486
+ * Set to the start of the hour.
487
+ */
488
+ startOfHour(): DateBuilder;
489
+ /**
490
+ * Set to the start of the day (midnight).
491
+ */
492
+ startOfDay(): DateBuilder;
493
+ /**
494
+ * Set to the start of the week (Sunday).
495
+ */
496
+ startOfWeek(): DateBuilder;
497
+ /**
498
+ * Set to the start of the month.
499
+ */
500
+ startOfMonth(): DateBuilder;
501
+ /**
502
+ * Set to the start of the quarter.
503
+ */
504
+ startOfQuarter(): DateBuilder;
505
+ /**
506
+ * Set to the start of the year.
507
+ */
508
+ startOfYear(): DateBuilder;
509
+ /**
510
+ * Set to the end of the second.
511
+ */
512
+ endOfSecond(): DateBuilder;
513
+ /**
514
+ * Set to the end of the minute.
515
+ */
516
+ endOfMinute(): DateBuilder;
517
+ /**
518
+ * Set to the end of the hour.
519
+ */
520
+ endOfHour(): DateBuilder;
521
+ /**
522
+ * Set to the end of the day (23:59:59.999).
523
+ */
524
+ endOfDay(): DateBuilder;
525
+ /**
526
+ * Set to the end of the week (Saturday).
527
+ */
528
+ endOfWeek(): DateBuilder;
529
+ /**
530
+ * Set to the end of the month.
531
+ */
532
+ endOfMonth(): DateBuilder;
533
+ /**
534
+ * Set to the end of the quarter.
535
+ */
536
+ endOfQuarter(): DateBuilder;
537
+ /**
538
+ * Set to the end of the year.
539
+ */
540
+ endOfYear(): DateBuilder;
541
+ /**
542
+ * Check if the date is before another date.
543
+ * @param other - Date to compare with
544
+ */
545
+ isBefore(other: Date | DateBuilder): boolean;
546
+ /**
547
+ * Check if the date is after another date.
548
+ * @param other - Date to compare with
549
+ */
550
+ isAfter(other: Date | DateBuilder): boolean;
551
+ /**
552
+ * Check if the date is the same as another date.
553
+ * @param other - Date to compare with
554
+ */
555
+ isSame(other: Date | DateBuilder): boolean;
556
+ /**
557
+ * Check if the date is between two dates.
558
+ * @param start - Start date
559
+ * @param end - End date
560
+ * @param inclusive - Whether to include boundaries
561
+ */
562
+ isBetween(start: Date | DateBuilder, end: Date | DateBuilder, inclusive?: boolean): boolean;
563
+ /**
564
+ * Check if the date is today.
565
+ */
566
+ isToday(): boolean;
567
+ /**
568
+ * Check if the date is in the future.
569
+ */
570
+ isFuture(): boolean;
571
+ /**
572
+ * Check if the date is in the past.
573
+ */
574
+ isPast(): boolean;
575
+ /**
576
+ * Check if the date is on a weekend.
577
+ */
578
+ isWeekend(): boolean;
579
+ /**
580
+ * Check if the year is a leap year.
581
+ */
582
+ isLeapYear(): boolean;
583
+ /**
584
+ * Get the year.
585
+ */
586
+ getYear(): number;
587
+ /**
588
+ * Get the month (1-12, not 0-11).
589
+ */
590
+ getMonth(): number;
591
+ /**
592
+ * Get the day of the month.
593
+ */
594
+ getDay(): number;
595
+ /**
596
+ * Get the day of the week (0-6, Sunday is 0).
597
+ */
598
+ getDayOfWeek(): number;
599
+ /**
600
+ * Get the hour.
601
+ */
602
+ getHour(): number;
603
+ /**
604
+ * Get the minute.
605
+ */
606
+ getMinute(): number;
607
+ /**
608
+ * Get the second.
609
+ */
610
+ getSecond(): number;
611
+ /**
612
+ * Get the millisecond.
613
+ */
614
+ getMillisecond(): number;
615
+ /**
616
+ * Get the quarter (1-4).
617
+ */
618
+ getQuarter(): 1 | 2 | 3 | 4;
619
+ /**
620
+ * Get the ISO week number.
621
+ */
622
+ getWeekOfYear(): number;
623
+ /**
624
+ * Get the number of days in the current month.
625
+ */
626
+ getDaysInMonth(): number;
627
+ /**
628
+ * Get the Unix timestamp in milliseconds.
629
+ */
630
+ getTime(): number;
631
+ /**
632
+ * Get the Unix timestamp in seconds.
633
+ */
634
+ getUnixTimestamp(): number;
635
+ /**
636
+ * Calculate the difference from another date.
637
+ * @param other - Date to compare with
638
+ * @param unit - Unit of time
639
+ */
640
+ diff(other: Date | DateBuilder, unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
641
+ /**
642
+ * Get the difference from now.
643
+ * @param unit - Unit of time
644
+ */
645
+ diffFromNow(unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
646
+ /**
647
+ * Format the date.
648
+ * @param options - Formatting options
649
+ */
650
+ format(options?: DateFormatOptions | string): string;
651
+ /**
652
+ * Format as relative time (e.g., "5 minutes ago").
653
+ * @param locale - Locale for formatting
654
+ */
655
+ formatRelative(locale?: string | string[]): string;
656
+ /**
657
+ * Format as ISO 8601 string.
658
+ */
659
+ toISOString(): string;
660
+ /**
661
+ * Format as UTC string.
662
+ */
663
+ toUTCString(): string;
664
+ /**
665
+ * Format as date string.
666
+ */
667
+ toDateString(): string;
668
+ /**
669
+ * Format as time string.
670
+ */
671
+ toTimeString(): string;
672
+ /**
673
+ * Format as locale string.
674
+ */
675
+ toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
676
+ /**
677
+ * Convert to JSON string.
678
+ */
679
+ toJSON(): string;
680
+ /**
681
+ * Build and return the Date object.
682
+ */
683
+ build(): Date;
684
+ /**
685
+ * Get the Date object (alias for build).
686
+ */
687
+ toDate(): Date;
688
+ /**
689
+ * Get the internal Date object value.
690
+ */
691
+ valueOf(): number;
692
+ /**
693
+ * Convert to string.
694
+ */
695
+ toString(): string;
696
+ }
212
697
 
213
- export { addToDate, dateDiff, daysInMonth, endOf, formatDate, formatDuration, formatRelativeTime, getDateFromDuration, isBetween, isLeapYear, parseDate, parseDuration, startOf };
698
+ export { DateBuilder, addDays, addMonths, addToDate, addYears, dateDiff, daysInMonth, endOf, formatDate, formatDuration, formatRelativeTime, getDateFromDuration, isBetween, isFuture, isLeapYear, isPast, isToday, isWeekend, parseDate, parseDuration, quarterOf, startOf, weekOfYear };
214
699
  export type { DateFormatOptions };