Skip to content

Commit

Permalink
📖 docs: v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maktoobgar committed Aug 20, 2023
1 parent 96b8405 commit d5a39f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ CHANGELOG
UNRELEASED
----------

* 🎉 feat: field names will get translatoed

.. 1.4.0 (2023-08-20)
.. ------------------
1.4.0 (2023-08-20)
------------------

* ✅ test: test cases updated for new features
* 🎉 feat: field names will get translated
* 🎉 feat: ability to pass custom validators from generators to ruleSet is now possible
* 🎉 feat: added AlwaysCheckRules method in ruleSet
* 🎉 feat: added WhenNotExistOne + WhenNotExistAll
Expand Down
18 changes: 1 addition & 17 deletions rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,19 @@ type (
// Checks if input is float
Float() ruleSet
// Checks if input acts like: input >= min or len(input) >= min
//
// Note: If min > 0, field will be required
Min(min float64) ruleSet
// Checks if input acts like: input <= max or len(input) <= max
Max(max float64) ruleSet
// Checks if input acts like: len(input) >= from && len(input) <= to
//
// If from == -1, no check on from will happen
// If to == -1, no check on to will happen
//
// Note: If from > 0, field will be required
LenRange(from int, to int) ruleSet
// Checks if input acts like: len(input) == length
//
// Note: If length > 0, field will be required
Len(length int) ruleSet
// Makes this field required, Checks if input is not zero(0, "", ''), nil or empty
//
// Note: Field will be required
Required() ruleSet
// Makes this field optional
//
// Note: Use this after functions that make fields required automatically
//
// Note: Field will be optional
Optional() ruleSet
// If data is zero(0, "", ''), nil or empty, all validation rules will be checked anyway
//
Expand Down Expand Up @@ -105,14 +93,12 @@ type (
// Checks if input is a valid email address
Email() ruleSet
// Validates inputs with passed pattern
//
// Note: If pattern does not pass empty string, it will be required
Regex(pattern string) ruleSet
// Checks if input is a valid phone number
Phone() ruleSet
// Adds custom validators
Custom(validators Validators) ruleSet
// Adds one custom validator which is registed before
// Adds one custom validator which is registered before in generator
RegisteredCustom(validatorKeys ...string) ruleSet
// Checks if input is a map
Map() ruleSet
Expand All @@ -129,8 +115,6 @@ type (
// Checks if input is a Specific type
Type(input interface{}) ruleSet
// Checks if input is at least 8 characters long, has one lowercase, one uppercase and one number character
//
// Note: Field will be required
Password() ruleSet
// Checks if at least one of passed ruleSets pass its own validation check
OR(ruleSets ...ruleSet) ruleSet
Expand Down
6 changes: 5 additions & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func getFormattedErrorMessage(message string, fieldName string, value interface{
for key, value := range options {
message = strings.ReplaceAll(message, "$"+key, value)
}
return strings.ReplaceAll(strings.ReplaceAll(message, "$field", fieldName), "$value", t(fmt.Sprint(value)))
newValue := fmt.Sprint(value)
if t != nil {
newValue = t(newValue)
}
return strings.ReplaceAll(strings.ReplaceAll(message, "$field", fieldName), "$value", newValue)
}

// Formats and returns error message associated with passed ruleKey
Expand Down

0 comments on commit d5a39f4

Please sign in to comment.