From fd47fdad29f03657acc4826e2a909fca497e6adc Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 26 Apr 2021 01:40:16 +0900 Subject: Intl.ListFormat.formatToParts() を更新 (#491) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2021/03/29 時点の英語版に同期 --- .../intl/listformat/formattoparts/index.html | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.html (limited to 'files/ja/web/javascript/reference') diff --git a/files/ja/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.html new file mode 100644 index 0000000000..af8fce9eab --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.html @@ -0,0 +1,92 @@ +--- +title: Intl.ListFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts +tags: + - Internationalization + - Intl + - JavaScript + - ListFormat + - Localization + - Method + - Prototype + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts +--- +
{{JSRef}}
+ +

Intl.ListFormat.prototype.formatToParts() メソッドは、ロケールを意識した値のリストの書式化で使用できる様々な部分を表すオブジェクトの配列を返します。

+ +

構文

+ +
Intl.ListFormat.prototype.formatToParts(list)
+
+ +

引数

+ +
+
list
+
ロケールに従って書式化するための値の {{jsxref("Array")}} です。
+
+ +

返値

+ +

リストから書式された部品を含むコンポーネントの {{jsxref("Array")}} です。

+ +

解説

+ +

{{jsxref("Intl/ListFormat/format", "Intl.ListFormat.prototype.format()")}} は、 (渡されたロケールとスタイルのオプションに応じて) リストの書式化された文字列を返すのに対し、 formatToParts() は、書式化されたされた文字列のさまざまなコンポーネントの配列を返します。

+ +

フォーマットに使用されるロケールとスタイルのオプションは、Intl.ListFormatインスタンスを構築する際に与えられます。結果として得られる配列の各要素には、 typevalue という 2 つのプロパティがあります。 type プロパティには、リストの値を表す "element" か、言語構造を表す "literal" のいずれかを指定します。 value プロパティは、トークンの内容を文字列で表したものです。

+ +

フォーマットに使用されるロケールとスタイルのオプションは、 {{jsxref("Intl.ListFormat")}} インスタンスを構築する際に与えられます。

+ +

+ +

formatToParts の使用

+ +
const fruits = ['Apple', 'Orange', 'Pineapple'];
+const myListFormat = new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' });
+
+console.table(myListFormat.formatToParts(fruits));
+// [
+//  { "type": "element", "value": "Apple" },
+//  { "type": "literal", "value": ", " },
+//  { "type": "element", "value": "Orange" },
+//  { "type": "literal", "value": ", and " },
+//  { "type": "element", "value": "Pineapple" }
+// ]
+
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('Intl.ListFormat', + '#sec-Intl.ListFormat.prototype.formatToParts', 'formatToParts()')}}
+ +

ブラウザーの互換性

+ +
{{Compat("javascript.builtins.Intl.ListFormat.formatToParts")}}
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf