astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
24 lines (23 loc) • 561 B
JavaScript
import { typeHandlers, types } from "./types/index.js";
// This map helps avoid validating for every single image type
const firstBytes = new Map([
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]);
export function detector(input) {
const byte = input[0];
const type = firstBytes.get(byte);
if (type && typeHandlers.get(type).validate(input)) {
return type;
}
return types.find((imageType) => typeHandlers.get(imageType).validate(input));
}