aright-lexicon
Version:
babelute DSL for Object and Types validations
54 lines (45 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _babelute = require('babelute');
var _babelute2 = _interopRequireDefault(_babelute);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var arightLexicon = _babelute2.default.createLexicon('aright'); /**
* @author Gilles Coomans
* @licence MIT
* @copyright 2016-2017 Gilles Coomans
*/
arightLexicon.addAtoms(['is', 'has', 'strict', 'not', 'switch', 'minLength', 'maxLength', 'minimum', 'maximum', 'format', 'enum', 'item', 'equal', 'instanceOf', 'array', 'isArray', 'null']).addCompounds(function () {
return {
between: function between(min, max) {
return this.minimum(min).maximum(max);
},
isNull: function isNull() {
return this.equal(null);
},
or: function or() {
for (var _len = arguments.length, rules = Array(_len), _key = 0; _key < _len; _key++) {
rules[_key] = arguments[_key];
}
return this._append('aright', 'or', rules);
},
email: function email() {
return this.isString().format('email').minLength(6);
}
};
}).addCompounds(function () {
var methods = {};
['object', 'string', 'function', 'boolean', 'number', 'boolean'].forEach(function (type) {
var upperName = type[0].toUpperCase() + type.substring(1);
methods['is' + upperName] = function () {
return this.is(type);
};
methods[type] = function (name, babelute) {
return this.has(name, type, babelute);
};
});
return methods;
});
exports.default = arightLexicon;
//______________________________________________________