deno.land / std@0.224.0 / media_types / type_by_extension.ts

type_by_extension.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { types } from "./_db.ts";
/** * Returns the media type associated with the file extension. Values are * normalized to lower case and matched irrespective of a leading `.`. * * When `extension` has no associated type, the function returns `undefined`. * * @example * ```ts * import { typeByExtension } from "https://deno.land/std@$STD_VERSION/media_types/type_by_extension.ts"; * * typeByExtension("js"); // "application/json" * typeByExtension(".HTML"); // "text/html" * typeByExtension("foo"); // undefined * typeByExtension("file.json"); // undefined * ``` */export function typeByExtension(extension: string): string | undefined { extension = extension.startsWith(".") ? extension.slice(1) : extension; // @ts-ignore workaround around denoland/dnt#148 return types.get(extension.toLowerCase());}
std

Version Info

Tagged at
6 months ago