staticdelivr
Version:
StaticDelivr simplifies image delivery by optimizing performance through CDN integration, format conversion, and dynamic resizing. Perfect for React applications.
23 lines (22 loc) • 790 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUrl = void 0;
const buildUrl = ({ src, width, height, quality, format, }) => {
if (!src) {
throw new Error('The src parameter is required');
}
// Initialize the query parameters object
const params = [];
if (width)
params.push(`w=${width}`);
if (height)
params.push(`h=${height}`);
if (quality)
params.push(`q=${quality}`);
if (format)
params.push(`format=${format}`);
// If there are parameters, append them to the URL
const paramString = params.length > 0 ? `&${params.join('&')}` : '';
return `https://cdn.staticdelivr.com/img/images?url=${encodeURIComponent(src)}${paramString}`;
};
exports.buildUrl = buildUrl;