From e7c177f428f9c3bacc19de55cc3c4a254a658ea8 Mon Sep 17 00:00:00 2001 From: daltenburg Date: Mon, 1 Mar 2021 20:50:23 -0500 Subject: [PATCH] Added a way to add 'implicit' custom rules to the Validator --- lib/index.js | 3 ++- lib/validator.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 1d3d5c2..f65ab60 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,8 +11,9 @@ function setLang(lang) { messages.defaultLang = lang; } -function extend(name, callback) { +function extend(name, callback, isImplicit=false) { rules[name] = callback; + if (isImplicit) Validator.addImplicitRule(name); } /** diff --git a/lib/validator.js b/lib/validator.js index 83bd428..ee30c7a 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -78,6 +78,14 @@ class Validator { this.breakWhenFailed = sure; } + /** + * Allows a custom rule to be added as an implicit rule + * @param {String} ruleName + */ + static addImplicitRule(ruleName){ + implicitRules.push(ruleName); + } + /** * set attributes nice names * @param {*} attributeNames