1 | import type {
|
2 | DateAfter,
|
3 | DateBefore,
|
4 | DateInterval,
|
5 | DateLib,
|
6 | DateRange,
|
7 | DayOfWeek
|
8 | } from "../types/index.js";
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function isDateInterval(matcher: unknown): matcher is DateInterval {
|
16 | return Boolean(
|
17 | matcher &&
|
18 | typeof matcher === "object" &&
|
19 | "before" in matcher &&
|
20 | "after" in matcher
|
21 | );
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export function isDateRange(value: unknown): value is DateRange {
|
30 | return Boolean(value && typeof value === "object" && "from" in value);
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export function isDateAfterType(value: unknown): value is DateAfter {
|
39 | return Boolean(value && typeof value === "object" && "after" in value);
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export function isDateBeforeType(value: unknown): value is DateBefore {
|
48 | return Boolean(value && typeof value === "object" && "before" in value);
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | export function isDayOfWeekType(value: unknown): value is DayOfWeek {
|
57 | return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
58 | }
|
59 |
|
60 |
|
61 | export function isDatesArray(
|
62 | value: unknown,
|
63 | dateLib: DateLib
|
64 | ): value is Date[] {
|
65 | return Array.isArray(value) && value.every(dateLib.isDate);
|
66 | }
|