diff --git a/js/modules/types/mime.js b/js/modules/types/mime.js new file mode 100644 index 0000000000..12ff3bb66d --- /dev/null +++ b/js/modules/types/mime.js @@ -0,0 +1,3 @@ +exports.isJPEG = mimeType => + mimeType === 'image/jpeg' || + mimeType === 'image/jpg'; diff --git a/test/modules/types/mime_test.js b/test/modules/types/mime_test.js new file mode 100644 index 0000000000..38be30aaec --- /dev/null +++ b/test/modules/types/mime_test.js @@ -0,0 +1,23 @@ +const { assert } = require('chai'); + +const MIME = require('../../../js/modules/types/mime'); + + +describe('MIME', () => { + describe('isJPEG', () => { + it('should return true for `image/jpeg`', () => { + assert.isTrue(MIME.isJPEG('image/jpeg')); + }); + + it('should return true for `image/jpg`', () => { + assert.isTrue(MIME.isJPEG('image/jpeg')); + }); + + ['image/gif', 'image/tiff', 'application/json', 0, false, null, undefined] + .forEach((value) => { + it(`should return false for \`${value}\``, () => { + assert.isFalse(MIME.isJPEG(value)); + }); + }); + }); +});