Baseline Widely available
Intl.ListFormat
æ¯ä¸ä¸ªè¯è¨ç¸å
³çåè¡¨æ ¼å¼åæé å¨ã
const vehicles = ["Motorcycle", "Bus", "Car"];
const formatter = new Intl.ListFormat("en", {
style: "long",
type: "conjunction",
});
console.log(formatter.format(vehicles));
// Expected output: "Motorcycle, Bus, and Car"
const formatter2 = new Intl.ListFormat("de", {
style: "short",
type: "disjunction",
});
console.log(formatter2.format(vehicles));
// Expected output: "Motorcycle, Bus oder Car"
const formatter3 = new Intl.ListFormat("en", { style: "narrow", type: "unit" });
console.log(formatter3.format(vehicles));
// Expected output: "Motorcycle Bus Car"
è¯æ³
new Intl.ListFormat([locales[, options]])åæ°
locales
å¯éç.ã符å BCP 47 è¯è¨æ 注çå符串æå符串æ°ç»ãlocales
åæ°çä¸è¬å½¢å¼åç¸å
³è§£éï¼è¯·åé
Intl page.
options
å¯éçãæ¥æä¸é¢æå屿§ä¸ä»»æå 个æå ¨é¨ç对象ï¼
localeMatcher
æå®è¦ä½¿ç¨çæ¬å°å¹é
ç®æ³ãå¯éç弿"lookup"
å "best fit"
ï¼é»è®¤æ
åµä¸ä½¿ç¨"best fit"
ãè¯¥åæ°çæ´å¤ä¿¡æ¯ï¼è¯·åèIntl
page.type
æ¶æ¯è¾åºçæ ¼å¼ãå¯éç弿ç¨äºæ¿ä»£åºäºâä¸âå
³ç³»å表ç"conjunction"
(é»è®¤å¼ï¼ä¾å¦ï¼ A, B, and C
)ï¼æè
ç¨äºæ¿ä»£åºäºâæâå
³ç³»å表ç "disjunction"
(ä¾å¦ï¼ A, B, or C
)ï¼ä»¥åç¨äºæ¿ä»£å¸¦è®¡éåä½çå¼å表ç"unit"
(ä¾å¦ï¼ 5 pounds, 12 ounces
).style
è¢«æ ¼å¼åæ¶æ¯çé¿åº¦ãå¯é弿ï¼"long"
(é»è®¤å¼ï¼ä¾å¦ï¼A, B, and C
)ã"short"
æè
"narrow"
(ä¾å¦ï¼A, B, C
)ãå½style
çå¼ä¸ºnarrow
æ¶ï¼type 屿§çå¼åªè½åå¼unit
ãIntl.ListFormat.prototype
å 许å¢å ä¸ä¸ªå±æ§å°å表ä¸çææå¯¹è±¡ã
Intl.ListFormat.supportedLocalesOf()
è¿åä¸ä¸ªå 嫿å®çè¢«æ¯æåºåè®¾ç½®çæ°ç»ï¼æ²¡ææ¶ä½¿ç¨è¿è¡ç¯å¢é»è®¤åºå设置
format
ä¸é¢çä¾åå±ç¤ºäºç¨è±è¯è¯è¨æä¹å»å建ä¸ä¸ªåè¡¨æ ¼å¼åå¨ã
const list = ["Motorcycle", "Bus", "Car"];
console.log(
new Intl.ListFormat("en-GB", { style: "long", type: "conjunction" }).format(
list,
),
);
// > Motorcycle, Bus and Car
console.log(
new Intl.ListFormat("en-GB", { style: "short", type: "disjunction" }).format(
list,
),
);
// > Motorcycle, Bus or Car
console.log(
new Intl.ListFormat("en-GB", { style: "narrow", type: "unit" }).format(list),
);
// > Motorcycle Bus Car
ä½¿ç¨ formatToParts
ä¸é¢çä¾åå±ç¤ºäºå¦ä½å建ä¸ä¸ªè¿åè¢«æ ¼å¼åé¨åçåè¡¨æ ¼å¼åå¨ã
const list = ["Motorcycle", "Bus", "Car"];
console.log(
new Intl.ListFormat("en-GB", {
style: "long",
type: "conjunction",
}).formatToParts(list),
);
// > [ { "type": "element", "value": "Motorcycle" }, { "type": "literal", "value": ", " }, { "type": "element", "value": "Bus" }, { "type": "literal", "value": ", and " }, { "type": "element", "value": "Car" } ];
è§è æµè§å¨å
¼å®¹æ§ åè§
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4