UNPKG

javascript-decorators

Version:
159 lines (139 loc) 5.56 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports._validateSchema = exports._acceptsString = exports._acceptsPromise = exports._acceptsFunction = exports._acceptsBoolean = exports._acceptsInteger = exports._acceptsNumber = exports._acceptsArray = exports._acceptsObject = undefined; var _validationHelpers = require('./validationHelpers'); /** * @acceptsObject Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsObject = exports._acceptsObject = function acceptsObject() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isObject, ' is not an object', failSilent); }; /** * @acceptsArray Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ /** * Validation related decorators * * @author Avraam Mavridis <avr.mav@gmail.com> * */ var _acceptsArray = exports._acceptsArray = function acceptsArray() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isArray, ' is not an array', failSilent); }; /** * @acceptsNumber Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsNumber = exports._acceptsNumber = function acceptsNumber() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isNumber, ' is not a number', failSilent); }; /** * @acceptsInteger Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsInteger = exports._acceptsInteger = function acceptsInteger() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isInteger, ' is not an integer', failSilent); }; /** * @acceptsBoolean Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsBoolean = exports._acceptsBoolean = function acceptsBoolean() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isBoolean, ' is not a boolean', failSilent); }; /** * @acceptsFunction Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsFunction = exports._acceptsFunction = function acceptsFunction() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isFunction, ' is not a function', failSilent); }; /** * @acceptsPromise Decorator * * @method acceptsObject * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsPromise = exports._acceptsPromise = function acceptsPromise() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isPromise, ' is not a promise', failSilent); }; /** * @acceptsString Decorator * * @method acceptsString * * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _acceptsString = exports._acceptsString = function acceptsString() { var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var failSilent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _validationHelpers._basefunc)(position, _validationHelpers._isString, ' is not a string', failSilent); }; /** * @validateSchema Decorator * * @method acceptsObject * * @param { object } validation schema * @param { integer|array } position = 0 Position of the property to validate * * @return { function } Decorator */ var _validateSchema = exports._validateSchema = function validateSchema(schema) { var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var failSilent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; return (0, _validationHelpers._isValidSchema)(schema, position, failSilent); };