@pixel-puppy/javascript
Version:
Official JavaScript/TypeScript library for Pixel Puppy - Transform and optimize images with WebP conversion and smart resizing
47 lines • 1.67 kB
TypeScript
/**
* Checks if a URL is relative (needs a base URL to resolve)
*
* @param url - The URL to check
* @returns true if the URL is relative, false if absolute
*
* @example
* isRelativeUrl('/images/hero.webp') // true
* isRelativeUrl('images/hero.webp') // true
* isRelativeUrl('https://example.com/image.jpg') // false
* isRelativeUrl('//cdn.example.com/image.jpg') // false (protocol-relative)
*/
export declare function isRelativeUrl(url: string): boolean;
/**
* Resolves a potentially relative URL to an absolute URL.
* Returns the original URL unchanged if it's already absolute.
*
* Resolution priority:
* 1. If URL is absolute, return as-is
* 2. Use provided baseUrl parameter
* 3. Use globally configured baseUrl
* 4. Auto-detect from browser (window.location.origin)
* 5. Throw error if no baseUrl available
*
* @param url - The URL to resolve
* @param baseUrl - Optional base URL to use (overrides global config)
* @returns The resolved absolute URL
* @throws {Error} if the URL is relative and no baseUrl is available
*
* @example
* // With explicit baseUrl
* resolveUrl('/images/hero.webp', 'https://example.com')
* // Returns: 'https://example.com/images/hero.webp'
*
* @example
* // With global config
* configure({ baseUrl: 'https://example.com' })
* resolveUrl('/images/hero.webp')
* // Returns: 'https://example.com/images/hero.webp'
*
* @example
* // Absolute URLs pass through unchanged
* resolveUrl('https://other.com/image.jpg', 'https://example.com')
* // Returns: 'https://other.com/image.jpg'
*/
export declare function resolveUrl(url: string, baseUrl?: string): string;
//# sourceMappingURL=url-utils.d.ts.map