@jadsonlucena/mediatypes

1.0.0 • Public • Published

MediaTypes

CodeQL Test Coverage Status JavaScript Style Guide Conventional Commits

This is a comprehensive compilation of media types under the RFC-6838 protocol that may be periodically updated through the following projects: Apache, NGINX and Debian

What is

A file's extension has no meaning on the web. In order for the client to interpret the document correctly, the media type must be sent in the Content-Type header.

Interfaces

/**
 * @constructor
 * @fires MediaTypes#update
 * @fires MediaTypes#error
 * 
 * @throws {TypeError} Invalid updateInterval
 */
constructor(updateInterval?: number = 86400000)
// Getters
list(): { [extension: string]: MIMEType[] } // List of all extensions with their media types
updateInterval(): number
versions(): { apache: string, debian: string, nginx: string }
// Setters
/**
 * Periodic database update in milliseconds. if less than zero, will be disabled
 * 
 * @fires MediaTypes#update
 * @fires MediaTypes#error
 * 
 * @throws {TypeError} Invalid updateInterval
 * @see https://developer.mozilla.org/en-US/docs/Web/API/setInterval#delay
 */
updateInterval(updateInterval?: number = 86400000): void
/**
 * @method
 * @throws {TypeError} Invalid extension
 * @throws {SyntaxError} Invalid extension
 * @throws {TypeError} Invalid mediaType
 * @throws {SyntaxError} Invalid mediaType
 */
delete(
    extension: string
    mediaType: string, // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#structure_of_a_mime_type
): boolean

/**
 * @method
 * @throws {TypeError} Invalid path
 * @throws {SyntaxError} Invalid extension
 */
get(
    path: string // https://nodejs.org/api/path.html#pathparsepath
): MIMEType[] // https://nodejs.org/api/util.html#class-utilmimetype

/**
 * @method
 * @throws {TypeError} Invalid extension
 * @throws {SyntaxError} Invalid extension
 * @throws {TypeError} Invalid mediaType
 * @throws {SyntaxError} Invalid mediaType
 */
set(
    extension: string
    mediaType: string, // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#structure_of_a_mime_type
): boolean

/**
 * @method
 * @fires MediaTypes#update
 */
update(force?: boolean = false): Promise<null | { [extension: string]: MIMEType[] }> // List of new inserted media types
// Events
on('update', callback: (list: { [extension: string]: MIMEType[] }) => void): void
on('error', callback: (error: Error) => void): void

This module extends the main methods of the EventEmitter module:

Specifications

We strive to maintain complete code coverage in tests. With that, we provide all the necessary use cases for a good understanding of how this module works. See: test/MediaTypes.spec.js

Package Sidebar

Install

npm i @jadsonlucena/mediatypes

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

83.8 kB

Total Files

5

Last publish

Collaborators

  • jadsonlucena