JavaScript

Intl.ListFormat() コンストラクター


編集:2023.01.09 by T.A.

[Edge]。→

言語を考慮したリストの書式化を可能にする Intl.ListFormat オブジェクトを生成して返します。

構文
new Intl.ListFormat([locales[, options]])
locales 省略可 言語コードの文字列、またはそのような文字列の配列。→Intl:locales

省略した場合は、¶システムのロケール?

options 省略可。以下のプロパティを 1 つ以上持つオブジェクト。
localeMatcher
ロケール照合アルゴリズムを表す文字列。値は以下の何れか。
lookup
best fit (既定値)

Intl:マッチング アルゴリズム

type
リスト化の種類を表す文字列。値は以下の何れか。
DA=new Intl.ListFormat(○○);
D=DA.format(["A", "B", "C"]);
conjunction リスト項目の "and" ベースのリスト化。(既定値)

D: 「A、B、C」('ja', {type:'conjunction'})

D: 「A, B, and C」('en', {type:'conjunction'})

disjunction リスト項目の "or" ベースのリスト化。

D: 「A、B、またはC」('ja', {type:'disjunction'})

D: 「A, B, or C」('en', {type:'disjunction'})

unit リスト項目の単位としてのリスト化。

D: 「A B C」('ja', {type:'unit'})

D: 「A, B, C」('en', {type:'unit'})

style
リスト化のスタイルを表す文字列。値は以下の何れか。
DA=new Intl.ListFormat(○○);
D=DA.format(["A", "B", "C"]);
long (既定値)

D: 「A、B、C」('ja', {style:'long'})

D: 「A, B, and C」('en', {style:'long'})

short

D: 「A、B、C」('ja', {style:'short'})

D: 「A, B, & C」('en', {style:'short'})

narrow

D: 「A、B、C」('ja', {style:'narrow'})

D: 「A, B, C」('en', {style:'narrow'})

Lst=["Cat", "Dog", "Panda"];
DA=new Intl.ListFormat('ja');  //日本語。
D=DA.format(Lst);  //=[string]:Cat、Dog、Panda
DA=new Intl.ListFormat('en');  //英語。
D=DA.format(Lst);  //=[string]:Cat, Dog, and Panda
DA=new Intl.ListFormat('en', {type:'disjunction'});  //英語、リスト化の種類。
D=DA.format(Lst);  //=[string]:Cat, Dog, or Panda
DA=new Intl.ListFormat('ja', {type:'disjunction'});  //日本語、リスト化の種類。
D=DA.format(Lst);  //=[string]:Cat、Dog、またはPanda
DA=new Intl.ListFormat('ja', {type:'conjunction'});  //日本語、リスト化の種類。
D=DA.format(Lst);  //=[string]:Cat、Dog、Panda
DA=new Intl.ListFormat('ja', {style:'short'});  //日本語、リスト化のスタイル。
D=DA.format(Lst);  //=[string]:Cat、Dog、Panda
DA=new Intl.ListFormat('ja', {style:'narrow'});  //日本語、リスト化のスタイル。
D=DA.format(Lst);  //=[string]:Cat、Dog、Panda

Intl.ListFormat.format()format()


テスト