Skip to content

Commit

Permalink
V2
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Aug 24, 2022
1 parent 7df1a20 commit 9e055a9
Show file tree
Hide file tree
Showing 170 changed files with 3,113 additions and 8,943 deletions.
193 changes: 100 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ uses DataValidator;
* Values
* JSON

##### Modo: Values
## Values

- No modo values, o valor informado no **_validate_** é o que será analisado!

Expand All @@ -80,10 +80,10 @@ begin
.NormalizeEmail
.&End
.CheckAll;
.Check;
```

##### Modo: JSON
## JSON

- No modo JSON, o que deve ser informado **_validate_** é o nome da key do json!
- Caso seja utilizado algum **_sanitizer_**, o valor dentro do JSON será modificado!
Expand Down Expand Up @@ -145,35 +145,42 @@ begin
.CheckAll;
```
## Informações

### Diferença de Check e CheckAll
- **Check**: Faz a verificação de todos os **_validate_**, mas se houver um item com retorno **_false_** ele interrompe, retornando uma única mensagem com erro se tiver!

- **CheckAll**: Faz a verificação de todos os **_validate_**, retornando todas mensagens com erro se tiver! <br>

Usando o ``` CheckAll(TDataValidatorCheckAll.tcFirst) ``` ele retornar apenas a primeira mensagem de erro de cada **_validate_**.

#### Como saber se houve error
### Como saber se houve error

```
Result := LResult.Ok; // True = Nenhum erro | False = Tem erro
```

#### Como recuperar todas as mensagens de errors
### Como recuperar a mensagem com erro
```
Result := LResult.Informations.Message;
```

#### Como recuperar uma única mensagem de error
### Como recuperar uma única mensagem de error
```
Result := LResult.Informations.GetItem(0).Message;
```

#### Como recuperar o total de errors
### Como recuperar a quantidade de errors
```
Result := LResult.Informations.Count;
```

#### Diferença de Check e CheckAll

- **Check**: Faz a verificação de todos os **_validate_**, mas se houver um item com retorno **_false_** ele interrompe, retornando uma única mensagem de erro se tiver!
- **CheckAll**: Faz a verificação de todos os **_validate_**, retornando todas mensagens de erro se tiver!
### Como recuperar o valor analizado
```
Result := LResult.Values[0]; // Recupera o primeiro valor
```

#### **Validação Schema**
### **Validação Schema**
- É uma forma de criar um esqueleto de validação e conseguir reutilizar em outras validações.

```
Expand Down Expand Up @@ -250,84 +257,84 @@ TDataValidator.Values

## Validators / Sanitizers

|Validação para values |Validação JSON (Key/Value) |Sanitizers para Valus |
| ------------ | ------------ | ------------ |
|CustomValue |(Key) IsOptional |CustomSanitizer |
|Contains |(Key) IsRequired |NormalizeEmail |
|EndsWith |(Value) CustomJSONValue |OnlyNumbers |
|IsAlpha |(Value) IsNull |RemoveAccents |
|IsAlphaNumeric |(Value) MinItems |Replace |
|IsAscii |(Value) MaxItems |ToBase64Decode |
|IsBase32 |(Value) + Validação para values |ToBase64Encode |
|IsBase58 | |ToDate |
|IsBase64 | |ToDateTime |
|IsBetween | |ToHTMLDecode |
|IsBoolean | |ToHTMLEncode |
|IsBTCAddress | |ToInteger |
|IsCNPJ | |ToLowerCase |
|IsCPF | |ToMD5 |
|IsCPFCNPJ | |ToNumeric |
|IsDate | |ToTime |
|IsDateBetween | |ToUpperCase |
|IsDateEquals | |ToURLDecode |
|IsDateGreaterThan | |ToURLEncode |
|IsDateLessThan | |Trim |
|IsDateTime | |TrimLeft |
|IsEmail | |TrimRight |
|IsEmpty | | |
|IsEquals | | |
|IsEthereumAddress | | |
|IsGreaterThan | | |
|IsGTIN | | |
|IsGTIN8 | | |
|IsGTIN12 | | |
|IsGTIN13 | | |
|IsGTIN14 | | |
|IsHexadecimal | | |
|IsHexColor | | |
|IsInteger | | |
|IsIP | | |
|IsIPv4 | | |
|IsIPv6 | | |
|IsISO8601 | | |
|IsJSON | | |
|IsJSONArray | | |
|IsJSONObject | | |
|IsJWT | | |
|IsLatLong | | |
|IsLength | | |
|IsLessThan | | |
|IsLocale | | |
|IsLowercase | | |
|IsMACAddress | | |
|IsMagnetURI | | |
|IsMD5 | | |
|IsMimeType | | |
|IsMongoId | | |
|IsNegative | | |
|IsNumeric | | |
|IsOptional | | |
|IsOctal | | |
|IsPassportNumber | | |
|IsPhoneNumber | | |
|IsPort | | |
|IsPositive | | |
|IsPostalCode | | |
|IsRGBColor | | |
|IsSSN | | |
|IsTime | | |
|IsTimeBetween | | |
|IsTimeEquals | | |
|IsTimeGreaterThan | | |
|IsTimeLessThan | | |
|IsUppercase | | |
|IsURL | | |
|IsUUID | | |
|IsUUIDv1 | | |
|IsUUIDv2 | | |
|IsUUIDv3 | | |
|IsUUIDv4 | | |
|IsUUIDv5 | | |
|IsZero | | |
|RegexIsMatch | | |
|StartsWith | | |
| Validação para values | Validação JSON (Key/Value) | Sanitizers para values |
| ------------ | ------------ | ------------ |
| CustomValue | (Key) IsOptional | CustomSanitizer |
| Contains | (Key) IsRequired | NormalizeEmail |
| EndsWith | (Value) CustomJSONValue | OnlyNumbers |
| IsAlpha | (Value) IsJSONNull | RemoveAccents |
| IsAlphaNumeric | (Value) IsJSONBoolean | Replace |
| IsAscii | (Value) IsJSONNumeric | ToBase64Decode |
| IsBase32 | (Value) IsJSONString | ToBase64Encode |
| IsBase58 | (Value) MinItems | ToDate |
| IsBase64 | (Value) MaxItems | ToDateTime |
| IsBetween | (Value) + Validação para values | ToHTMLDecode |
| IsBoolean | | ToHTMLEncode |
| IsBTCAddress | | ToInteger |
| IsCNPJ | | ToLowerCase |
| IsCPF | | ToMD5 |
| IsCPFCNPJ | | ToNumeric |
| IsDate | | ToTime |
| IsDateBetween | | ToUpperCase |
| IsDateEquals | | ToURLDecode |
| IsDateGreaterThan | | ToURLEncode |
| IsDateLessThan | | Trim |
| IsDateTime | | TrimLeft |
| IsEmail | | TrimRight |
| IsEmpty | | |
| IsEquals | | |
| IsEthereumAddress | | |
| IsGreaterThan | | |
| IsGTIN | | |
| IsGTIN8 | | |
| IsGTIN12 | | |
| IsGTIN13 | | |
| IsGTIN14 | | |
| IsHexadecimal | | |
| IsHexColor | | |
| IsInteger | | |
| IsIP | | |
| IsIPv4 | | |
| IsIPv6 | | |
| IsISO8601 | | |
| IsJSON | | |
| IsJSONArray | | |
| IsJSONObject | | |
| IsJWT | | |
| IsLatLong | | |
| IsLength | | |
| IsLessThan | | |
| IsLocale | | |
| IsLowercase | | |
| IsMACAddress | | |
| IsMagnetURI | | |
| IsMD5 | | |
| IsMimeType | | |
| IsMongoId | | |
| IsNegative | | |
| IsNumeric | | |
| IsOptional | | |
| IsOctal | | |
| IsPassportNumber | | |
| IsPhoneNumber | | |
| IsPort | | |
| IsPositive | | |
| IsPostalCode | | |
| IsRGBColor | | |
| IsSSN | | |
| IsTime | | |
| IsTimeBetween | | |
| IsTimeEquals | | |
| IsTimeGreaterThan | | |
| IsTimeLessThan | | |
| IsUppercase | | |
| IsURL | | |
| IsUUID | | |
| IsUUIDv1 | | |
| IsUUIDv2 | | |
| IsUUIDv3 | | |
| IsUUIDv4 | | |
| IsUUIDv5 | | |
| IsZero | | |
| RegexIsMatch | | |
| StartsWith | | |
1 change: 1 addition & 0 deletions samples/JSON/Basic/Basic.delphilsp.json

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions samples/JSON/Basic/Basic.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
program Basic;

uses
Vcl.Forms,
UBasic in 'UBasic.pas' {Form2},
DataValidator.Context in '..\..\..\src\core\DataValidator.Context.pas',
DataValidator.Information in '..\..\..\src\core\DataValidator.Information.pas',
DataValidator.Intf in '..\..\..\src\core\DataValidator.Intf.pas',
DataValidator.ItemBase in '..\..\..\src\core\DataValidator.ItemBase.pas',
DataValidator.ItemBase.Sanitizer in '..\..\..\src\core\DataValidator.ItemBase.Sanitizer.pas',
DataValidator.JSON.Base in '..\..\..\src\core\DataValidator.JSON.Base.pas',
DataValidator.JSON.Context in '..\..\..\src\core\DataValidator.JSON.Context.pas',
DataValidator.JSON in '..\..\..\src\core\DataValidator.JSON.pas',
DataValidator in '..\..\..\src\core\DataValidator.pas',
DataValidator.Result in '..\..\..\src\core\DataValidator.Result.pas',
DataValidator.Schema.Base in '..\..\..\src\core\DataValidator.Schema.Base.pas',
DataValidator.Schema in '..\..\..\src\core\DataValidator.Schema.pas',
DataValidator.Types in '..\..\..\src\core\DataValidator.Types.pas',
DataValidator.Value.Base in '..\..\..\src\core\DataValidator.Value.Base.pas',
DataValidator.Value in '..\..\..\src\core\DataValidator.Value.pas',
Sanitizer.Base64.Decode in '..\..\..\src\sanitializators\Sanitizer.Base64.Decode.pas',
Sanitizer.Base64.Encode in '..\..\..\src\sanitializators\Sanitizer.Base64.Encode.pas',
Sanitizer.Custom in '..\..\..\src\sanitializators\Sanitizer.Custom.pas',
Sanitizer.HTML.Decode in '..\..\..\src\sanitializators\Sanitizer.HTML.Decode.pas',
Sanitizer.HTML.Encode in '..\..\..\src\sanitializators\Sanitizer.HTML.Encode.pas',
Sanitizer.NormalizeEmail in '..\..\..\src\sanitializators\Sanitizer.NormalizeEmail.pas',
Sanitizer.OnlyNumbers in '..\..\..\src\sanitializators\Sanitizer.OnlyNumbers.pas',
Sanitizer.RemoveAccents in '..\..\..\src\sanitializators\Sanitizer.RemoveAccents.pas',
Sanitizer.Replace in '..\..\..\src\sanitializators\Sanitizer.Replace.pas',
Sanitizer.ToDate in '..\..\..\src\sanitializators\Sanitizer.ToDate.pas',
Sanitizer.ToDateTime in '..\..\..\src\sanitializators\Sanitizer.ToDateTime.pas',
Sanitizer.ToInteger in '..\..\..\src\sanitializators\Sanitizer.ToInteger.pas',
Sanitizer.ToLowerCase in '..\..\..\src\sanitializators\Sanitizer.ToLowerCase.pas',
Sanitizer.ToMD5 in '..\..\..\src\sanitializators\Sanitizer.ToMD5.pas',
Sanitizer.ToNumeric in '..\..\..\src\sanitializators\Sanitizer.ToNumeric.pas',
Sanitizer.ToTime in '..\..\..\src\sanitializators\Sanitizer.ToTime.pas',
Sanitizer.ToUpperCase in '..\..\..\src\sanitializators\Sanitizer.ToUpperCase.pas',
Sanitizer.Trim in '..\..\..\src\sanitializators\Sanitizer.Trim.pas',
Sanitizer.TrimLeft in '..\..\..\src\sanitializators\Sanitizer.TrimLeft.pas',
Sanitizer.TrimRight in '..\..\..\src\sanitializators\Sanitizer.TrimRight.pas',
Sanitizer.URL.Decode in '..\..\..\src\sanitializators\Sanitizer.URL.Decode.pas',
Sanitizer.URL.Encode in '..\..\..\src\sanitializators\Sanitizer.URL.Encode.pas',
Validator.Contains in '..\..\..\src\validators\Validator.Contains.pas',
Validator.Custom in '..\..\..\src\validators\Validator.Custom.pas',
Validator.EndsWith in '..\..\..\src\validators\Validator.EndsWith.pas',
Validator.IsAlpha in '..\..\..\src\validators\Validator.IsAlpha.pas',
Validator.IsAlphanumeric in '..\..\..\src\validators\Validator.IsAlphanumeric.pas',
Validator.IsAscii in '..\..\..\src\validators\Validator.IsAscii.pas',
Validator.IsBase32 in '..\..\..\src\validators\Validator.IsBase32.pas',
Validator.IsBase58 in '..\..\..\src\validators\Validator.IsBase58.pas',
Validator.IsBase64 in '..\..\..\src\validators\Validator.IsBase64.pas',
Validator.IsBetween in '..\..\..\src\validators\Validator.IsBetween.pas',
Validator.IsBoolean in '..\..\..\src\validators\Validator.IsBoolean.pas',
Validator.IsBTCAddress in '..\..\..\src\validators\Validator.IsBTCAddress.pas',
Validator.IsCNPJ in '..\..\..\src\validators\Validator.IsCNPJ.pas',
Validator.IsCPF in '..\..\..\src\validators\Validator.IsCPF.pas',
Validator.IsCPFCNPJ in '..\..\..\src\validators\Validator.IsCPFCNPJ.pas',
Validator.IsDate in '..\..\..\src\validators\Validator.IsDate.pas',
Validator.IsDateBetween in '..\..\..\src\validators\Validator.IsDateBetween.pas',
Validator.IsDateEquals in '..\..\..\src\validators\Validator.IsDateEquals.pas',
Validator.IsDateGreaterThan in '..\..\..\src\validators\Validator.IsDateGreaterThan.pas',
Validator.IsDateLessThan in '..\..\..\src\validators\Validator.IsDateLessThan.pas',
Validator.IsDateTime in '..\..\..\src\validators\Validator.IsDateTime.pas',
Validator.IsEmail in '..\..\..\src\validators\Validator.IsEmail.pas',
Validator.IsEmpty in '..\..\..\src\validators\Validator.IsEmpty.pas',
Validator.IsEquals in '..\..\..\src\validators\Validator.IsEquals.pas',
Validator.IsEthereumAddress in '..\..\..\src\validators\Validator.IsEthereumAddress.pas',
Validator.IsGreaterThan in '..\..\..\src\validators\Validator.IsGreaterThan.pas',
Validator.IsGTIN in '..\..\..\src\validators\Validator.IsGTIN.pas',
Validator.IsHexadecimal in '..\..\..\src\validators\Validator.IsHexadecimal.pas',
Validator.IsHexColor in '..\..\..\src\validators\Validator.IsHexColor.pas',
Validator.IsInteger in '..\..\..\src\validators\Validator.IsInteger.pas',
Validator.IsIP in '..\..\..\src\validators\Validator.IsIP.pas',
Validator.IsISO8601 in '..\..\..\src\validators\Validator.IsISO8601.pas',
Validator.IsJSON in '..\..\..\src\validators\Validator.IsJSON.pas',
Validator.IsJWT in '..\..\..\src\validators\Validator.IsJWT.pas',
Validator.IsLatLong in '..\..\..\src\validators\Validator.IsLatLong.pas',
Validator.IsLength in '..\..\..\src\validators\Validator.IsLength.pas',
Validator.IsLessThan in '..\..\..\src\validators\Validator.IsLessThan.pas',
Validator.IsLocale in '..\..\..\src\validators\Validator.IsLocale.pas',
Validator.IsLowercase in '..\..\..\src\validators\Validator.IsLowercase.pas',
Validator.IsMACAddress in '..\..\..\src\validators\Validator.IsMACAddress.pas',
Validator.IsMagnetURI in '..\..\..\src\validators\Validator.IsMagnetURI.pas',
Validator.IsMD5 in '..\..\..\src\validators\Validator.IsMD5.pas',
Validator.IsMimeType in '..\..\..\src\validators\Validator.IsMimeType.pas',
Validator.IsMongoId in '..\..\..\src\validators\Validator.IsMongoId.pas',
Validator.IsNegative in '..\..\..\src\validators\Validator.IsNegative.pas',
Validator.IsNumeric in '..\..\..\src\validators\Validator.IsNumeric.pas',
Validator.IsOctal in '..\..\..\src\validators\Validator.IsOctal.pas',
Validator.IsOptional in '..\..\..\src\validators\Validator.IsOptional.pas',
Validator.IsPassportNumber in '..\..\..\src\validators\Validator.IsPassportNumber.pas',
Validator.IsPhoneNumber in '..\..\..\src\validators\Validator.IsPhoneNumber.pas',
Validator.IsPort in '..\..\..\src\validators\Validator.IsPort.pas',
Validator.IsPositive in '..\..\..\src\validators\Validator.IsPositive.pas',
Validator.IsPostalCode in '..\..\..\src\validators\Validator.IsPostalCode.pas',
Validator.IsRGBColor in '..\..\..\src\validators\Validator.IsRGBColor.pas',
Validator.IsSSN in '..\..\..\src\validators\Validator.IsSSN.pas',
Validator.IsTime in '..\..\..\src\validators\Validator.IsTime.pas',
Validator.IsTimeBetween in '..\..\..\src\validators\Validator.IsTimeBetween.pas',
Validator.IsTimeEquals in '..\..\..\src\validators\Validator.IsTimeEquals.pas',
Validator.IsTimeGreaterThan in '..\..\..\src\validators\Validator.IsTimeGreaterThan.pas',
Validator.IsTimeLessThan in '..\..\..\src\validators\Validator.IsTimeLessThan.pas',
Validator.IsUppercase in '..\..\..\src\validators\Validator.IsUppercase.pas',
Validator.IsURL in '..\..\..\src\validators\Validator.IsURL.pas',
Validator.IsUUID in '..\..\..\src\validators\Validator.IsUUID.pas',
Validator.IsZero in '..\..\..\src\validators\Validator.IsZero.pas',
Validator.JSON.Key.IsOptional in '..\..\..\src\validators\Validator.JSON.Key.IsOptional.pas',
Validator.JSON.Key.IsRequired in '..\..\..\src\validators\Validator.JSON.Key.IsRequired.pas',
Validator.JSON.Value.Custom in '..\..\..\src\validators\Validator.JSON.Value.Custom.pas',
Validator.JSON.Value.IsJSONValue in '..\..\..\src\validators\Validator.JSON.Value.IsJSONValue.pas',
Validator.JSON.Value.IsMinMaxItems in '..\..\..\src\validators\Validator.JSON.Value.IsMinMaxItems.pas',
Validator.Regex.IsMatch in '..\..\..\src\validators\Validator.Regex.IsMatch.pas',
Validator.StartsWith in '..\..\..\src\validators\Validator.StartsWith.pas',
Validator.JSON.SubValidator.Custom in '..\..\..\src\validators\Validator.JSON.SubValidator.Custom.pas';

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
Loading

0 comments on commit 9e055a9

Please sign in to comment.