-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/strings
# Conflicts: # README.md # lib/src/string.dart # test/string_test.dart
- Loading branch information
Showing
16 changed files
with
166 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
part of dartx; | ||
|
||
extension Ordinals<T extends int> on T { | ||
/// Returns an ordinal number of `String` type for any integer | ||
/// | ||
/// ```dart | ||
/// 101.ordinal(); // 101st | ||
/// | ||
/// 999218.ordinal(); // 999218th | ||
/// ``` | ||
String ordinal() { | ||
final onesPlace = this % 10; | ||
final tensPlace = ((this / 10).floor()) % 10; | ||
if (tensPlace == 1) { | ||
return '${this}th'; | ||
} else { | ||
switch (onesPlace) { | ||
case 1: | ||
return '${this}st'; | ||
case 2: | ||
return '${this}nd'; | ||
case 3: | ||
return '${this}rd'; | ||
default: | ||
return '${this}th'; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:dartx/dartx.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group( | ||
'intX', | ||
() { | ||
test( | ||
'.ordinal()', | ||
() { | ||
expect(0.ordinal(), '0th'); | ||
expect(1.ordinal(), '1st'); | ||
expect(2.ordinal(), '2nd'); | ||
expect(3.ordinal(), '3rd'); | ||
expect(4.ordinal(), '4th'); | ||
expect(10.ordinal(), '10th'); | ||
expect(101.ordinal(), '101st'); | ||
expect(102.ordinal(), '102nd'); | ||
expect(103.ordinal(), '103rd'); | ||
expect(111.ordinal(), '111th'); | ||
expect(112.ordinal(), '112th'); | ||
expect(113.ordinal(), '113th'); | ||
}, | ||
); | ||
}, | ||
); | ||
} |
Oops, something went wrong.