构造器:new MIMEType(input)
¥Constructor: new MIMEType(input)
通过解析 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