Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 7, 2025

This PR adds a comprehensive set of MIME type utility functions to the javascript-utils library.

Functions Added

  • isImageMimeType(mimeType?: string): boolean - Check if MIME type is for images (image/*)
  • isPdfMimeType(mimeType?: string): boolean - Check if MIME type is for PDF files (application/pdf)
  • isVideoMimeType(mimeType?: string): boolean - Check if MIME type is for videos (video/*)
  • isAudioMimeType(mimeType?: string): boolean - Check if MIME type is for audio (audio/*)
  • isTextMimeType(mimeType?: string): boolean - Check if MIME type is for text (text/*)
  • isApplicationMimeType(mimeType?: string): boolean - Check if MIME type is for applications (application/*)

Usage Examples

import { isImageMimeType, isPdfMimeType, isVideoMimeType } from '@neolution-ch/javascript-utils';

// Image types
isImageMimeType('image/jpeg'); // true
isImageMimeType('image/png'); // true
isImageMimeType('video/mp4'); // false

// PDF documents
isPdfMimeType('application/pdf'); // true
isPdfMimeType('image/jpeg'); // false

// Video files
isVideoMimeType('video/mp4'); // true
isVideoMimeType('video/webm'); // true
isVideoMimeType('audio/mp3'); // false

Key Features

  • Robust input handling: Gracefully handles null/undefined inputs (returns false)
  • Case-insensitive: MIME type checking works regardless of case
  • Whitespace tolerant: Automatically trims whitespace from inputs
  • Format validation: Ensures proper MIME type format (requires type/subtype pattern)
  • Comprehensive testing: 100% test coverage with extensive edge cases

Implementation Details

  • Created src/lib/mimeType.ts with all utility functions
  • Created src/lib/mimeType.spec.ts with comprehensive test suite (102 test cases)
  • Added export to src/index.ts to make functions available
  • Follows existing library patterns for parameter validation and JSDoc documentation
  • Maintains 100% test coverage requirement

Testing

All tests pass including:

  • Input validation (null, undefined, non-strings)
  • Valid MIME type detection for each category
  • Case insensitivity verification
  • Whitespace handling
  • Invalid format rejection
  • Cross-category validation (ensuring image functions reject video types, etc.)

Fixes #44.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/neolution-ch/javascript-utils/@neolution-ch/javascript-utils@69

commit: f4f85fe

Co-authored-by: neotrow <92933708+neotrow@users.noreply.github.com>
Copilot AI changed the title [WIP] Add MimeType utility functions Add MimeType utility functions Jul 7, 2025
Copilot AI requested a review from neotrow July 7, 2025 12:44
@neotrow neotrow marked this pull request as ready for review July 7, 2025 12:52
@neotrow neotrow requested a review from a team as a code owner July 7, 2025 12:52
@neotrow
Copy link
Contributor

neotrow commented Jul 7, 2025

@copilot the check-changelog is failing because you didn't add you changes to the CHANGELOG.md.

Please add it under the unreleased section, make sure prettier is happy after adding it.

Co-authored-by: neotrow <92933708+neotrow@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 7, 2025

@copilot the check-changelog is failing because you didn't add you changes to the CHANGELOG.md.

Please add it under the unreleased section, make sure prettier is happy after adding it.

Added the MIME type utility functions to the CHANGELOG.md under the unreleased section. Prettier formatting verified and all tests pass with 100% coverage. (commit ca9fe58)

Co-authored-by: drebrez <1611547+drebrez@users.noreply.github.com>
Copilot AI requested a review from drebrez July 7, 2025 13:11
@drebrez drebrez requested a review from manni497 July 7, 2025 13:38
@neotrow neotrow merged commit 6882a77 into main Jul 7, 2025
5 checks passed
@neotrow neotrow deleted the copilot/fix-44 branch July 7, 2025 14:03
@github-actions
Copy link

github-actions bot commented Jul 7, 2025

Package Line Rate Branch Rate Complexity Health
main 100% 100% 0
Summary 100% (145 / 145) 100% (73 / 73) 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MimeType utility functions

4 participants