UNPKG

aright-lexicon

Version:

babelute DSL for Object and Types validations

54 lines (43 loc) 1.53 kB
'use strict'; function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var babelute = _interopDefault(require('babelute')); /** * @author Gilles Coomans * @licence MIT * @copyright 2016-2017 Gilles Coomans */ var arightLexicon = babelute.createLexicon('aright'); 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$$1) { return this.has(name, type, babelute$$1); }; }); return methods; }); //______________________________________________________ module.exports = arightLexicon; //# sourceMappingURL=index.js.map