mimeTypes is a unified Javascript AMD/CommonJS module for the browser or server (SSJS) which determines a file's MIME type from its name and/or extension.
The file extension to MIME type correspondence was derived from [stdicon.com/mimetypes] (http://www.stdicon.com/mimetypes).
Simply create a folder within your Wakanda project's WebFolder named scripts
and copy
mimeTypes.js
into it. Be sure that this location is recognized by your AMD vehicle (e.g.
RequireJS).
Simply create a folder named Modules
in your Wakanda project and copy mimeTypes.js
into it.
- mimeTypes.js - Fully commented script. Update to contribute.
- mimeTypes.min.js - Minimized script. For normal use.
- mimeTypes.no-md.js - Commented script without markdown comments. Use for debugging.
Returns the MIME type string for the fileName
. If the MIME type cannot be determined from
fileName
, an exception is raised unless a default MIME type has been provided by first calling
the setDefaultMimeType() function.
Examples:
var mimeTypes = require('mimeTypes');
theMimeType = mimeTypes.lookup('test.jpg'); // 'image/jpeg'
Sets the mimeType
to be returned if this module cannot determine the MIME type from a given file
name/extension.
mimeType
- The MIME type to return as a default if this module cannot determine a MIME type for a given file name/extension. If not set using this function, the lookup function throws an exception when it cannot find a MIME type.
Examples:
var mimeTypes = require('mimeTypes');
mimeTypes.setDefaultMimeType('text/plain');
mimeTypes uses Wakanda's implementation of YUI Test.
- Copy
mimeTypesTest.waPage
into your Wakanda project's WebFolder. - Copy
testCases.js
into thescripts
folder in your Wakanda project's WebFolder. - In Wakanda Studio, open
mimeTypesTest.waPage
. - Click Run File. The results should appear in your web browser.
- Copy
testCases.js
into your Wakanda project'sModules
folder. - Copy
test.js
into your Wakanda project as a server-side script. - In Wakanda Studio, open
test.js
. - Click Run File. Doing so will create a
testResults.html
file in the same location as thetest.js
file. The results should appear in your browser automatically. If they do not, open thetestResults.html
file.
If you contribute to this library, just modify mimeTypes.js
and testCases.js
and send a pull
request. Please remember to update the markdown if the public interface changes.
Licensed under MIT.
Copyright (C) 2013 Jeff Grann jeff@successware.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.