mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
BREAKING(media_types): remove typeByExtension()
(#3848)
This commit is contained in:
parent
c89fb9b5aa
commit
f34104ac53
@ -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";
|
||||
|
@ -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());
|
||||
}
|
@ -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);
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue
Block a user