ts-valid8
Version:
A next-generation TypeScript validation library with advanced features
147 lines • 4.8 kB
TypeScript
import { BaseSchema } from '../core/schema';
import { ValidationContext, ValidationResult } from '../core/types';
type TimeUnit = 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds';
type DateInput = Date | string | number;
/**
* DateSchema - Advanced date validation with unique features
* Supports date range validation, relative dates, business days, and more
*/
export declare class DateSchema extends BaseSchema<Date> {
_type: string;
private _parseMode;
protected validateType(value: unknown, context: ValidationContext): ValidationResult<Date>;
protected clone(): DateSchema;
/**
* Use lenient date parsing (more forgiving of formats)
* Unique feature not found in most validation libraries
*/
lenient(): DateSchema;
/**
* Use strict date parsing (less forgiving of formats)
*/
strict(): DateSchema;
/**
* Require the date to be after a minimum date
*/
min(date: DateInput, message?: string): DateSchema;
/**
* Require the date to be before a maximum date
*/
max(date: DateInput, message?: string): DateSchema;
/**
* Require the date to be within a specific range
*/
between(min: DateInput, max: DateInput, message?: string): DateSchema;
/**
* Require the date to be today
* Unique feature with configurable timezone support
*/
today(options?: {
timezoneOffset?: number;
message?: string;
}): DateSchema;
/**
* Require the date to be in the past
* More sophisticated than typical past validation with options for inclusive/exclusive
*/
past(options?: {
inclusive?: boolean;
message?: string;
reference?: DateInput;
}): DateSchema;
/**
* Require the date to be in the future
* More sophisticated than typical future validation with options for inclusive/exclusive
*/
future(options?: {
inclusive?: boolean;
message?: string;
reference?: DateInput;
}): DateSchema;
/**
* Require the date to be in a specific quarter of the year
* Unique validation not found in other validation libraries
*/
quarter(quarter: 1 | 2 | 3 | 4, options?: {
year?: number;
message?: string;
}): DateSchema;
/**
* Require the date to match a specific weekday
* Unique validation not found in most validation libraries
*/
weekday(days: number | number[], message?: string): DateSchema;
/**
* Require the date to be a business day (Mon-Fri)
* Enhanced with holiday exclusion support
*/
businessDay(options?: {
holidays?: Date[];
message?: string;
}): DateSchema;
/**
* Validate that a date is within a relative timeframe
* Unique feature not found in most validation libraries
*/
within(amount: number, unit: TimeUnit, options?: {
reference?: Date;
message?: string;
}): DateSchema;
/**
* Format validation - require date to be in a specific format
* Unique validation for date string inputs
*/
format(format: string, message?: string): DateSchema;
/**
* Require the date to be at the beginning of a time unit (month, day, hour, etc.)
* For example, beginning of day = midnight
*/
startOf(unit: TimeUnit, message?: string): DateSchema;
/**
* Require the date to be at the end of a time unit (month, day, hour, etc.)
* For example, end of day = 23:59:59.999
*/
endOf(unit: TimeUnit, message?: string): DateSchema;
/**
* Require the date to be a certain age (in years)
* Useful for age verification
*/
age(age: number, options?: {
comparison?: 'exact' | 'min' | 'max';
message?: string;
}): DateSchema;
/**
* Sets a transform function to adjust the date before validation
* For example, to set time to midnight or adjust timezone
*/
transform(fn: (date: Date) => Date): DateSchema;
/**
* Sets the time portion of the date to midnight (00:00:00.000)
*/
toStartOfDay(): DateSchema;
/**
* Require the date to have a specific day of the month
*/
dayOfMonth(day: number | number[], message?: string): DateSchema;
/**
* Require the date to be in a specific month
*/
month(month: number, message?: string): DateSchema;
/**
* Check if a date is at the start of a time unit
* @private
*/
private isStartOf;
/**
* Check if a date is at the end of a time unit
* @private
*/
private isEndOf;
/**
* Helper method to convert time units to milliseconds
* @private
*/
private getUnitInMilliseconds;
}
export {};
//# sourceMappingURL=date.d.ts.map