@nlib/content-type

Returns content-type from file extension

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Mar 18, 2019Nov 20, 2017Minified + gzip package size for @nlib/content-type in KB

Readme

@nlib/content-type

Build Status Build status codecov dependencies Status devDependencies Status

Returns a content type from file extension.

Install

npm install @nlib/content-type

Usage

const ContentType = require('@nlib/content-type');
const contentType = new ContentType();

// return a content-type
console.log(contentType.get('foo/bar.html'));
// text/html

// returns an extension
console.log(contentType.getExtname('application/json'));
// .json

// returns the default content-type if nothing matched.
console.log(contentType.get('foo/bar.bar'));
// text/plain

// changes the default content-type
contentType.defaultContentType = 'unknown/type';
console.log(contentType.get('foo/bar.bar'));
// unknown/type

// maps content-type to file extensions
contentType.set('test/baz', ['bar', 'baz']);
console.log(contentType.get('foo/bar.bar'));
// test/baz
console.log(contentType.get('foo/bar.baz'));
// test/baz
console.log(contentType.getExtname('test/baz'));
// .bar

Javascript API

See Usage section.

LICENSE

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.