Skip to content

Commit

Permalink
feat: add MediaType::is_typed method (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Apr 18, 2024
1 parent 43767f7 commit f3a9b3f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f3a9b3f

Please sign in to comment.