UNPKG

html-to-image

Version:

Generates an image from a DOM node using HTML5 canvas and SVG.

26 lines (23 loc) 607 B
const WOFF = 'application/font-woff' const JPEG = 'image/jpeg' const mimes: { [key: string]: string } = { woff: WOFF, woff2: WOFF, ttf: 'application/font-truetype', eot: 'application/vnd.ms-fontobject', png: 'image/png', jpg: JPEG, jpeg: JPEG, gif: 'image/gif', tiff: 'image/tiff', svg: 'image/svg+xml', webp: 'image/webp', } function getExtension(url: string): string { const match = /\.([^./]*?)$/g.exec(url) return match ? match[1] : '' } export function getMimeType(url: string): string { const extension = getExtension(url).toLowerCase() return mimes[extension] || '' }