diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0bfa0db..46af177 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -57,6 +57,10 @@ updates: directory: "app_lints" schedule: interval: "monthly" + - package-ecosystem: "pub" + directory: "app_media" + schedule: + interval: "monthly" - package-ecosystem: "pub" directory: "app_mirrors" schedule: diff --git a/app_media/lib/mime_type.dart b/app_media/lib/mime_type.dart index 718447e..fd60f4b 100644 --- a/app_media/lib/mime_type.dart +++ b/app_media/lib/mime_type.dart @@ -1 +1,2 @@ +export 'src/mapping.dart' show extensionFromMimeType; export 'src/mime_type_constant.dart'; diff --git a/app_media/lib/src/mapping.dart b/app_media/lib/src/mapping.dart new file mode 100644 index 0000000..f97e7bf --- /dev/null +++ b/app_media/lib/src/mapping.dart @@ -0,0 +1,13 @@ +import 'package:tekartik_app_media/mime_type.dart'; + +const _mimeTypeExtensions = { + mimeTypeApplicationJson: extensionApplicationJson, + mimeTypeImageJpg: extensionImageJpg, + mimeTypeImagePng: extensionImagePng, + mimeTypeImageWebp: extensionImageWebp, +}; + +/// Get the extension from a mime type +String? extensionFromMimeType(String mimeType) { + return _mimeTypeExtensions[mimeType]; +} diff --git a/app_media/lib/src/mime_type_constant.dart b/app_media/lib/src/mime_type_constant.dart index 5057729..2d569f5 100644 --- a/app_media/lib/src/mime_type_constant.dart +++ b/app_media/lib/src/mime_type_constant.dart @@ -1,2 +1,23 @@ /// Mime type for application/json const mimeTypeApplicationJson = 'application/json'; + +/// Extension for json +const extensionApplicationJson = '.json'; + +/// Mime type for jpg +const mimeTypeImageJpg = 'image/jpeg'; + +/// Extension for jpg +const extensionImageJpg = '.jpg'; + +/// Mime type for png +const mimeTypeImagePng = 'image/png'; + +/// Extension for jpg +const extensionImagePng = '.png'; + +/// Mime type for webp +const mimeTypeImageWebp = 'image/webp'; + +/// Extension for webp +const extensionImageWebp = '.webp'; diff --git a/app_media/pubspec.yaml b/app_media/pubspec.yaml index f0d60f4..c5651d8 100644 --- a/app_media/pubspec.yaml +++ b/app_media/pubspec.yaml @@ -1,5 +1,5 @@ name: tekartik_app_media -description: Media type constants +description: Media type constants and helpers version: 1.0.0 publish_to: none diff --git a/app_media/test/mime_type_test.dart b/app_media/test/mime_type_test.dart index 5ec04c5..c3d6107 100644 --- a/app_media/test/mime_type_test.dart +++ b/app_media/test/mime_type_test.dart @@ -5,8 +5,28 @@ void main() { group('mime_type', () { test('constants', () { // Ensure it is a const - const types = [mimeTypeApplicationJson]; - expect(types, ['application/json']); + const types = [ + mimeTypeApplicationJson, + mimeTypeImagePng, + mimeTypeImageJpg, + mimeTypeImageWebp + ]; + expect( + types, ['application/json', 'image/png', 'image/jpeg', 'image/webp']); + const extensions = [ + extensionApplicationJson, + extensionImagePng, + extensionImageJpg, + extensionImageWebp, + ]; + expect(extensions, ['.json', '.png', '.jpg', '.webp']); + }); + test('extensionFromMimeType', () { + expect(extensionFromMimeType(mimeTypeApplicationJson), + extensionApplicationJson); + expect(extensionFromMimeType(mimeTypeImagePng), extensionImagePng); + expect(extensionFromMimeType(mimeTypeImageJpg), extensionImageJpg); + expect(extensionFromMimeType(mimeTypeImageWebp), extensionImageWebp); }); }); }