shelving
Version:
Toolkit for using data in JavaScript.
35 lines (34 loc) • 1.6 kB
TypeScript
import type { PossibleDate } from "../util/date.js";
import type { Nullish } from "../util/null.js";
import type { SchemaOptions } from "./Schema.js";
import { Schema } from "./Schema.js";
/** `type=""` prop for HTML `<input />` tags that are relevant for dates. */
export type DateInputType = "time" | "date" | "datetime-local";
/** Allowed options for `DateSchema` */
export interface DateSchemaOptions extends SchemaOptions {
readonly value?: PossibleDate | undefined;
readonly min?: Nullish<PossibleDate>;
readonly max?: Nullish<PossibleDate>;
readonly input?: DateInputType | undefined;
/**
* Rounding step (in milliseconds, because that's the base unit for time).
* - E.g. `1000 * 60` will round to the nearest minute.
* - Note: HTML `<input>` `step` attributes are in _seconds_, so you may need to convert units.
*/
readonly step?: number | undefined;
}
export declare class DateSchema extends Schema<string> {
readonly value: PossibleDate;
readonly min: Date | undefined;
readonly max: Date | undefined;
readonly input: DateInputType;
readonly step: number | undefined;
constructor({ one, min, max, value, input, step, ...options }: DateSchemaOptions);
validate(value?: unknown): string;
stringify(value: Date): string;
format(value: Date): string;
}
/** Valid date, e.g. `2005-09-12` (required because falsy values are invalid). */
export declare const DATE: DateSchema;
/** Valid date, e.g. `2005-09-12`, or `null` */
export declare const NULLABLE_DATE: import("./NullableSchema.js").NullableSchema<string>;