date-limits
Version:
Check if a date is before a flexible limit.
49 lines (48 loc) • 1.85 kB
TypeScript
import { Range, RequiredAtLeastOne } from './_internal-types';
/**
* Configuration object for checking dates based on various criteria.
*/
export interface DateMatchesConfig {
/**
* Configuration for checking years.
*/
year?: DateMatchesPartConfig;
/**
* Configuration for checking months (1-12).
*/
month?: DateMatchesPartConfig;
/**
* Configuration for checking days of the month (1-31).
*/
day?: DateMatchesPartConfig;
/**
* Configuration for checking weekdays (0-7, where 0 and 7 are Sunday).
*/
weekday?: DateMatchesPartConfig;
}
type DateMatchesConfigAny = undefined;
type DateMatchesConfigStatic = number;
type DateMatchesConfigList = number[] | Set<number>;
type DateMatchesConfigNSeries = {
slope: number;
offset?: number;
};
type DateMatchesConfigRange = RequiredAtLeastOne<Range<number>>;
/**
* Represents a part of the date selector configuration, which can take various forms:
* - `undefined`: Matches any value.
* - `number`: Matches an exact value.
* - `number[]` or `Set<number>`: Matches any value in the list or set.
* - `{ slope: number, offset?: number }`: Matches values in an arithmetic sequence.
* - `Range<number>`: Matches values within a specific range.
*/
export type DateMatchesPartConfig = DateMatchesConfigAny | DateMatchesConfigStatic | DateMatchesConfigList | DateMatchesConfigNSeries | DateMatchesConfigRange;
/**
* Determines if a given date matches the criteria specified in the configuration.
*
* @param date - The date to check.
* @param config - The configuration object defining the criteria.
* @returns `true` if the date matches the criteria, otherwise `false`.
*/
export declare function checkDateMatches(date: Date, config: DateMatchesConfig): boolean;
export {};