From cf9c1d77c0c2424e2fa41bb5d0720c17673c2d94 Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 6 Sep 2024 17:03:11 +0200 Subject: [PATCH] Add docs --- pkgs/intl4x/lib/datetime_format.dart | 3 +++ pkgs/intl4x/lib/list_format.dart | 29 ++++++++++++++++++++++++-- pkgs/intl4x/test/list_format_test.dart | 4 +++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkgs/intl4x/lib/datetime_format.dart b/pkgs/intl4x/lib/datetime_format.dart index e41c8e13..07630167 100644 --- a/pkgs/intl4x/lib/datetime_format.dart +++ b/pkgs/intl4x/lib/datetime_format.dart @@ -9,6 +9,9 @@ export 'src/datetime_format/datetime_format_options.dart'; export 'src/options.dart'; extension DateTimeFormatIntl4x on DateTime { + /// Format a date in a locale-dependent manner. + /// + /// For more options, use [Intl.datetimeFormat] directly. String toLocaleDateString([Locale? locale]) => Intl(locale: locale).datetimeFormat().format(this); } diff --git a/pkgs/intl4x/lib/list_format.dart b/pkgs/intl4x/lib/list_format.dart index 96aedee9..bb886897 100644 --- a/pkgs/intl4x/lib/list_format.dart +++ b/pkgs/intl4x/lib/list_format.dart @@ -3,12 +3,37 @@ // BSD-style license that can be found in the LICENSE file. import 'intl4x.dart'; +import 'src/list_format/list_format_options.dart'; export 'src/list_format/list_format.dart'; export 'src/list_format/list_format_options.dart'; export 'src/options.dart'; extension ListFormatIntl4x on List { - String toLocaleFormat([Locale? locale]) => - Intl(locale: locale).listFormat().format(this); + /// Join a list in a locale-dependent manner using `and`-based grouping. + /// + /// Example: "A, B, and C". See also [Type.and]. + /// + /// For more options, use [Intl.listFormat] directly. + String joinAnd([Locale? locale]) => Intl(locale: locale) + .listFormat(const ListFormatOptions(type: Type.and)) + .format(this); + + /// Join a list in a locale-dependent manner using `or`-based grouping. + /// + /// Example: "A, B, or C". See also [Type.or]. + /// + /// For more options, use [Intl.listFormat] directly. + String joinOr([Locale? locale]) => Intl(locale: locale) + .listFormat(const ListFormatOptions(type: Type.or)) + .format(this); + + /// Join a list in a locale-dependent manner using unit-based grouping. + /// + /// Example: "A, B, C". See also [Type.unit]. + /// + /// For more options, use [Intl.listFormat] directly. + String joinUnit([Locale? locale]) => Intl(locale: locale) + .listFormat(const ListFormatOptions(type: Type.or)) + .format(this); } diff --git a/pkgs/intl4x/test/list_format_test.dart b/pkgs/intl4x/test/list_format_test.dart index 6b405f67..29c967dd 100644 --- a/pkgs/intl4x/test/list_format_test.dart +++ b/pkgs/intl4x/test/list_format_test.dart @@ -62,6 +62,8 @@ void main() { }); testWithFormatting('extension', () { - expect(list.toLocaleFormat(enUS), 'A, B, and C'); + expect(list.joinAnd(enUS), 'A, B, and C'); + expect(list.joinOr(enUS), 'A, B, or C'); + expect(list.joinUnit(enUS), 'A, B, C'); }); }