JonasKruckenberg / imagetools

Load and transform images using a toolbox :toolbox: of custom import directives!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make output format a URL parameter value instead of key

benmccann opened this issue · comments

Right now to have a default output format of picture I have to do:

			defaultDirectives: (url) => {
				const ext = path.extname(url.pathname);
				const params = new URLSearchParams();
				if (!params.has('heic') && !params.has('heif') && !params.has('avif') && !params.has('jpeg') && !params.has('jpg') && !params.has('png') && !params.has('tiff') && !params.has('webp') && !params.has('avif')) {
					params.set('format', 'avif;webp;' + fallback[ext]);
				}
				if (!params.has('meta') && !params.has('metadata') && !params.has('source') && !params.has('srcset') && !params.has('url')) {
					params.set('picture', true);
				}
				return params;
			}

This would break whenever a new output format is introduced and has the potential to be greatly simplified to a safer version as:

			defaultDirectives: (url) => new URLSearchParams({
					format: 'avif;webp;' + fallback[path.extname(url.pathname)], as: 'picture' });

This would make setting up the library much simpler, but would require a breaking change.

This being a breaking change doesn't bother me much, let's major bump whenever necessary. But, let's make sure no existing use cases become impossible