Code coverage report for lib/validator.js

Statements: 90.91% (20 / 22)      Branches: 83.33% (10 / 12)      Functions: 100% (9 / 9)      Lines: 90.91% (20 / 22)      Ignored: none     

All files » lib/ » validator.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 471 1   1     7 1 26       9   9 3 3   3 2       6 48 48   48 27           9     29     7            
var lacona = require('lacona');
var substrings = require('lacona-util-phrasehelpers').substrings;
 
module.exports = lacona.createPhrase({
	name: 'lacona/validator',
	getDefaultProps: function () {
		return {
			default: function (done) { done(); },
			validate: function (input, done) { done(null, true); }
		};
	},
	validate: function (inputString, data, done) {
		var this_ = this;
 
		if (inputString === '') {
			this_.props.default(function (err, suggestion) {
				Iif (err) {
					return done(err);
				} else if (suggestion || suggestion === '') {
					data({text: suggestion, value: suggestion});
				}
			});
		} else {
			substrings(inputString, this.props.splitOn).forEach(function (stringPart) {
				this_.props.validate(stringPart, function (err, isValid) {
					Iif (err) {
						return done(err);
					} else if (isValid) {
						data({text: stringPart, value: stringPart});
					}
				});
			});
		}
 
		done();
	},
	getValue: function (result) {
		return result.value;
	},
	describe: function () {
		return lacona.value({
			compute: this.validate,
			id: 'value'
		});
	}
});