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

type_by_extension.ts
نووسراو ببینە
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
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.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
11 months ago