From 3af3fb3dd6c553e14d3e47357017a68fe64950bd Mon Sep 17 00:00:00 2001 From: JonasKruckenberg Date: Mon, 8 Mar 2021 15:56:51 +0100 Subject: [PATCH] feat: add ouput processing function --- src/output.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/output.ts diff --git a/src/output.ts b/src/output.ts new file mode 100644 index 00000000..351457e4 --- /dev/null +++ b/src/output.ts @@ -0,0 +1,17 @@ +export const metadataOutput = (src:URL, outputMetadatas: Record[]) => { + if(!src.searchParams.has('metadata') && !src.searchParams.has('meta')) return null + + return outputMetadatas.length === 1 ? outputMetadatas[0] : outputMetadatas +} + +export const srcsetOutput = (src:URL, outputMetadatas: Record[]) => { + if(!src.searchParams.has('srcset')) return null + + return outputMetadatas.length === 1 ? outputMetadatas[0] : outputMetadatas +} + +export const urlOutput = (src:URL, outputMetadatas: Record[]) => { + const out:string[] = outputMetadatas.map(metadata => metadata.src) + + return out.length == 1 ? out[0] : out +} \ No newline at end of file