Constructor: new MIMEType(input)
input
<string> 要解析的输入 MIME
通过解析 input
创建一个新的 MIMEType
对象。
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
。
注意,会将给定的值强制转换为字符串。
例如:
import { MIMEType } from 'node:util';
const myMIME = new MIMEType({ toString: () => 'text/plain' });
console.log(String(myMIME));
// 打印: text/plain
const { MIMEType } = require('node:util');
const myMIME = new MIMEType({ toString: () => 'text/plain' });
console.log(String(myMIME));
// 打印: text/plain
input
<string> The input MIME to parse
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');
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/plain
const { MIMEType } = require('node:util');
const myMIME = new MIMEType({ toString: () => 'text/plain' });
console.log(String(myMIME));
// Prints: text/plain