@osaedasia/oresume
Version:
A user-friendly library for generating complete Single Page Applications (SPAs)
84 lines (83 loc) • 3.76 kB
TypeScript
import { Observable } from "../observer/Observable";
import { LanguageService } from "../LanguageService";
import { ProgressMessage } from "../task/messages/ProgressMessage";
import { LocalizedUrl } from "../../domain/models/LocalizedUrl";
import { ISO639_1 } from "../../domain/definitions/types/Country";
/**
* A class that provides functionality to handle public resources, including managing folder paths, URLs, and localized URLs.
* It supports loading files from specified paths with tracking progress and loading of localized resources.
* @template LSupported A generic parameter that extends ISO639_1, representing the supported language codes
*/
export declare class PublicResource<LSupported extends ISO639_1> {
/**
* The normalized path to the resource folder
*/
private readonly _folderPath;
/**
* The complete URL to access the resource
*/
private readonly _url;
/**
* Observable that emits localized URL information for the resource
*/
private readonly _localizedUrl;
/**
* Service handling language-specific operations and resource localization
*/
private readonly _languageService;
/**
* Creates a new PublicResource instance
* @param {string} folderPath The path to the resource folder
* @param {LanguageService<LSupported>} languageService Service for handling language-specific operations
*/
constructor(folderPath: string, languageService: LanguageService<LSupported>);
/**
* @returns {string} The normalized folder path
*/
get folderPath(): string;
/**
* @returns {URL} The complete URL for accessing the resource
*/
get url(): URL;
/**
* @returns {Observable<LocalizedUrl>} An observable emitting the localized URL
*/
get localizedUrl(): Observable<LocalizedUrl>;
/**
* Loads and processes a file from the specified path
* @template T The type of data returned from the file
* @param {string} file Path to the file
* @param {(data: Promise<T | URL>) => void} onLoaded Callback function executed when file is loaded
*/
load<T>(file: string, onLoaded: (data: Promise<T | URL>) => void): Observable<ProgressMessage>;
/**
* Loads a localized file with progress tracking
* @template T The type of data returned from the file
* @param {string} file The name or path of the file to load
* @param {(data: Promise<T | URL>) => void} onLoaded Callback executed when file is loaded
* @returns {Observable<ProgressMessage>} Observable tracking the loading progress
*/
loadLocalized<T>(file: string, onLoaded: (data: Promise<T | URL>) => void): Observable<ProgressMessage>;
/**
* Generates a localized URL based on the current language settings
* @returns {Observable<LocalizedUrl>} An observable containing the localized URL information
*/
private _generateLocalizedUrl;
/**
* Validates and returns the file extension from the given file path
* @param {string} file The file path to check
* @returns {string} The extracted file extension
* @throws {MissingFileExtensionError} If the file extension is missing
* @throws {InvalidFileExtensionError} If the file extension is invalid
*/
private _assertFileExtension;
/**
* Handles the file loading process based on the file type
* @template T The type of data to be loaded
* @param {URL} url The URL of the file to load
* @param {string} fileExt The file extension
* @param {Observable<ProgressMessage>} progressObserver Observable for tracking loading progress
* @returns {Promise<T | URL>} Promise resolving to the loaded data or URL
*/
private _handleFileLoading;
}