i.am.gopher
i.am.gopher15mo ago

extension method returning undefined for `text/plain`

Given the following:
console.log(
"text/plain",
extension("text/plain"),
extensionsByType("text/plain"),
parseMediaType("text/plain"),
[...extensions.entries()]
);
console.log(
"text/plain",
extension("text/plain"),
extensionsByType("text/plain"),
parseMediaType("text/plain"),
[...extensions.entries()]
);
I seem to get the result
text/plain undefined undefined [ "text/plain", undefined ] []
text/plain undefined undefined [ "text/plain", undefined ] []
Am I missing something?
4 Replies
marvinh.
marvinh.15mo ago
Where are those functions extension, extensionsByType , etc coming from?
i.am.gopher
i.am.gopher15mo ago
stdlib https://deno.land/std@0.197.0/media_types/extensions_by_type.ts?s=extensionsByType
import { contentType } from "https://deno.land/std@0.198.0/media_types/content_type.ts";
import { extension } from "https://deno.land/std@0.198.0/media_types/extension.ts";
import { extensionsByType } from "https://deno.land/std@0.198.0/media_types/extensions_by_type.ts";
import { extensions } from "https://deno.land/std@0.198.0/media_types/_util.ts";
import { parseMediaType } from "https://deno.land/std@0.198.0/media_types/parse_media_type.ts";
import { contentType } from "https://deno.land/std@0.198.0/media_types/content_type.ts";
import { extension } from "https://deno.land/std@0.198.0/media_types/extension.ts";
import { extensionsByType } from "https://deno.land/std@0.198.0/media_types/extensions_by_type.ts";
import { extensions } from "https://deno.land/std@0.198.0/media_types/_util.ts";
import { parseMediaType } from "https://deno.land/std@0.198.0/media_types/parse_media_type.ts";
this is how I was importing them but looks like this was causing the error changing it to import from mod seems to have brought in the iife that populates the extenstion and types
import {
contentType,
extension,
extensionsByType,
extensions,
parseMediaType,
} from "https://deno.land/std@0.198.0/media_types/mod.ts";
import {
contentType,
extension,
extensionsByType,
extensions,
parseMediaType,
} from "https://deno.land/std@0.198.0/media_types/mod.ts";
I dunno, should I be allowed to just import the scripts i need without requiring to import mod.ts?
marvinh.
marvinh.15mo ago
I was mainly asking because the code snippet in the original message doesn't make it obvious where they are coming from. So when I copy & pasted the snippet it didn't find those functions This is the result I get on my end:
text/plain txt [
"txt", "text",
"conf", "def",
"list", "log",
"in", "ini"
] [ "text/plain", undefined ] [
[ "application/andrew-inset", [ "ez" ] ],
[ "application/applixware", [ "aw" ] ],
[ "application/atom+xml", [ "atom" ] ],
[ "application/atomcat+xml", [ "atomcat" ] ],
[ "application/atomdeleted+xml", [ "atomdeleted" ] ],
[ "application/atomsvc+xml", [ "atomsvc" ] ],
[ "application/atsc-dwd+xml", [ "dwd" ] ],
[ "application/atsc-held+xml", [ "held" ] ],
[ "application/atsc-rsat+xml", [ "rsat" ] ],
[ "application/bdoc", [ "bdoc" ] ]
...
]
text/plain txt [
"txt", "text",
"conf", "def",
"list", "log",
"in", "ini"
] [ "text/plain", undefined ] [
[ "application/andrew-inset", [ "ez" ] ],
[ "application/applixware", [ "aw" ] ],
[ "application/atom+xml", [ "atom" ] ],
[ "application/atomcat+xml", [ "atomcat" ] ],
[ "application/atomdeleted+xml", [ "atomdeleted" ] ],
[ "application/atomsvc+xml", [ "atomsvc" ] ],
[ "application/atsc-dwd+xml", [ "dwd" ] ],
[ "application/atsc-held+xml", [ "held" ] ],
[ "application/atsc-rsat+xml", [ "rsat" ] ],
[ "application/bdoc", [ "bdoc" ] ]
...
]
i.am.gopher
i.am.gopher15mo ago
ahhh nwnw, do you get those results when importing from mod.ts or from importing individual scripts (i.e media_types/extension.ts, media_types/content_type) @marvinh. thank you