MimeType
Represents a MIME type associated with a particular plugin.
Usage
To use this module, you first need to import the MimeType class:
import { MimeType } from '@ponsetya/core'
Constructor
Constructs a new MimeType object.
new MimeType(type: string): MimeType
Parameters
- type:
string
- The MIME type string.
Examples
const mime = new MimeType('application/json')
console.log(mime.extension) // json
Properties
type:
string | undefined
- The MIME type string.
charset:
string | undefined
- The character set of the MIME type.
source:
MimeTypeSource | undefined
- The source of the MIME type.
compressible:
boolean | undefined
- The source of the MIME type.
extension:
string | undefined
- The default extension associated with the MIME type.
extensions:
string[] | undefined
- An array of all extensions associated with the MIME type.
Static Methods
MimeType.find()
Finds the first MIME type entry in the mimetypes array that satisfies the provided testing function.
MimeType.find(
predicate: (value: MimeTypeEntry, index: number) => boolean | undefined
): MimeTypeEntry | undefined
Parameters
- predicate:
function
A function that accepts a MIME type entry and returns a boolean value indicating whether the entry satisfies a certain condition.
- Returns:
MimeTypeEntry | undefined
The first MIME type entry that satisfies the testing function, or undefined if none is found.
Examples
const result = MimeType.find((entry) => entry.type === 'application/json')
console.log(result)
// {
// type: 'application/json',
// charset: 'UTF-8',
// source: 'iana',
// compressible: true,
// extension: 'json',
// extensions: ['json', 'map'],
// }
MimeType.filter()
Returns an array of all MIME type entries in the mimetypes array that satisfy the provided testing function.
MimeType.filter(
predicate: (value: MimeTypeEntry, index: number) => boolean | undefined
): MimeTypeEntry[] | undefined
Parameters
- predicate:
function
A function that accepts a MIME type entry and returns a boolean value indicating whether the entry satisfies a certain condition.
- Returns:
MimeTypeEntry[] | undefined
The first MIME type entry that satisfies the testing function, or undefined if none is found.
Examples
const results = MimeType.filter((entry) => entry.type === 'application/json')
console.log(results)
// [{
// type: 'application/json',
// charset: 'UTF-8',
// source: 'iana',
// compressible: true,
// extension: 'json',
// extensions: ['json', 'map'],
// }]