From f3a9b3fc5d09ac455a37336c79dcc504bae45f43 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 18 Apr 2024 16:31:17 +0200 Subject: [PATCH] feat: add `MediaType::is_typed` method (#9) --- src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 515511c..bd3b714 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,6 +142,32 @@ impl MediaType { } } + /// Returns true if this media type provides types inherently. + /// + /// Examples are TypeScript, TSX, or DTS files. Wasm and JSON files are also + /// considered typed. + pub fn is_typed(&self) -> bool { + match self { + Self::TypeScript + | Self::Mts + | Self::Cts + | Self::Dts + | Self::Dmts + | Self::Dcts + | Self::Tsx + | Self::Json + | Self::Wasm => true, + Self::JavaScript + | Self::Jsx + | Self::Mjs + | Self::Cjs + | Self::Css + | Self::TsBuildInfo + | Self::SourceMap + | Self::Unknown => false, + } + } + #[cfg(feature = "module_specifier")] pub fn from_specifier_and_headers( specifier: &ModuleSpecifier,