Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Sep 6, 2024
1 parent 7290fd1 commit cf9c1d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkgs/intl4x/lib/datetime_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
29 changes: 27 additions & 2 deletions pkgs/intl4x/lib/list_format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
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);
}
4 changes: 3 additions & 1 deletion pkgs/intl4x/test/list_format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

0 comments on commit cf9c1d7

Please sign in to comment.