-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/strings #147
Merged
Merged
Feature/strings #147
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5af19f
Add buildString() and .toChar() function
ghasemdev 2155035
Update README.md
ghasemdev 52a210e
Add console function like print args and read line
ghasemdev 7f48a65
Update README.md
ghasemdev 6a3102e
Remove console functions
ghasemdev 50d380d
Add strings function (orEmpty, isHttp, urlEncode, urlDecode, matches)
ghasemdev a08b97d
Update README.md
ghasemdev bd4cb88
Update pubspec.yaml
ghasemdev d6020b3
Add new string methods
ghasemdev f873189
Update README.md
ghasemdev ff15d8d
Remove not yet mergeable function
passsy 2d58b25
Merge branch 'master' into feature/strings
passsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
[![Dart CI](https://github.com/leisim/dartx/workflows/Dart%20CI/badge.svg?branch=master)](https://github.com/leisim/dartx/actions) [![Codecov](https://img.shields.io/codecov/c/github/leisim/dartx.svg)](https://codecov.io/gh/leisim/dartx) [![dartx](https://img.shields.io/pub/v/dartx?label=dartx)](https://pub.dev/packages/dartx) [![flutterx](https://img.shields.io/pub/v/flutterx?label=flutterx)](https://pub.dev/packages/flutterx) | ||
|
||
*If you miss an extension, please open an issue or pull request* | ||
_If you miss an extension, please open an issue or pull request_ | ||
|
||
### Resources: | ||
|
||
|
@@ -95,6 +95,20 @@ the predicate _didn't_ match. | |
|
||
## int | ||
|
||
### buildString() | ||
|
||
Builds new string by populating newly created `StringBuffer` using provided `builderAction` | ||
and then converting it to `String`. | ||
|
||
```dart | ||
final word = buildString((sb) { | ||
for (var i = 0; i < 10; i++) { | ||
sb.write(i); | ||
} | ||
}); | ||
// 0123456789 | ||
``` | ||
|
||
### .ordinal | ||
|
||
Returns an ordinal number of `String` type for any integer | ||
|
@@ -123,15 +137,15 @@ Returns a copy of the string having its first letter lowercased, or the original | |
final word = 'abcd'.decapitalize(); // abcd | ||
final anotherWord = 'Abcd'.decapitalize(); // abcd | ||
``` | ||
|
||
### .isAscii | ||
|
||
Returns `true` if the string is ASCII encoded. | ||
|
||
```dart | ||
final isAscii = 'abc123 !,.~'.isAscii; // true | ||
final isNotAscii = '§3'.isAscii; // false | ||
```` | ||
``` | ||
|
||
### .isBlank | ||
|
||
|
@@ -262,6 +276,26 @@ final a = 'abc'.md5; // 900150983cd24fb0d6963f7d28e17f72 | |
final b = 'ഐ⌛酪Б👨👨👧👦'.md5; // c7834eff7c967101cfb65b8f6d15ad46 | ||
``` | ||
|
||
### .urlEncode | ||
|
||
Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. | ||
|
||
```dart | ||
const originalUrl = 'Hello Ladies + Gentlemen, a signed OAuth request!'; | ||
final encodedUrl = originalUrl.urlEncode; | ||
// 'Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!' | ||
``` | ||
|
||
### .urlDecode | ||
|
||
Decodes an application/x-www-form-urlencoded string using a specific encoding scheme. | ||
|
||
```dart | ||
const encodedUrl = 'Hello%20Ladies%20+%20Gentlemen,%20a%20signed%20OAuth%20request!'; | ||
final decodedUrl = encodingUrl.urlDecode; | ||
// 'Hello Ladies + Gentlemen, a signed OAuth request!' | ||
``` | ||
|
||
### .removePrefix(), .removeSuffix() and .removeSurrounding() | ||
|
||
Remove a prefix, a suffix, or both from a given string: | ||
|
@@ -343,7 +377,25 @@ final hi = 'hi'.toUtf16(); // [104, 105] | |
final emoji = '😄'.toUtf16(); // [55357, 56836] | ||
``` | ||
|
||
## Time utils | ||
### .orEmpty() | ||
|
||
Returns the string if it is not `null`, or the empty string otherwise. | ||
|
||
```dart | ||
String? nullableStr; | ||
final str = nullableStr.orEmpty(); // '' | ||
``` | ||
|
||
### .matches() | ||
|
||
Returns `true` if this char sequence matches the given regular expression. | ||
|
||
```dart | ||
print('as'.matches(RegExp('^.s\$'))) // true | ||
print('mst'.matches(RegExp('^.s\$'))) // false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love it |
||
``` | ||
|
||
### Time utils | ||
|
||
Dartx exports [@jogboms](https://github.com/jogboms) great [⏰ time.dart](https://github.com/jogboms/time.dart) package so you can do the following: | ||
|
||
|
@@ -372,6 +424,14 @@ final numberOutOfRange = -123.coerceIn(0, 1000); // 0 | |
|
||
Converts this value to binary form. | ||
|
||
### .toChar() | ||
|
||
Converts this value to character | ||
|
||
```dart | ||
final character = 97.toChar(); // a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
``` | ||
|
||
## range | ||
|
||
### rangeTo | ||
|
@@ -454,7 +514,6 @@ Directory androidDir = Directory('flutter-app/android'); | |
Directory mainSrc = androidDir.directory("app/src/main"); | ||
``` | ||
|
||
|
||
### .contains(FileSystemEntity entity, {bool recursive = false}) | ||
|
||
Checks if a `Directory` contains a `FileSystemEntity`. This can be a `File` or a `Directory`. | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fantastic!