Skip to content

Commit

Permalink
Switch from part structure to export layout
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Jul 16, 2023
1 parent 34cfa79 commit a6bd37f
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 63 deletions.
35 changes: 13 additions & 22 deletions lib/dartx.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
/// Superpowers for Dart. Collection of useful static extension methods.
library dartx;

import 'dart:collection';
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';

import 'package:characters/characters.dart' as characters;
import 'package:collection/collection.dart' as collection;
import 'package:crypto/crypto.dart' as crypto;

export 'package:characters/characters.dart';
export 'package:time/time.dart';

part 'src/arithmetic.dart';
part 'src/comparable.dart';
part 'src/comparator.dart';
part 'src/function.dart';
part 'src/int.dart';
part 'src/iterable.dart';
part 'src/iterable_num.dart';
part 'src/list.dart';
part 'src/map.dart';
part 'src/num.dart';
part 'src/range.dart';
part 'src/sorted_list.dart';
part 'src/string.dart';
export 'src/arithmetic.dart';
export 'src/comparable.dart';
export 'src/comparator.dart';
export 'src/function.dart';
export 'src/int.dart';
export 'src/iterable.dart';
export 'src/iterable_num.dart';
export 'src/list.dart';
export 'src/map.dart';
export 'src/num.dart';
export 'src/range.dart';
export 'src/sorted_list.dart';
export 'src/string.dart';
12 changes: 3 additions & 9 deletions lib/dartx_io.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/// Superpowers for Dart IO. Collection of useful static extension methods.
library dartx_io;

import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:path/path.dart' as path_helper;

export 'dartx.dart';

part 'src/io/directory.dart';
part 'src/io/file_system_entity.dart';
part 'src/io/file.dart';
export 'src/io/directory.dart';
export 'src/io/file.dart';
export 'src/io/file_system_entity.dart';
2 changes: 0 additions & 2 deletions lib/src/arithmetic.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

extension NumArithmeticX<T extends num> on T {
/// Minus val if if it not null else returns `this`
T? minus(T? val) => val == null ? this : this - val as T?;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/comparable.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of dartx;
import 'package:dartx/dartx.dart';

/// Provides comparison operators for [Comparable] types.
extension ComparableSmallerExtension<T extends Comparable<T>> on T {
Expand Down
2 changes: 0 additions & 2 deletions lib/src/comparator.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

extension CompararatorComposeExtensions<T> on Comparator<T> {
/// return a new comparator,
/// that sorts the items first by the criteria of this comparator,
Expand Down
2 changes: 0 additions & 2 deletions lib/src/function.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

typedef Function0<R> = R Function();
typedef Function1<A, R> = R Function(A a);
typedef Function2<A, B, R> = R Function(A a, B b);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/int.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

extension Ordinals<T extends int> on T {
/// Returns an ordinal number of `String` type for any integer
///
Expand Down
4 changes: 3 additions & 1 deletion lib/src/io/directory.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of dartx_io;
import 'dart:io';

import 'package:path/path.dart' as path_helper;

extension DirectorySubDirExtension on Directory {
Directory subdir(
Expand Down
4 changes: 3 additions & 1 deletion lib/src/io/file.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of dartx_io;
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

extension FileAppendBytesExtension on File {
/// Appends an array of [bytes] to the content of this file.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/io/file_system_entity.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of dartx_io;
import 'dart:io';

import 'package:path/path.dart' as path_helper;

extension FileSystemEntityNameExtension on FileSystemEntity {
/// Gets the part of [path] after the last separator.
Expand Down
12 changes: 8 additions & 4 deletions lib/src/iterable.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
part of dartx;
import 'dart:collection';
import 'dart:math';

import 'package:collection/collection.dart' as collection;
import 'package:dartx/src/sorted_list.dart';

extension IterableSecondItem<E> on Iterable<E> {
/// Second element.
Expand Down Expand Up @@ -278,7 +282,7 @@ extension IterableSortedBy<E> on Iterable<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> sortedBy(Comparable Function(E element) selector) {
return SortedList<E>._withSelector(this, selector, 1, null);
return SortedList<E>.withSelector(this, selector, 1, null);
}
}

Expand All @@ -293,7 +297,7 @@ extension IterableSortedByDescending<E> on Iterable<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> sortedByDescending(Comparable Function(E element) selector) {
return SortedList<E>._withSelector(this, selector, -1, null);
return SortedList<E>.withSelector(this, selector, -1, null);
}
}

Expand All @@ -307,7 +311,7 @@ extension IterableSortedWith<E> on Iterable<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> sortedWith(Comparator<E> comparator) {
return SortedList<E>._(this, comparator);
return SortedList<E>(this, comparator);
}
}

Expand Down
2 changes: 0 additions & 2 deletions lib/src/iterable_num.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

/// Extensions for iterables
extension IterableNumSumExtension<T extends num> on Iterable<T> {
/// Returns the sum of all elements in the collection.
Expand Down
4 changes: 1 addition & 3 deletions lib/src/list.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// ignore_for_file: deprecated_member_use

part of dartx;
import 'package:collection/collection.dart' as collection;

extension ListExtension<E> on List<E> {
/// Index of the first element or -1 if the collection is empty.
Expand Down
2 changes: 0 additions & 2 deletions lib/src/map.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of dartx;

extension MapAll<K, V> on Map<K, V> {
/// Returns true if all entries match the given [predicate].
/// [predicate] must not be null.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/num.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of dartx;
import 'dart:typed_data';

import 'package:dartx/dartx.dart';

extension NumCoerceInExtension<T extends num> on T {
/// Ensures that this value lies in the specified range
Expand Down
2 changes: 1 addition & 1 deletion lib/src/range.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of dartx;
import 'dart:collection';

/// Represents a range of values (for example, numbers or characters)
/// with a fixed [start] value and a fixed [endInclusive] value.
Expand Down
13 changes: 7 additions & 6 deletions lib/src/sorted_list.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
part of dartx;
import 'dart:math';
import 'package:dartx/dartx.dart';

Comparator<E> _getComparator<E>(
int order,
Expand All @@ -17,12 +18,12 @@ class SortedList<E> extends _DelegatingList<E> {
final Comparator<E> _comparator;
List<E>? _sortedResults;

SortedList._(
SortedList(
this._source,
this._comparator,
);

SortedList._withSelector(
SortedList.withSelector(
this._source,
Comparable Function(E element) selector,
int order,
Expand All @@ -45,7 +46,7 @@ class SortedList<E> extends _DelegatingList<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> thenBy(Comparable Function(E element) selector) {
return SortedList<E>._withSelector(this, selector, 1, _comparator);
return SortedList<E>.withSelector(this, selector, 1, _comparator);
}

/// Returns a new list with all elements sorted according to previously
Expand All @@ -55,7 +56,7 @@ class SortedList<E> extends _DelegatingList<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> thenByDescending(Comparable Function(E element) selector) {
return SortedList<E>._withSelector(this, selector, -1, _comparator);
return SortedList<E>.withSelector(this, selector, -1, _comparator);

Check warning on line 59 in lib/src/sorted_list.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/sorted_list.dart#L59

Added line #L59 was not covered by tests
}

/// Returns a new list with all elements sorted according to previously
Expand All @@ -64,7 +65,7 @@ class SortedList<E> extends _DelegatingList<E> {
/// **Note:** The actual sorting is performed when an element is accessed for
/// the first time.
SortedList<E> thenWith(Comparator<E> comparator) {
return SortedList<E>._(this, _comparator.compose(comparator));
return SortedList<E>(this, _comparator.compose(comparator));

Check warning on line 68 in lib/src/sorted_list.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/sorted_list.dart#L68

Added line #L68 was not covered by tests
}

@override
Expand Down
5 changes: 4 additions & 1 deletion lib/src/string.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
part of dartx;
import 'dart:convert';

import 'package:characters/characters.dart' as characters;
import 'package:crypto/crypto.dart' as crypto;

const _ascii = 0x007f;
const _latin1 = 0x00ff;
Expand Down

0 comments on commit a6bd37f

Please sign in to comment.