MIMEType class
MIMEType 类
根据浏览器约定,MIMEType 对象的所有属性作为类原型上的 getter 和 setter 实现,而不是作为对象本身的数据属性实现。
MIME 字符串是包含多个有意义的组件的结构化字符串。 分析后,将返回一个 MIMEType 对象,其中包含每个组件的属性。
构造函数
| MIMEType(string | { to |
通过分析输入创建新的 MIMEType 对象。 如果 |
属性
| essence | 获取 MIME 的本质。 此属性为只读。
使用
|
| params | 获取表示 MIME 参数的 |
| subtype | 获取和设置 MIME 的子类型部分。
|
| type | 获取和设置 MIME 的类型部分。
|
方法
| to |
由于需要标准符合性,此方法不允许用户自定义 MIME 的序列化过程。 |
构造函数详细信息
MIMEType(string | { toString: () => string })
通过分析输入创建新的 MIMEType 对象。
如果 TypeError 不是有效的 MIME,将引发 input。
请注意,将努力将给定值强制转换为字符串。
new MIMEType(input: string | { toString: () => string })
参数
- input
-
string | { toString: () => string }
要分析的输入 MIME。
属性详细信息
essence
获取 MIME 的本质。 此属性为只读。
使用 mime.type 或 mime.subtype 更改 MIME。
import { MIMEType } from 'node:util';
const myMIME = new MIMEType('text/javascript;key=value');
console.log(myMIME.essence);
// Prints: text/javascript
myMIME.type = 'application';
console.log(myMIME.essence);
// Prints: application/javascript
console.log(String(myMIME));
// Prints: application/javascript;key=value
essence: string
属性值
string
params
subtype
获取和设置 MIME 的子类型部分。
import { MIMEType } from 'node:util';
const myMIME = new MIMEType('text/ecmascript');
console.log(myMIME.subtype);
// Prints: ecmascript
myMIME.subtype = 'javascript';
console.log(myMIME.subtype);
// Prints: javascript
console.log(String(myMIME));
// Prints: text/javascript
subtype: string
属性值
string
type
获取和设置 MIME 的类型部分。
import { MIMEType } from 'node:util';
const myMIME = new MIMEType('text/javascript');
console.log(myMIME.type);
// Prints: text
myMIME.type = 'application';
console.log(myMIME.type);
// Prints: application
console.log(String(myMIME));
// Prints: application/javascript
type: string
属性值
string
方法详细信息
toString()
toString() 对象的 MIMEType 方法返回序列化的 MIME。
由于需要标准符合性,此方法不允许用户自定义 MIME 的序列化过程。
function toString(): string
返回
string