@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
29 lines (27 loc) • 984 B
TypeScript
import { DateField } from "../types/value/date.js";
import { TimestampField } from "../types/value/timestamp.js";
//#region src/helpers/asDate.d.ts
/**
* The return type of `asDate()`.
*/
type AsDateReturnType<Field extends DateField | TimestampField | null | undefined> = Field extends DateField<"filled"> | TimestampField<"filled"> ? Date : null;
/**
* Converts a date or timestamp field to a JavaScript Date object.
*
* @example
*
* ```ts
* const date = asDate(document.data.release_date)
* // => Date object or null
* ```
*
* @param dateOrTimestampField - A date or timestamp field from Prismic.
*
* @returns A Date object, or `null` if the field is empty.
*
* @see Learn about date and timestamp fields: {@link https://prismic.io/docs/fields/date}
*/
declare const asDate: <Field extends DateField | TimestampField | null | undefined>(dateOrTimestampField: Field) => AsDateReturnType<Field>;
//#endregion
export { asDate };
//# sourceMappingURL=asDate.d.ts.map