You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for your pull request. Extension methods are a good idea. Thanks for adding tests too.
I'd recommend a minor change on the API for some of the methods, especially the boolean isFoo methods. Let's use a getter instead of a regular method. Thus, myString.isEmail() would become myString.isEmail. This is more consistent with the current boolean getters on String (for example, myString.isEmpty). Other methods like '123'.toDouble() can retain the parentheses.
Here is some advice from ChatGPT about when to use getters or not:
In Dart and Flutter, the choice between using a getter method (e.g., foo.isSomething) and a regular method (e.g., foo.isSomething()) often depends on the nature of the operation and the convention within the community. Here are some guidelines:
Use a getter when:
The operation is side-effect-free. It shouldn't modify any state.
The operation is relatively quick to perform. It shouldn't involve complex computations, I/O operations, or network requests.
You're retrieving a property that logically belongs to the object, or you want to compute something on-the-fly based on the object's existing state.
Use a method when:
The operation has side effects or modifies the object's state.
The operation is computationally expensive, involves I/O, or makes network requests.
You need to pass additional arguments to compute the value or perform the operation.
You want to make it explicit that the operation performs something more than just fetching a property.
Examples
Getter: list.isEmpty checks whether a list is empty. This is side-effect-free and quick, and it's a property of the list.
Method: list.removeLast() removes the last item from the list. This has a side effect and thus is a method.
In designing your API, if isSomething represents a state or property of foo that can be determined quickly and without side effects, a getter (foo.isSomething) would be appropriate. If it's an operation that's more complex, has side effects, or requires additional arguments, then a method (foo.isSomething()) would be more fitting.
For idiomatic Dart code, following these guidelines is generally a good practice.
This file contains hidden or 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.
added extensions methods all of validators and most of sanitizers