Skip to main content
Foldkit
On this pageFunctions

Task

Functions

clickElement

functionsource

Programmatically clicks an element matching the given selector. Uses requestAnimationFrame to ensure the DOM is updated before attempting to click. Fails with ElementNotFound if the selector does not match an HTMLElement.

(selector: string): Effect<void, ElementNotFound>

closeModal

functionsource

Closes a dialog element using .close(). Uses requestAnimationFrame to ensure the DOM is updated before attempting to close. Fails with ElementNotFound if the selector does not match an HTMLDialogElement.

(selector: string): Effect<void, ElementNotFound>

delay

functionsource

Waits for the given duration before completing. Useful for debouncing, such as clearing a typeahead search query.

(duration: DurationInput): Effect<void>

focus

functionsource

Focuses an element matching the given selector. Uses requestAnimationFrame to ensure the DOM is updated before attempting to focus. Fails with ElementNotFound if the selector does not match an HTMLElement.

(selector: string): Effect<void, ElementNotFound>

getZonedTimeIn

functionsource

Gets the current time in a specific timezone. Fails with TimeZoneError if the timezone ID is invalid.

(zoneId: string): Effect<Zoned, TimeZoneError>

randomInt

functionsource

Generates a random integer between min (inclusive) and max (exclusive).

(
  min: number,
  max: number
): Effect<number>

scrollIntoView

functionsource

Scrolls an element into view by selector using { block: 'nearest' }. Uses requestAnimationFrame to ensure the DOM is updated before attempting to scroll. Fails with ElementNotFound if the selector does not match an HTMLElement.

(selector: string): Effect<void, ElementNotFound>

showModal

functionsource

Opens a dialog element as a modal using showModal(). Uses requestAnimationFrame to ensure the DOM is updated before attempting to show. Fails with ElementNotFound if the selector does not match an HTMLDialogElement.

(selector: string): Effect<void, ElementNotFound>

waitForTransitions

functionsource

Waits for all CSS transitions on the element matching the selector to complete. Uses the Web Animations API for reliable detection. Falls back to completing immediately if the element is missing or has no active transitions.

(selector: string): Effect<void>

Constants

getTime

constsource

Gets the current UTC time.

const getTime: Effect.Effect<DateTime.Utc>

getTimeZone

constsource

Gets the system timezone.

const getTimeZone: Effect.Effect<DateTime.TimeZone>

getZonedTime

constsource

Gets the current time in the system timezone.

const getZonedTime: Effect.Effect<DateTime.Zoned>

nextFrame

constsource

Completes after two animation frames, ensuring the browser has painted the current state before proceeding. Used for CSS transition orchestration — the double-rAF guarantees the "from" state is visible before transitioning to the "to" state.

const nextFrame: Effect.Effect<void>