@redocly/theme
Version:
Shared UI components lib
42 lines (41 loc) • 2.15 kB
TypeScript
import type { Locale } from '../types/l10n';
export declare function combineUrls(baseURL: string, ...relativeURLs: (string | undefined)[]): string;
export declare function withPathPrefix(url: string): string;
export declare function withoutPathPrefix(pathname: string): string;
export declare function withoutHash(url: undefined | null): undefined;
export declare function withoutHash(url: string): string;
export declare function withoutHash(url: string | undefined): string | undefined;
/**
*
* @returns url with leading and without trailing slash or empty string, e.g. '/prefix'
*/
export declare function getPathPrefix(): string;
export declare function normalizePathPrefix(prefix: string): string;
export declare function addLeadingSlash(url: string): string;
export declare function removeTrailingSlash(url: string): string;
export declare function removeLeadingSlash(url: string): string;
export declare function isPathInFolder(child: string, parent: string): boolean;
/**
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
*
* @param path
* @return slashed path
*/
export declare function slash(path: string): string;
export declare function addTrailingSlash(url: string): string;
/**
* Adds locale to pathname, or replaces current locale in pathname with a new one
* @param originalPathname - Pathname without path prefix
* @param defaultLocale - Default locale code
* @param newLocale - New locale code to apply
* @param allLocales - Array of all available locales
*/
export declare function getPathnameForLocale(originalPathname: string, defaultLocale: string, newLocale: string, allLocales: Locale[]): string;
/**
* Extracts the locale code from a pathname
* @param pathname - URL pathname to extract locale from without path prefix
* @param defaultLocale - Default locale code to return if no locale found in pathname
* @param allLocales - Array of all available locales to check against
* @returns The locale code from the pathname, or the default locale if none found
*/
export declare function getLocaleFromPathname(pathname: string, defaultLocale?: string, allLocales?: Locale[]): string;