MIMEType class
根據瀏覽器慣例,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