1.1.1 • Published 6 years ago

@nlib/content-type v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@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

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago