Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+16
View File
@@ -0,0 +1,16 @@
import { type DateLib } from "../classes/DateLib.js";
import type { DateRange } from "../types/index.js";
/**
* Adds a date to an existing range, considering constraints like minimum and
* maximum range size.
*
* @param date - The date to add to the range.
* @param initialRange - The initial range to which the date will be added.
* @param min - The minimum number of days in the range.
* @param max - The maximum number of days in the range.
* @param required - Whether the range must always include at least one date.
* @param dateLib - The date utility library instance.
* @returns The updated date range, or `undefined` if the range is cleared.
* @group Utilities
*/
export declare function addToRange(date: Date, initialRange: DateRange | undefined, min?: number, max?: number, required?: boolean, dateLib?: DateLib): DateRange | undefined;
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addToRange = addToRange;
const DateLib_js_1 = require("../classes/DateLib.js");
/**
* Adds a date to an existing range, considering constraints like minimum and
* maximum range size.
*
* @param date - The date to add to the range.
* @param initialRange - The initial range to which the date will be added.
* @param min - The minimum number of days in the range.
* @param max - The maximum number of days in the range.
* @param required - Whether the range must always include at least one date.
* @param dateLib - The date utility library instance.
* @returns The updated date range, or `undefined` if the range is cleared.
* @group Utilities
*/
function addToRange(date, initialRange, min = 0, max = 0, required = false, dateLib = DateLib_js_1.defaultDateLib) {
const { from, to } = initialRange || {};
const { isSameDay, isAfter, isBefore } = dateLib;
let range;
if (!from && !to) {
// the range is empty, add the date
range = { from: date, to: min > 0 ? undefined : date };
}
else if (from && !to) {
// adding date to an incomplete range
if (isSameDay(from, date)) {
// adding a date equal to the start of the range
if (min === 0) {
range = { from, to: date };
}
else if (required) {
range = { from, to: undefined };
}
else {
range = undefined;
}
}
else if (isBefore(date, from)) {
// adding a date before the start of the range
range = { from: date, to: from };
}
else {
// adding a date after the start of the range
range = { from, to: date };
}
}
else if (from && to) {
// adding date to a complete range
if (isSameDay(from, date) && isSameDay(to, date)) {
// adding a date that is equal to both start and end of the range
if (required) {
range = { from, to };
}
else {
range = undefined;
}
}
else if (isSameDay(from, date)) {
// adding a date equal to the the start of the range
range = { from, to: min > 0 ? undefined : date };
}
else if (isSameDay(to, date)) {
// adding a dare equal to the end of the range
range = { from: date, to: min > 0 ? undefined : date };
}
else if (isBefore(date, from)) {
// adding a date before the start of the range
range = { from: date, to: to };
}
else if (isAfter(date, from)) {
// adding a date after the start of the range
range = { from, to: date };
}
else if (isAfter(date, to)) {
// adding a date after the end of the range
range = { from, to: date };
}
else {
throw new Error("Invalid range");
}
}
// check for min / max
if (range?.from && range?.to) {
const diff = dateLib.differenceInCalendarDays(range.to, range.from);
if (max > 0 && diff > max) {
range = { from: date, to: undefined };
}
else if (min > 1 && diff < min) {
range = { from: date, to: undefined };
}
}
return range;
}
@@ -0,0 +1,10 @@
import type { Matcher } from "../types/index.js";
/**
* Convert any {@link Matcher} or array of matchers to the specified time zone.
*
* @param matchers - The matcher or matchers to convert.
* @param timeZone - The target IANA time zone.
* @returns The converted matcher(s).
* @group Utilities
*/
export declare function convertMatchersToTimeZone(matchers: Matcher | Matcher[] | undefined, timeZone: string, noonSafe?: boolean): Matcher | Matcher[] | undefined;
@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertMatchersToTimeZone = convertMatchersToTimeZone;
const tz_1 = require("@date-fns/tz");
const toTimeZone_js_1 = require("./toTimeZone.js");
const typeguards_js_1 = require("./typeguards.js");
function toZoneNoon(date, timeZone, noonSafe) {
if (!noonSafe)
return (0, toTimeZone_js_1.toTimeZone)(date, timeZone);
const zoned = (0, toTimeZone_js_1.toTimeZone)(date, timeZone);
const noonZoned = new tz_1.TZDate(zoned.getFullYear(), zoned.getMonth(), zoned.getDate(), 12, 0, 0, timeZone);
return new Date(noonZoned.getTime());
}
function convertMatcher(matcher, timeZone, noonSafe) {
if (typeof matcher === "boolean" || typeof matcher === "function") {
return matcher;
}
if (matcher instanceof Date) {
return toZoneNoon(matcher, timeZone, noonSafe);
}
if (Array.isArray(matcher)) {
return matcher.map((value) => value instanceof Date ? toZoneNoon(value, timeZone, noonSafe) : value);
}
if ((0, typeguards_js_1.isDateRange)(matcher)) {
return {
...matcher,
from: matcher.from ? (0, toTimeZone_js_1.toTimeZone)(matcher.from, timeZone) : matcher.from,
to: matcher.to ? (0, toTimeZone_js_1.toTimeZone)(matcher.to, timeZone) : matcher.to,
};
}
if ((0, typeguards_js_1.isDateInterval)(matcher)) {
return {
before: toZoneNoon(matcher.before, timeZone, noonSafe),
after: toZoneNoon(matcher.after, timeZone, noonSafe),
};
}
if ((0, typeguards_js_1.isDateAfterType)(matcher)) {
return {
after: toZoneNoon(matcher.after, timeZone, noonSafe),
};
}
if ((0, typeguards_js_1.isDateBeforeType)(matcher)) {
return {
before: toZoneNoon(matcher.before, timeZone, noonSafe),
};
}
return matcher;
}
/**
* Convert any {@link Matcher} or array of matchers to the specified time zone.
*
* @param matchers - The matcher or matchers to convert.
* @param timeZone - The target IANA time zone.
* @returns The converted matcher(s).
* @group Utilities
*/
function convertMatchersToTimeZone(matchers, timeZone, noonSafe) {
if (!matchers) {
return matchers;
}
if (Array.isArray(matchers)) {
return matchers.map((matcher) => convertMatcher(matcher, timeZone, noonSafe));
}
return convertMatcher(matchers, timeZone, noonSafe);
}
+17
View File
@@ -0,0 +1,17 @@
import { type DateLib } from "../classes/DateLib.js";
import type { Matcher } from "../types/index.js";
/**
* Checks if a given date matches at least one of the specified {@link Matcher}.
*
* @param date - The date to check.
* @param matchers - The matchers to check against.
* @param dateLib - The date utility library instance.
* @returns `true` if the date matches any of the matchers, otherwise `false`.
* @group Utilities
*/
export declare function dateMatchModifiers(date: Date, matchers: Matcher | Matcher[], dateLib?: DateLib): boolean;
/**
* @private
* @deprecated Use {@link dateMatchModifiers} instead.
*/
export declare const isMatch: typeof dateMatchModifiers;
+68
View File
@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMatch = void 0;
exports.dateMatchModifiers = dateMatchModifiers;
const DateLib_js_1 = require("../classes/DateLib.js");
const rangeIncludesDate_js_1 = require("./rangeIncludesDate.js");
const typeguards_js_1 = require("./typeguards.js");
/**
* Checks if a given date matches at least one of the specified {@link Matcher}.
*
* @param date - The date to check.
* @param matchers - The matchers to check against.
* @param dateLib - The date utility library instance.
* @returns `true` if the date matches any of the matchers, otherwise `false`.
* @group Utilities
*/
function dateMatchModifiers(date, matchers, dateLib = DateLib_js_1.defaultDateLib) {
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
const { isSameDay, differenceInCalendarDays, isAfter } = dateLib;
return matchersArr.some((matcher) => {
if (typeof matcher === "boolean") {
return matcher;
}
if (dateLib.isDate(matcher)) {
return isSameDay(date, matcher);
}
if ((0, typeguards_js_1.isDatesArray)(matcher, dateLib)) {
return matcher.some((matcherDate) => isSameDay(date, matcherDate));
}
if ((0, typeguards_js_1.isDateRange)(matcher)) {
return (0, rangeIncludesDate_js_1.rangeIncludesDate)(matcher, date, false, dateLib);
}
if ((0, typeguards_js_1.isDayOfWeekType)(matcher)) {
if (!Array.isArray(matcher.dayOfWeek)) {
return matcher.dayOfWeek === date.getDay();
}
return matcher.dayOfWeek.includes(date.getDay());
}
if ((0, typeguards_js_1.isDateInterval)(matcher)) {
const diffBefore = differenceInCalendarDays(matcher.before, date);
const diffAfter = differenceInCalendarDays(matcher.after, date);
const isDayBefore = diffBefore > 0;
const isDayAfter = diffAfter < 0;
const isClosedInterval = isAfter(matcher.before, matcher.after);
if (isClosedInterval) {
return isDayAfter && isDayBefore;
}
else {
return isDayBefore || isDayAfter;
}
}
if ((0, typeguards_js_1.isDateAfterType)(matcher)) {
return differenceInCalendarDays(date, matcher.after) > 0;
}
if ((0, typeguards_js_1.isDateBeforeType)(matcher)) {
return differenceInCalendarDays(matcher.before, date) > 0;
}
if (typeof matcher === "function") {
return matcher(date);
}
return false;
});
}
/**
* @private
* @deprecated Use {@link dateMatchModifiers} instead.
*/
exports.isMatch = dateMatchModifiers;
+7
View File
@@ -0,0 +1,7 @@
export * from "./addToRange.js";
export * from "./dateMatchModifiers.js";
export * from "./rangeContainsDayOfWeek.js";
export * from "./rangeContainsModifiers.js";
export * from "./rangeIncludesDate.js";
export * from "./rangeOverlaps.js";
export * from "./typeguards.js";
+23
View File
@@ -0,0 +1,23 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./addToRange.js"), exports);
__exportStar(require("./dateMatchModifiers.js"), exports);
__exportStar(require("./rangeContainsDayOfWeek.js"), exports);
__exportStar(require("./rangeContainsModifiers.js"), exports);
__exportStar(require("./rangeIncludesDate.js"), exports);
__exportStar(require("./rangeOverlaps.js"), exports);
__exportStar(require("./typeguards.js"), exports);
@@ -0,0 +1,17 @@
import { type DateLib } from "../classes/DateLib.js";
/**
* Checks if a date range contains one or more specified days of the week.
*
* @since 9.2.2
* @param range - The date range to check.
* @param dayOfWeek - The day(s) of the week to check for (`0-6`, where `0` is
* Sunday).
* @param dateLib - The date utility library instance.
* @returns `true` if the range contains the specified day(s) of the week,
* otherwise `false`.
* @group Utilities
*/
export declare function rangeContainsDayOfWeek(range: {
from: Date;
to: Date;
}, dayOfWeek: number | number[], dateLib?: DateLib): boolean;
+30
View File
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rangeContainsDayOfWeek = rangeContainsDayOfWeek;
const DateLib_js_1 = require("../classes/DateLib.js");
/**
* Checks if a date range contains one or more specified days of the week.
*
* @since 9.2.2
* @param range - The date range to check.
* @param dayOfWeek - The day(s) of the week to check for (`0-6`, where `0` is
* Sunday).
* @param dateLib - The date utility library instance.
* @returns `true` if the range contains the specified day(s) of the week,
* otherwise `false`.
* @group Utilities
*/
function rangeContainsDayOfWeek(range, dayOfWeek, dateLib = DateLib_js_1.defaultDateLib) {
const dayOfWeekArr = !Array.isArray(dayOfWeek) ? [dayOfWeek] : dayOfWeek;
let date = range.from;
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
// iterate at maximum one week or the total days if the range is shorter than one week
const totalDaysLimit = Math.min(totalDays, 6);
for (let i = 0; i <= totalDaysLimit; i++) {
if (dayOfWeekArr.includes(date.getDay())) {
return true;
}
date = dateLib.addDays(date, 1);
}
return false;
}
@@ -0,0 +1,16 @@
import { type DateLib } from "../classes/DateLib.js";
import type { Matcher } from "../types/index.js";
/**
* Checks if a date range contains dates that match the given modifiers.
*
* @since 9.2.2
* @param range - The date range to check.
* @param modifiers - The modifiers to match against.
* @param dateLib - The date utility library instance.
* @returns `true` if the range contains matching dates, otherwise `false`.
* @group Utilities
*/
export declare function rangeContainsModifiers(range: {
from: Date;
to: Date;
}, modifiers: Matcher | Matcher[], dateLib?: DateLib): boolean;
+74
View File
@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rangeContainsModifiers = rangeContainsModifiers;
const DateLib_js_1 = require("../classes/DateLib.js");
const dateMatchModifiers_js_1 = require("./dateMatchModifiers.js");
const rangeContainsDayOfWeek_js_1 = require("./rangeContainsDayOfWeek.js");
const rangeIncludesDate_js_1 = require("./rangeIncludesDate.js");
const rangeOverlaps_js_1 = require("./rangeOverlaps.js");
const typeguards_js_1 = require("./typeguards.js");
/**
* Checks if a date range contains dates that match the given modifiers.
*
* @since 9.2.2
* @param range - The date range to check.
* @param modifiers - The modifiers to match against.
* @param dateLib - The date utility library instance.
* @returns `true` if the range contains matching dates, otherwise `false`.
* @group Utilities
*/
function rangeContainsModifiers(range, modifiers, dateLib = DateLib_js_1.defaultDateLib) {
const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
// Defer function matchers evaluation as they are the least performant.
const nonFunctionMatchers = matchers.filter((matcher) => typeof matcher !== "function");
const nonFunctionMatchersResult = nonFunctionMatchers.some((matcher) => {
if (typeof matcher === "boolean")
return matcher;
if (dateLib.isDate(matcher)) {
return (0, rangeIncludesDate_js_1.rangeIncludesDate)(range, matcher, false, dateLib);
}
if ((0, typeguards_js_1.isDatesArray)(matcher, dateLib)) {
return matcher.some((date) => (0, rangeIncludesDate_js_1.rangeIncludesDate)(range, date, false, dateLib));
}
if ((0, typeguards_js_1.isDateRange)(matcher)) {
if (matcher.from && matcher.to) {
return (0, rangeOverlaps_js_1.rangeOverlaps)(range, { from: matcher.from, to: matcher.to }, dateLib);
}
return false;
}
if ((0, typeguards_js_1.isDayOfWeekType)(matcher)) {
return (0, rangeContainsDayOfWeek_js_1.rangeContainsDayOfWeek)(range, matcher.dayOfWeek, dateLib);
}
if ((0, typeguards_js_1.isDateInterval)(matcher)) {
const isClosedInterval = dateLib.isAfter(matcher.before, matcher.after);
if (isClosedInterval) {
return (0, rangeOverlaps_js_1.rangeOverlaps)(range, {
from: dateLib.addDays(matcher.after, 1),
to: dateLib.addDays(matcher.before, -1),
}, dateLib);
}
return ((0, dateMatchModifiers_js_1.dateMatchModifiers)(range.from, matcher, dateLib) ||
(0, dateMatchModifiers_js_1.dateMatchModifiers)(range.to, matcher, dateLib));
}
if ((0, typeguards_js_1.isDateAfterType)(matcher) || (0, typeguards_js_1.isDateBeforeType)(matcher)) {
return ((0, dateMatchModifiers_js_1.dateMatchModifiers)(range.from, matcher, dateLib) ||
(0, dateMatchModifiers_js_1.dateMatchModifiers)(range.to, matcher, dateLib));
}
return false;
});
if (nonFunctionMatchersResult) {
return true;
}
const functionMatchers = matchers.filter((matcher) => typeof matcher === "function");
if (functionMatchers.length) {
let date = range.from;
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
for (let i = 0; i <= totalDays; i++) {
if (functionMatchers.some((matcher) => matcher(date))) {
return true;
}
date = dateLib.addDays(date, 1);
}
}
return false;
}
+18
View File
@@ -0,0 +1,18 @@
import type { DateRange } from "../types/index.js";
/**
* Checks if a given date is within a specified date range.
*
* @since 9.0.0
* @param range - The date range to check against.
* @param date - The date to check.
* @param excludeEnds - If `true`, the range's start and end dates are excluded.
* @param dateLib - The date utility library instance.
* @returns `true` if the date is within the range, otherwise `false`.
* @group Utilities
*/
export declare function rangeIncludesDate(range: DateRange, date: Date, excludeEnds?: boolean, dateLib?: import("../classes/DateLib.js").DateLib): boolean;
/**
* @private
* @deprecated Use {@link rangeIncludesDate} instead.
*/
export declare const isDateInRange: (range: DateRange, date: Date) => boolean;
+42
View File
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDateInRange = void 0;
exports.rangeIncludesDate = rangeIncludesDate;
const index_js_1 = require("../classes/index.js");
/**
* Checks if a given date is within a specified date range.
*
* @since 9.0.0
* @param range - The date range to check against.
* @param date - The date to check.
* @param excludeEnds - If `true`, the range's start and end dates are excluded.
* @param dateLib - The date utility library instance.
* @returns `true` if the date is within the range, otherwise `false`.
* @group Utilities
*/
function rangeIncludesDate(range, date, excludeEnds = false, dateLib = index_js_1.defaultDateLib) {
let { from, to } = range;
const { differenceInCalendarDays, isSameDay } = dateLib;
if (from && to) {
const isRangeInverted = differenceInCalendarDays(to, from) < 0;
if (isRangeInverted) {
[from, to] = [to, from];
}
const isInRange = differenceInCalendarDays(date, from) >= (excludeEnds ? 1 : 0) &&
differenceInCalendarDays(to, date) >= (excludeEnds ? 1 : 0);
return isInRange;
}
if (!excludeEnds && to) {
return isSameDay(to, date);
}
if (!excludeEnds && from) {
return isSameDay(from, date);
}
return false;
}
/**
* @private
* @deprecated Use {@link rangeIncludesDate} instead.
*/
const isDateInRange = (range, date) => rangeIncludesDate(range, date, false, index_js_1.defaultDateLib);
exports.isDateInRange = isDateInRange;
+17
View File
@@ -0,0 +1,17 @@
/**
* Determines if two date ranges overlap.
*
* @since 9.2.2
* @param rangeLeft - The first date range.
* @param rangeRight - The second date range.
* @param dateLib - The date utility library instance.
* @returns `true` if the ranges overlap, otherwise `false`.
* @group Utilities
*/
export declare function rangeOverlaps(rangeLeft: {
from: Date;
to: Date;
}, rangeRight: {
from: Date;
to: Date;
}, dateLib?: import("../classes/DateLib.js").DateLib): boolean;
+21
View File
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rangeOverlaps = rangeOverlaps;
const index_js_1 = require("../classes/index.js");
const rangeIncludesDate_js_1 = require("./rangeIncludesDate.js");
/**
* Determines if two date ranges overlap.
*
* @since 9.2.2
* @param rangeLeft - The first date range.
* @param rangeRight - The second date range.
* @param dateLib - The date utility library instance.
* @returns `true` if the ranges overlap, otherwise `false`.
* @group Utilities
*/
function rangeOverlaps(rangeLeft, rangeRight, dateLib = index_js_1.defaultDateLib) {
return ((0, rangeIncludesDate_js_1.rangeIncludesDate)(rangeLeft, rangeRight.from, false, dateLib) ||
(0, rangeIncludesDate_js_1.rangeIncludesDate)(rangeLeft, rangeRight.to, false, dateLib) ||
(0, rangeIncludesDate_js_1.rangeIncludesDate)(rangeRight, rangeLeft.from, false, dateLib) ||
(0, rangeIncludesDate_js_1.rangeIncludesDate)(rangeRight, rangeLeft.to, false, dateLib));
}
+7
View File
@@ -0,0 +1,7 @@
import { TZDate } from "@date-fns/tz";
/**
* Convert a {@link Date} or {@link TZDate} instance to the given time zone.
* Reuses the same instance when it is already a {@link TZDate} using the target
* time zone to avoid extra allocations.
*/
export declare function toTimeZone(date: Date, timeZone: string): TZDate;
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toTimeZone = toTimeZone;
const tz_1 = require("@date-fns/tz");
/**
* Convert a {@link Date} or {@link TZDate} instance to the given time zone.
* Reuses the same instance when it is already a {@link TZDate} using the target
* time zone to avoid extra allocations.
*/
function toTimeZone(date, timeZone) {
if (date instanceof tz_1.TZDate && date.timeZone === timeZone) {
return date;
}
return new tz_1.TZDate(date, timeZone);
}
+51
View File
@@ -0,0 +1,51 @@
import type { DateLib } from "../classes/DateLib.js";
import type { DateAfter, DateBefore, DateInterval, DateRange, DayOfWeek } from "../types/index.js";
/**
* Checks if the given value is of type {@link DateInterval}.
*
* @param matcher - The value to check.
* @returns `true` if the value is a {@link DateInterval}, otherwise `false`.
* @group Utilities
*/
export declare function isDateInterval(matcher: unknown): matcher is DateInterval;
/**
* Checks if the given value is of type {@link DateRange}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateRange}, otherwise `false`.
* @group Utilities
*/
export declare function isDateRange(value: unknown): value is DateRange;
/**
* Checks if the given value is of type {@link DateAfter}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateAfter}, otherwise `false`.
* @group Utilities
*/
export declare function isDateAfterType(value: unknown): value is DateAfter;
/**
* Checks if the given value is of type {@link DateBefore}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateBefore}, otherwise `false`.
* @group Utilities
*/
export declare function isDateBeforeType(value: unknown): value is DateBefore;
/**
* Checks if the given value is of type {@link DayOfWeek}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DayOfWeek}, otherwise `false`.
* @group Utilities
*/
export declare function isDayOfWeekType(value: unknown): value is DayOfWeek;
/**
* Checks if the given value is an array of valid dates.
*
* @private
* @param value - The value to check.
* @param dateLib - The date utility library instance.
* @returns `true` if the value is an array of valid dates, otherwise `false`.
*/
export declare function isDatesArray(value: unknown, dateLib: DateLib): value is Date[];
+72
View File
@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDateInterval = isDateInterval;
exports.isDateRange = isDateRange;
exports.isDateAfterType = isDateAfterType;
exports.isDateBeforeType = isDateBeforeType;
exports.isDayOfWeekType = isDayOfWeekType;
exports.isDatesArray = isDatesArray;
/**
* Checks if the given value is of type {@link DateInterval}.
*
* @param matcher - The value to check.
* @returns `true` if the value is a {@link DateInterval}, otherwise `false`.
* @group Utilities
*/
function isDateInterval(matcher) {
return Boolean(matcher &&
typeof matcher === "object" &&
"before" in matcher &&
"after" in matcher);
}
/**
* Checks if the given value is of type {@link DateRange}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateRange}, otherwise `false`.
* @group Utilities
*/
function isDateRange(value) {
return Boolean(value && typeof value === "object" && "from" in value);
}
/**
* Checks if the given value is of type {@link DateAfter}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateAfter}, otherwise `false`.
* @group Utilities
*/
function isDateAfterType(value) {
return Boolean(value && typeof value === "object" && "after" in value);
}
/**
* Checks if the given value is of type {@link DateBefore}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DateBefore}, otherwise `false`.
* @group Utilities
*/
function isDateBeforeType(value) {
return Boolean(value && typeof value === "object" && "before" in value);
}
/**
* Checks if the given value is of type {@link DayOfWeek}.
*
* @param value - The value to check.
* @returns `true` if the value is a {@link DayOfWeek}, otherwise `false`.
* @group Utilities
*/
function isDayOfWeekType(value) {
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
}
/**
* Checks if the given value is an array of valid dates.
*
* @private
* @param value - The value to check.
* @param dateLib - The date utility library instance.
* @returns `true` if the value is an array of valid dates, otherwise `false`.
*/
function isDatesArray(value, dateLib) {
return Array.isArray(value) && value.every(dateLib.isDate);
}