import { buildCDNUrl } from '.'; import { CDNOptions } from '../types'; export interface ImageLoaderParams { src: string; width: number; quality: number; crop: CDNOptions['crop']; fill?: boolean; aspectRatio?: number; } export const ImageLoader = ({ src, width, quality, crop, fill, aspectRatio }: ImageLoaderParams) => { if (src?.match?.(/akinoncdn|akinoncloud|b-cdn\.net/)) { const height = fill && aspectRatio ? parseInt(String(Number(width) / aspectRatio)) : undefined; const config: CDNOptions = { width, height, quality, crop: crop !== 'none' ? crop : undefined }; return buildCDNUrl(src, config); } return src; };