BREAKING(media_types): remove typeByExtension() (#3848)

This commit is contained in:
Asher Gomez 2023-11-24 19:08:26 +11:00 committed by GitHub
parent c89fb9b5aa
commit f34104ac53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 53 deletions

View File

@ -21,4 +21,3 @@ export * from "./extensions_by_type.ts";
export * from "./format_media_type.ts";
export * from "./get_charset.ts";
export * from "./parse_media_type.ts";
export * from "./type_by_extension.ts";

View File

@ -1,28 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
import { types } from "./_db.ts";
/**
* @deprecated (will be removed in 0.209.0) Use {@linkcode import("./content_type.ts").contentType} instead.
*
* 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());
}

View File

@ -1,24 +0,0 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";
import { typeByExtension } from "./mod.ts";
Deno.test({
name: "media_types - typeByExtension",
fn() {
const fixtures = [
["js", "application/javascript"],
[".js", "application/javascript"],
["Js", "application/javascript"],
["html", "text/html"],
[".html", "text/html"],
[".HTML", "text/html"],
["file.json", undefined],
["foo", undefined],
[".foo", undefined],
] as const;
for (const [fixture, expected] of fixtures) {
assertEquals(typeByExtension(fixture), expected);
}
},
});