UNPKG

@creamapi/cream

Version:

Concise REST API Maker - An extension library for express to create REST APIs faster

56 lines (55 loc) 1.88 kB
/** * Represents a time frame for managing cookie expiration. * Provides methods to initialize, set expiration, and retrieve time details. */ export declare class CookieTimeFrame { /** * Stores the initialization timestamp. * `undefined` until initialized with `fromNow()`. */ private _now; /** * Stores the initialization timestamp. * `undefined` until initialized with `fromNow()`. */ private _final; /** * Initializes the timeframe with the current timestamp. * * @returns The updated `CookieTimeFrame` instance. */ fromNow(): CookieTimeFrame; /** * Sets the expiration time in milliseconds, relative to initialization. * * @param milliseconds - The duration from the initialization point. * @returns The updated `CookieTimeFrame` instance. * @throws Error if the timeframe has not been initialized or if milliseconds are negative */ willEndIn(milliseconds: number): CookieTimeFrame; /** * Ensures that both initialization and expiration values are set. * * @throws Error if the timeframe has not been properly initialized or finalized. */ private checkIfParamsAreSet; /** * Retrieves the expiration date as a `Date` object. * * @returns A `Date` object representing the expiration time. * @throws Error if the timeframe has not been properly initialized or finalized. */ getEndDate(): Date; /** * Calculates the remaining time in milliseconds until expiration. * * @returns The number of milliseconds until expiration. * @throws Error if the timeframe has not been properly initialized or finalized. */ getDeltaTime(): number; /** * This method is used to get the starting point of the time frame; * @returns */ getStartingPoint(): number; }