new MIMEType(input)


  • input <string> 要解析的输入 MIME

通过解析 input 创建一个新的 MIMEType 对象。

【Creates a new MIMEType object by parsing the input.】

import { MIMEType } from 'node:util';

const myMIME = new MIMEType('text/plain');const { MIMEType } = require('node:util');

const myMIME = new MIMEType('text/plain');

如果 input 不是有效的 MIME,将会抛出 TypeError。请注意,会尝试将给定的值强制转换为字符串。例如:

【A TypeError will be thrown if the input is not a valid MIME. Note that an effort will be made to coerce the given values into strings. For instance:】

import { MIMEType } from 'node:util';
const myMIME = new MIMEType({ toString: () => 'text/plain' });
console.log(String(myMIME));
// Prints: text/plainconst { MIMEType } = require('node:util');
const myMIME = new MIMEType({ toString: () => 'text/plain' });
console.log(String(myMIME));
// Prints: text/plain