Skip to content

Commit 20a8e98

Browse files
authored
Merge pull request #47 from DanielAlt/master
Added a way to add 'implicit' custom rules to the Validator
2 parents f2db06a + e7c177f commit 20a8e98

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ function setLang(lang) {
1111
messages.defaultLang = lang;
1212
}
1313

14-
function extend(name, callback) {
14+
function extend(name, callback, isImplicit=false) {
1515
rules[name] = callback;
16+
if (isImplicit) Validator.addImplicitRule(name);
1617
}
1718

1819
/**

lib/validator.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ class Validator {
7878
this.breakWhenFailed = sure;
7979
}
8080

81+
/**
82+
* Allows a custom rule to be added as an implicit rule
83+
* @param {String} ruleName
84+
*/
85+
static addImplicitRule(ruleName){
86+
implicitRules.push(ruleName);
87+
}
88+
8189
/**
8290
* set attributes nice names
8391
* @param {*} attributeNames

0 commit comments

Comments
 (0)