libj-mime
v1.1.0
Published
- Checking mime types and showing related file icons. - Giving associated file icon image file for a file extension or media type
Downloads
1
Readme
libj-mime
Part of libj tools
- Checking mime types and showing related file icons.
- Giving associated file icon image file for a file extension or media type
Copy file-icon-set folder somewhere on your server
Usage (npm)
npm install libj-mime
import { mimeHelper } from 'libj-mime'
These are from test/test.js to show you the methods:
//We must set options one time
var o = {
fileIconPath: '/file-icon-set'
};
mimeHelper.setOptions(o)
it('set options', function() {
assert.deepEqual(o, mimeHelper.options);
})
it('get extension from media type', function() {
var k = mimeHelper.getExtension('image/png');
assert.equal('.png', k)
})
it('get media type from extension', function() {
var k = mimeHelper.getMediaType('png')
assert.equal('image/png', k)
k = mimeHelper.getMediaType('.png')
assert.equal('image/png', k)
})
it('get icon path for extension', function() {
var k = mimeHelper.getIconPathForExtension('.png', 24)
assert.equal(`${o.fileIconPath}/png-icon-24x24.png`, k)
})
it('get icon path for url', function() {
var k = mimeHelper.getIconPathForUrl('/some-folder/some-file.png', 24)
assert.deepEqual(`${o.fileIconPath}/png-icon-24x24.png`, k)
})
Test
- Run this in a separate command line to start node server
node server.js
- Run one of the following to re-create bundles
npm run dev
npm run dev:watch
- Navigate to http://localhost:3000
Build
npm run build
npm run build:watch