refactor(common): remove unnecessary toString conversions (#47082)

A small refactor that removes explicit toString calls when not needed.

PR Close #47082
This commit is contained in:
Pawel Kozlowski 2022-06-10 14:29:56 +02:00 committed by Pawel Kozlowski
parent 8343133e94
commit feb6ee8f6e
3 changed files with 5 additions and 3 deletions

View file

@ -30,7 +30,7 @@ function cloudflareLoaderFactory(path: string) {
return (config: ImageLoaderConfig) => {
let params = `format=auto`;
if (config.width) {
params += `,width=${config.width.toString()}`;
params += `,width=${config.width}`;
}
const url = `${path}/cdn-cgi/image/${params}/${normalizeSrc(config.src)}`;
return url;

View file

@ -36,7 +36,7 @@ export function imagekitLoaderFactory(path: string) {
// https://ik.imagekit.io/demo/tr:w-300,h-300/medium_cafe_B1iTdD0C.jpg
let params = `tr:q-auto`; // applies the "auto quality" transformation
if (config.width) {
params += `,w-${config.width?.toString()}`;
params += `,w-${config.width}`;
}
const url = `${path}/${params}/${normalizeSrc(config.src)}`;
return url;

View file

@ -32,7 +32,9 @@ function imgixLoaderFactory(path: string) {
const url = new URL(`${path}/${normalizeSrc(config.src)}`);
// This setting ensures the smallest allowable format is set.
url.searchParams.set('auto', 'format');
config.width && url.searchParams.set('w', config.width.toString());
if (config.width) {
url.searchParams.set('w', config.width.toString());
}
return url.href;
};
}