Skip to content

Commit 7c28c48

Browse files
committed
feat: implement missing rules
1 parent d9bca6a commit 7c28c48

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.3.0
2+
- Add missing `VineNotSameAsRule` implementation
3+
- Implement `VineRegexRule` validation rule
4+
- Add related [Dev.to](https://dev.to/baptiste_parmantier/validate-your-data-structures-with-vine-in-your-dart-projects-111p) article
5+
16
## 1.2.0
27
- Move rules from handlers to dedicated classes
38
- Implement OpenAPI reporter

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ ensuring that data complies with an expected format before it is used, which red
2929
Vine is a data structure validation library for Dart. You may use it to validate the HTTP request body or any data in
3030
your backend applications.
3131

32+
> See related [article](https://dev.to/baptiste_parmantier/validate-your-data-structures-with-vine-in-your-dart-projects-111p) in `Dev.to` to discover how to use Vine in your Dart projects.
33+
3234
### Built for validating form data and JSON payloads
3335

3436
Serializing an HTML form to FormData or a JSON object comes with its own set of quirks.

lib/src/contracts/schema.dart

+11
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ abstract interface class VineString implements VineSchema, BasicSchema<VineStrin
310310
/// message: 'The value must not be one of admin or user');
311311
/// ```
312312
VineString notInList(List<String> values, {String? message});
313+
314+
/// Check if the string is a valid regular [RegExp] [expression] the regular expression [message] the error message to display
315+
/// ```dart
316+
/// vine.string().regexp(RegExp(r'^[a-zA-Z]+$'));
317+
/// ```
318+
/// You can specify a custom error message
319+
/// ```dart
320+
/// vine.string().regexp(RegExp(r'^[a-zA-Z]+$'),
321+
/// message: 'The value must contain only alphabetic characters');
322+
/// ```
323+
VineString regex(RegExp expression, {String? message});
313324
}
314325

315326
abstract interface class VineNumber implements VineSchema, BasicSchema<VineNumber> {

lib/src/schema/string_schema.dart

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ final class VineStringSchema extends RuleParser implements VineString {
8282
return this;
8383
}
8484

85+
@override
86+
VineString regex(RegExp expression, {String? message}) {
87+
super.addRule(VineRegexRule(expression, message));
88+
return this;
89+
}
90+
8591
@override
8692
VineString trim() {
8793
super.addRule(VineTrimRule());
@@ -132,6 +138,7 @@ final class VineStringSchema extends RuleParser implements VineString {
132138

133139
@override
134140
VineString notSameAs(String value, {String? message}) {
141+
super.addRule(VineNotSameAsRule(value, message));
135142
return this;
136143
}
137144

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vine
22
description: Vine is a robust, typed validation library for Dart/Flutter, designed to simplify and secure data management in applications
3-
version: 1.2.0
3+
version: 1.3.0
44
repository: https://github.com/LeadcodeDev/vine
55

66
platforms:

0 commit comments

Comments
 (0)