1.1.1 • Published 6 years ago
@nlib/content-type v1.1.1
@nlib/content-type
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