mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 280 forks source link

Add public method to get parsed rules #113

Open garygreen opened 8 years ago

garygreen commented 8 years ago

I would find this particularly useful in dominar.js as I need to determine what data to pass to validator js from the form (in the case of the confirmed and same rule) -- I manually have to parse the rules in pretty much the same way validatorjs does.

It would be nice to get the parsed rules (where all the values have been exploded into a normalized format etc).

This could relate to #89 and improve performance if we allow passing rules to validator that have already been parsed. That way when you re-create the validator, it won't have to re parse the rules as it would detect the rules have already been parsed (might not be a huge speed increase, but still worthwhile).

var parsedRules = Validator.parseRules({ name: 'required' });
var validator = new Validator({ name: 'gary' }, parsedRules);
iamdtang commented 8 years ago

So this would make the data structure that gets created in _parsedRules() public?