@lyra/base
Version:
Lyra plugin containing the base components and roles for a Lyra configuration
29 lines (22 loc) • 771 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = assetUrlBuilder;
const lyraUrlMatch = /^https?:\/\/cdn.lyra.\w+\/images\//;
function assetUrlBuilder(url, options) {
const width = options.width,
height = options.height,
fit = options.fit;
if (!lyraUrlMatch.test(url)) {
return url;
}
if (url.includes('?')) {
// todo: this is an lyra cdn url that already has parameters specified
// Consider merging with options instead of just bypassing
return url;
}
const defaultFit = width === height ? 'crop' : 'clip';
const params = [width && `w=${width}`, height && `h=${height}`, `fit=${fit ? fit : defaultFit}`, 'q=85'].filter(Boolean).join('&');
return `${url}?${params}`;
}