API Reference

Core API

DataFetcher

A class for fetching data from various sources.
new DataFetcher(options?: object)

Methods

  • fetch(url: string, config?: object): Promise<Response>
    Performs an HTTP request to the specified URL.
    Parameters:
    • url (string): The URL to fetch.
    • config (object, optional): Configuration options for the fetch request (e.g., method, headers, body).
    Returns:
    • A Promise that resolves with the Response object.
  • getJson(url: string, params?: object): Promise<any>
    Fetches JSON data from a URL, optionally with query parameters.
    Parameters:
    • url (string): The URL to fetch JSON from.
    • params (object, optional): An object of query parameters to append to the URL.
    Returns:
    • A Promise that resolves with the parsed JSON data.

Logger

Utility class for logging messages to the console or a remote service.
Logger.log(message: string, level?: 'info' | 'warn' | 'error')

Methods

  • log(message: string, level: 'info' | 'warn' | 'error' = 'info'): void
    Logs a message with an optional log level.
    Parameters:
    • message (string): The message to log.
    • level (string, optional): The log level ('info', 'warn', 'error'). Defaults to 'info'.
    Returns:
    • void
  • error(message: string): void
    Logs an error message. Shorthand for log(message, 'error').
    Parameters:
    • message (string): The error message to log.
    Returns:
    • void

UI Components

Modal

A versatile modal dialog component.
new Modal(options: ModalOptions)

Properties

  • isOpen (boolean): Indicates if the modal is currently open.
  • title (string): The title of the modal.

Methods

  • open(): void
    Opens the modal dialog.
  • close(): void
    Closes the modal dialog.
  • setContent(content: HTMLElement | string): void
    Sets the HTML content of the modal body.
    Parameters:
    • content (HTMLElement | string): The content to display in the modal.

Events

  • onClose(callback: () => void): void: Registers a callback function to be executed when the modal is closed.

Utilities

StringUtils

Helper functions for string manipulation.

Methods

  • capitalize(str: string): string
    Capitalizes the first letter of a string.
    Parameters:
    • str (string): The string to capitalize.
    Returns:
    • The capitalized string.
  • truncate(str: string, maxLength: number, suffix: string = '...'): string
    Truncates a string to a specified maximum length, appending a suffix if necessary.
    Parameters:
    • str (string): The string to truncate.
    • maxLength (number): The maximum length of the resulting string.
    • suffix (string, optional): The suffix to append if truncation occurs. Defaults to '...'.
    Returns:
    • The truncated string.