0.9.2 • Published 2 years ago

mime-types-no-nodejs v0.9.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

npm

About

Convert mime type to and from document type.

Reference:

W3cubDocs/http

Credits

Source modified from jshttp/mime-types.

Why?

  1. Removed Node.js dependency.

See #50.

  1. Re-write in typescript.

Qick start

install dependency

    npm install mime-types-no-nodejs

run test (with source)

    npm install
    npm test

API

    import Mime from 'mime-types-no-nodejs';
  • lookup()

Lookup the MIME type for a file / path extension.

    /**
     * @param {string} path
     * @return {boolean|string} false when failed
     */
    function lookup (path);
  • extension()

Get the default extension for a MIME type.

    /**
     * @param {string} type
     * @return {boolean|string} doc type or false if failed
     */
    function extension (type);

Testing code snippet:

    // test/no-node.js
    import Mime from '../index';

    it('mime2type', () => {
        assert.equal(Mime.extension('image/png;base64'), 'png');
    });

    it('type2mime', () => {
        assert.equal(Mime.lookup('png'), 'image/png');
    });